Skip to content
Snippets Groups Projects

More test helpers

Merged Georges Racinet requested to merge topic/default/testhelpers into branch/default
1 file
+ 26
7
Compare changes
  • Side-by-side
  • Inline
@@ -24,6 +24,11 @@
from .git import GitRepo
logger = logging.getLogger(__name__)
STATE_MAINTAINER_ACTIVATION_CONFIG = (
b'hooks', b'pretxnclose.testcase',
b'python:heptapod.hooks.gitlab_mirror.mirror',
)
def patch_gitlab_hooks(monkeypatch, records, action=None):
@@ -43,6 +48,26 @@
monkeypatch.setattr(hooks.PostReceive, '__call__', call)
def activate_gitlab_state_maintainer(hg_repo_wrapper):
"""Make state maintaining or mirroring to Git repo automatic.
This is essential to get the state maintaining happen in-transaction.
If the repository is configured with `native=False` (legacy hg-git based
projects), this triggers the mirroring to Git.
"""
hg_repo_wrapper.repo.ui.setconfig(*STATE_MAINTAINER_ACTIVATION_CONFIG)
def activate_gitlab_state_maintainer_in_dict(config): # pragma no cover
"""Activation in config dicts used before persisting configuration.
This is used in HGitaly tests, as py-heptapod tests tend to do it
after repo creation, in non-persistent form.
"""
section, key, value = STATE_MAINTAINER_ACTIVATION_CONFIG
config[section] = {key: value}
@attr.s
class GitLabStateMaintainerFixture:
"""Helper class to create fixtures for GitLab state maintainers.
@@ -97,13 +122,7 @@
del self.gitlab_notifs[:]
def activate_mirror(self):
"""Make mirroring from Mercurial to Git repo automatic.
This is essential to get the mirroring code to run in-transaction.
"""
self.hg_repo_wrapper.repo.ui.setconfig(
b'hooks', b'pretxnclose.testcase',
b'python:heptapod.hooks.gitlab_mirror.mirror')
activate_gitlab_state_maintainer(self.hg_repo_wrapper)
def delete(self):
hg_path = self.hg_repo_wrapper.repo.root
Loading