Skip to content

Commit

Permalink
chore: add a functional test for issue #1120
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JohnVillalovos committed May 25, 2021
1 parent 184b94b commit 7d66115
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tools/functional/api/test_merge_requests.py
@@ -1,6 +1,9 @@
import time

import pytest

import gitlab
import gitlab.v4.objects


def test_merge_requests(project):
Expand Down Expand Up @@ -95,3 +98,59 @@ def test_merge_request_merge(project):
with pytest.raises(gitlab.GitlabMRClosedError):
# Two merge attempts should raise GitlabMRClosedError
mr.merge()


def test_merge_request_should_remove_source_branch(
project: gitlab.v4.objects.Project, wait_for_sidekiq
):
"""Test to ensure https://github.com/python-gitlab/python-gitlab/issues/1120
is fixed"""

source_branch = "remove_source_branch"
project.branches.create({"branch": source_branch, "ref": "master"})

# NOTE(jlvillal): Must create a commit in the new branch before we can
# create an MR that will work.
project.files.create(
{
"file_path": f"README.{source_branch}",
"branch": source_branch,
"content": "Initial content",
"commit_message": "New commit in new branch",
}
)

mr = project.mergerequests.create(
{
"source_branch": source_branch,
"target_branch": "master",
"title": "Should remove source branch",
"remove_source_branch": True,
}
)

result = wait_for_sidekiq(timeout=60)
assert result is True, "sidekiq process should have terminated but did not"

mr_iid = mr.iid
for _ in range(60):
mr = project.mergerequests.get(mr_iid)
if mr.merge_status != "checking":
break
time.sleep(0.5)
assert mr.merge_status != "checking"

# Ensure we can get the MR branch
project.branches.get(source_branch)

mr.merge(should_remove_source_branch=True)

result = wait_for_sidekiq(timeout=60)
assert result is True, "sidekiq process should have terminated but did not"

# Ensure we can NOT get the MR branch
with pytest.raises(gitlab.exceptions.GitlabGetError):
project.branches.get(source_branch)

mr = project.mergerequests.get(mr.iid)
assert mr.merged_at is not None # Now is merged

0 comments on commit 7d66115

Please sign in to comment.