Read about our upcoming Code of Conduct on this issue

Commit 615bf94a authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Git: testing MR from fork, merged by web app

This works, but we still have uncertainties about
MR creation prompt on push and the expected pipelines,
so we don't test these.
parent ea826dc5dbfb
import json
from .utils.git import LocalRepo as GitRepo
from .utils.runner import Runner
from .utils.project import ProjectAccess
from .test_merge_requests import api_accept_merge_request
......@@ -77,12 +78,19 @@ def test_basic(git_project, tmpdir):
assert repo_path.join('foo').read() == "Tired of foo!"
def prepare_mr_source_branch(repo, with_ci=False, needing_rebase=True):
def prepare_mr_source_branch(repo,
"""Prepare a source branch
This is meant to be very close to what `prepare_topic()` does in the
Mercurial case.
:param src_remote_url: name of remote to push the source branch to. The
``origin```default value matches the case where source and target
projects are the same.
Graph after preparation if needing_rebase is True::
* commit f6d284cc (HEAD -> antelope)
......@@ -129,9 +137,12 @@ def prepare_mr_source_branch(repo, with_ci=False, needing_rebase=True):
# using git_unchecked because we need stderr
code, out, err = repo.git_unchecked('push', '--set-upstream',
'origin', 'antelope')
src_remote, 'antelope')
assert code == 0
assert "create a merge request for %s" % source_branch in err
if src_remote == 'origin':
# TODO investigate proper conditions for MR creation prompt
# in forks
assert "create a merge request for %s" % source_branch in err
return source_branch
......@@ -218,3 +229,45 @@ def test_mergerequest_cli(git_project, tmpdir):
assert vcs_info['repo_type'] == 'git'
assert vcs_info['sha'] == repo.sha('origin/master')
assert vcs_info.get('hgsha') is None
def test_fork_mergerequest_api_explicit_merge_message(
git_project, additional_user, tmpdir):
"""Accepting MR done from a fork via API with an explicit merge changeset.
proj = git_project
with git_project.api_fork(user=additional_user) as fork:
default_url = proj.owner_basic_auth_url
repo = GitRepo.init(tmpdir.join('repo'),
repo.git('remote', 'add', 'fork', fork.owner_basic_auth_url)
src_branch = prepare_mr_source_branch(repo,
mr_id = fork.api_create_merge_request(source=src_branch,
api_accept_merge_request(proj, mr_id)
repo.git('fetch', 'origin', 'master')
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 (wouldn't work after deletion of fork)
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)
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