Skip to content
Snippets Groups Projects
Commit ebfb0b7b148b authored by Georges Racinet's avatar Georges Racinet
Browse files

Test fixtures: extracted a GitLabStateMaintainerFixture base class

It will be useful to test the future `NativeStateMaintainer` class
parent 2eb152fab02a
No related branches found
No related tags found
2 merge requests!66Topic/default/merge hgitaly2,!65NoGitStateMaintainer
......@@ -38,8 +38,8 @@
@attr.s
class GitLabMirrorFixture:
"""Helper class to create fixtures for GitLab aware hg-git mirroring.
class GitLabStateMaintainerFixture:
"""Helper class to create fixtures for GitLab state maintainers.
The pytest fixture functions themselves will have to be provided with
the tests that use them.
......@@ -47,8 +47,12 @@
It is not the role of this class to make decisions about scopes or
the kind of root directory it operates in.
There will be later on a fixture for Mercurial-native Heptapod
repositories, hence GitLab notifications without a Git repository.
This provides
- Mercurial repository test wrapper
- GitLab notifications interception
and is thus usable directly for native repositories.
"""
base_path = attr.ib()
hg_repo_wrapper = attr.ib()
......@@ -52,5 +56,4 @@
"""
base_path = attr.ib()
hg_repo_wrapper = attr.ib()
git_repo = attr.ib()
gitlab_notifs = attr.ib()
......@@ -56,5 +59,4 @@
gitlab_notifs = attr.ib()
import heptapod.testhelpers.gitlab
@classmethod
def init(cls, base_path, monkeypatch, hg_config=None,
......@@ -58,9 +60,11 @@
@classmethod
def init(cls, base_path, monkeypatch, hg_config=None,
common_repo_name='repo'):
common_repo_name='repo',
additional_extensions=(),
**kw):
if hg_config is None:
config = {}
else:
config = deepcopy(hg_config)
......@@ -62,11 +66,12 @@
if hg_config is None:
config = {}
else:
config = deepcopy(hg_config)
config.setdefault('extensions', {})['hggit'] = ''
config.setdefault('extensions', {}).update(
(ext, '') for ext in additional_extensions)
config['phases'] = dict(publish=False)
hg_repo_wrapper = RepoWrapper.init(
base_path / (common_repo_name + '.hg'),
config=config)
......@@ -68,9 +73,8 @@
config['phases'] = dict(publish=False)
hg_repo_wrapper = RepoWrapper.init(
base_path / (common_repo_name + '.hg'),
config=config)
git_repo = GitRepo.init(base_path / (common_repo_name + '.git'))
notifs = []
patch_gitlab_hooks(monkeypatch, notifs)
return cls(hg_repo_wrapper=hg_repo_wrapper,
......@@ -74,5 +78,4 @@
notifs = []
patch_gitlab_hooks(monkeypatch, notifs)
return cls(hg_repo_wrapper=hg_repo_wrapper,
git_repo=git_repo,
gitlab_notifs=notifs,
......@@ -78,5 +81,6 @@
gitlab_notifs=notifs,
base_path=base_path)
base_path=base_path,
**kw)
def clear_gitlab_notifs(self):
"""Forget about all notifications already sent to GitLab.
......@@ -96,12 +100,6 @@
b'python:heptapod.hooks.gitlab_mirror.mirror')
def delete(self):
git_path = self.git_repo.path
try:
shutil.rmtree(git_path)
except Exception:
logger.exception("Error removing the Git repo at %r", git_path)
hg_path = self.hg_repo_wrapper.repo.root
try:
shutil.rmtree(hg_path)
......@@ -115,3 +113,33 @@
def __exit__(self, *exc_args):
self.delete()
return False # no exception handling related to exc_args
@attr.s
class GitLabMirrorFixture(GitLabStateMaintainerFixture):
"""Helper class to create fixtures for GitLab aware hg-git mirroring.
Adds the Git repository to GitLabStateMaintainerFixture
"""
git_repo = attr.ib()
import heptapod.testhelpers.gitlab
@classmethod
def init(cls, base_path, monkeypatch,
common_repo_name='repo', **kw):
git_repo = GitRepo.init(base_path / (common_repo_name + '.git'))
return super(GitLabMirrorFixture, cls).init(
base_path, monkeypatch,
common_repo_name=common_repo_name,
additional_extensions=['hggit'],
git_repo=git_repo,
**kw)
def delete(self):
git_path = self.git_repo.path
try:
shutil.rmtree(git_path)
except Exception:
logger.exception("Error removing the Git repo at %r", git_path)
super(GitLabMirrorFixture, self).delete()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment