Skip to content

Commit 8329cd6

Browse files
chore: add a functional test for issue #1120
Going to switch to putting parameters from in the query string to having them in the 'data' body section. Add a functional test to make sure that we don't break anything. #1120
1 parent 09ef8d4 commit 8329cd6

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tools/functional/api/test_merge_requests.py

+59
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import time
2+
13
import pytest
24

35
import gitlab
6+
import gitlab.v4.objects
47

58

69
def test_merge_requests(project):
@@ -95,3 +98,59 @@ def test_merge_request_merge(project):
9598
with pytest.raises(gitlab.GitlabMRClosedError):
9699
# Two merge attempts should raise GitlabMRClosedError
97100
mr.merge()
101+
102+
103+
def test_merge_request_should_remove_source_branch(
104+
project: gitlab.v4.objects.Project, wait_for_sidekiq
105+
):
106+
"""Test to ensure https://github.com/python-gitlab/python-gitlab/issues/1120
107+
is fixed"""
108+
109+
source_branch = "remove_source_branch"
110+
project.branches.create({"branch": source_branch, "ref": "master"})
111+
112+
# NOTE(jlvillal): Must create a commit in the new branch before we can
113+
# create an MR that will work.
114+
project.files.create(
115+
{
116+
"file_path": f"README.{source_branch}",
117+
"branch": source_branch,
118+
"content": "Initial content",
119+
"commit_message": "New commit in new branch",
120+
}
121+
)
122+
123+
mr = project.mergerequests.create(
124+
{
125+
"source_branch": source_branch,
126+
"target_branch": "master",
127+
"title": "Should remove source branch",
128+
"remove_source_branch": True,
129+
}
130+
)
131+
132+
result = wait_for_sidekiq(timeout=60)
133+
assert result is True, "sidekiq process should have terminated but did not"
134+
135+
mr_iid = mr.iid
136+
for _ in range(60):
137+
mr = project.mergerequests.get(mr_iid)
138+
if mr.merge_status != "checking":
139+
break
140+
time.sleep(0.5)
141+
assert mr.merge_status != "checking"
142+
143+
# Ensure we can get the MR branch
144+
project.branches.get(source_branch)
145+
146+
mr.merge(should_remove_source_branch=True)
147+
148+
result = wait_for_sidekiq(timeout=60)
149+
assert result is True, "sidekiq process should have terminated but did not"
150+
151+
# Ensure we can NOT get the MR branch
152+
with pytest.raises(gitlab.exceptions.GitlabGetError):
153+
project.branches.get(source_branch)
154+
155+
mr = project.mergerequests.get(mr.iid)
156+
assert mr.merged_at is not None # Now is merged

0 commit comments

Comments
 (0)