|
| 1 | +import json |
| 2 | +import time |
| 3 | + |
| 4 | + |
1 | 5 | def test_project_create_file(gitlab_cli, project):
|
2 | 6 | file_path = "README"
|
3 | 7 | branch = "main"
|
@@ -45,6 +49,49 @@ def test_list_all_commits(gitlab_cli, project):
|
45 | 49 | assert len(ret_all.stdout) > len(ret.stdout)
|
46 | 50 |
|
47 | 51 |
|
| 52 | +def test_commit_merge_requests(gitlab_cli, project, merge_request, wait_for_sidekiq): |
| 53 | + """This tests the `project-commit merge-requests` command and also tests |
| 54 | + that we can print the result using the `json` formatter""" |
| 55 | + # create and then merge a merge-request |
| 56 | + source_branch = "test_commit_merge_requests" |
| 57 | + mr = merge_request(source_branch=source_branch) |
| 58 | + merge_result = mr.merge(should_remove_source_branch=True) |
| 59 | + result = wait_for_sidekiq(timeout=60) |
| 60 | + assert result is True, "sidekiq process should have terminated but did not" |
| 61 | + # Wait until it is merged |
| 62 | + mr_iid = mr.iid |
| 63 | + for _ in range(60): |
| 64 | + mr = project.mergerequests.get(mr_iid) |
| 65 | + if mr.merged_at is not None: |
| 66 | + break |
| 67 | + time.sleep(0.5) |
| 68 | + assert mr.merged_at is not None |
| 69 | + time.sleep(0.5) |
| 70 | + result = wait_for_sidekiq(timeout=60) |
| 71 | + assert result is True, "sidekiq process should have terminated but did not" |
| 72 | + |
| 73 | + commit_sha = merge_result["sha"] |
| 74 | + cmd = [ |
| 75 | + "-o", |
| 76 | + "json", |
| 77 | + "project-commit", |
| 78 | + "merge-requests", |
| 79 | + "--project-id", |
| 80 | + project.id, |
| 81 | + "--id", |
| 82 | + commit_sha, |
| 83 | + ] |
| 84 | + ret = gitlab_cli(cmd) |
| 85 | + assert ret.success |
| 86 | + |
| 87 | + json_list = json.loads(ret.stdout) |
| 88 | + assert isinstance(json_list, list) |
| 89 | + assert len(json_list) == 1 |
| 90 | + mr_dict = json_list[0] |
| 91 | + assert mr_dict["id"] == mr.id |
| 92 | + assert mr_dict["iid"] == mr.iid |
| 93 | + |
| 94 | + |
48 | 95 | def test_revert_commit(gitlab_cli, project):
|
49 | 96 | commit = project.commits.list()[0]
|
50 | 97 |
|
|
0 commit comments