Commit d7bd2b7a authored by Georges Racinet on's avatar Georges Racinet on
Browse files

Git: testing Merge Request with merge from Rails

parent 820d92d00c83
import json
from .utils.git import LocalRepo as GitRepo
from .utils.runner import Runner
from .test_merge_requests import api_accept_merge_request
def test_basic(git_project, tmpdir):
proj = git_project
......@@ -51,3 +53,101 @@ def test_basic(git_project, tmpdir):
# Pulling new commit in original repo (over SSH) for correctness assertion
repo.git('pull', ssh_cmd=ssh_cmd)
assert repo_path.join('foo').read() == "Tired of foo!"
def prepare_mr_source_branch(repo, with_ci=False, needing_rebase=True):
"""Prepare a source branch
This is meant to be very close to what `prepare_topic()` does in the
Mercurial case.
Graph after preparation if needing_rebase is True::
* commit f6d284cc (HEAD -> antelope)
| Author: Test Git <testgit@heptapod.test>
| Date: Thu Oct 29 13:08:46 2020 +0100
| Même une antilope !
| * commit 8e1c7bbb (origin/master, master)
|/ Author: Test Git <testgit@heptapod.test>
| Date: Thu Oct 29 13:08:37 2020 +0100
| Even a horse!
* commit 7bd79271
Author: Test Git <testgit@heptapod.test>
Date: Thu Oct 29 13:08:31 2020 +0100
Initial sentence
source_branch = 'antelope'
repo.path.join('kitten').write("A lion is stronger than a kitten\n")
if with_ci:
# let's not depend on auto-devops (JSON is a subset of YaML)
ci_config = dict(job=dict(script=["grep lion antelope"]))
repo.git('add', '.gitlab-ci.yml')
repo.git('add', 'kitten')
repo.git('commit', '-m', 'Initial sentence')
repo.git('branch', source_branch)
if needing_rebase:
repo.path.join('horse').write("A lion is stronger than a horse\n")
repo.git('add', 'horse')
repo.git('commit', '-m', "Even a horse!")
repo.git('push', '--set-upstream', 'origin', 'master')
repo.git('checkout', source_branch)
repo.path.join('antelope').write("A lion is stronger than an antelope\n")
repo.git('add', 'antelope')
repo.git('commit', '-m', "Même une antilope !")
print("Graph after preparation of source branch:")
# using git_unchecked because we need stderr
code, out, err = repo.git_unchecked('push', '--set-upstream',
'origin', 'antelope')
assert code == 0
assert "create a merge request for %s" % source_branch in err
return source_branch
def test_mergerequest_api_explicit_merge_message(git_project, tmpdir):
"""Accepting the MR via API with an explicit merge changeset.
see `test_merge_requests.test_mergerequest_api()` for relevance of API
call for testing. In the Git case, we don't worry too much about the
push protocol (HTTP or SSH), the low level side of it being handled
by test_basic above, and the Git hooks calls being unchanged compared
to GitLab. What matters is the Rails logic that is triggered by
those hooks.
proj = git_project
runner = Runner.api_register(git_project, 'explicit')
default_url = proj.owner_basic_auth_url
repo = GitRepo.init(tmpdir.join('repo'),
src_branch = prepare_mr_source_branch(repo, with_ci=True)
mr_id = proj.api_create_merge_request(source=src_branch, target='master')
api_accept_merge_request(proj, mr_id)
repo.git('pull', '--all')
print("Graph after API merge:")
log = repo.git('log', 'origin/master', '--oneline')
titles = {l.split(' ', 1)[1] for l in log.splitlines()}
assert titles == {
"Merge branch 'antelope' into 'master'",
"Même une antilope !",
"Even a horse!",
"Initial sentence",
# Commit list is correct
expected = "Même une antilope !"
commit_links = proj.webdriver_get_merge_request_commits(mr_id)
assert any(expected in l.text for l in commit_links), (
"Commit summaries don't contain %r" % expected)
......@@ -100,3 +100,6 @@ class LocalRepo(object):
:returns: (process return code, stdout, stderr).
return git_call(self.path, args, check_return_code=False, **kwargs)
def graphlog(self):
return self.git('log', '--all', '--graph')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment