Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod-tests
Commits
94813596a46e
Commit
d7bd2b7a
authored
Oct 29, 2020
by
Georges Racinet on mutations.racinet.fr
Browse files
Git: testing Merge Request with merge from Rails
parent
820d92d00c83
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/test_git.py
View file @
94813596
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
.
path
.
join
(
'.gitlab-ci.yml'
).
write
(
json
.
dumps
(
ci_config
))
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:"
)
print
(
repo
.
graphlog
())
# 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'
),
default_url
=
default_url
)
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:"
)
print
(
repo
.
graphlog
())
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
)
tests/utils/git.py
View file @
94813596
...
...
@@ -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'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment