|
| 1 | +""" |
| 2 | +GitLab API: |
| 3 | +https://docs.gitlab.com/ee/api/merge_trains.html |
| 4 | +""" |
| 5 | +importpytest |
| 6 | +importresponses |
| 7 | + |
| 8 | +fromgitlab.v4.objectsimportProjectMergeTrain |
| 9 | + |
| 10 | +mr_content= { |
| 11 | +"id":110, |
| 12 | +"merge_request": { |
| 13 | +"id":1, |
| 14 | +"iid":1, |
| 15 | +"project_id":3, |
| 16 | +"title":"Test merge train", |
| 17 | +"description":"", |
| 18 | +"state":"merged", |
| 19 | +"created_at":"2020-02-06T08:39:14.883Z", |
| 20 | +"updated_at":"2020-02-06T08:40:57.038Z", |
| 21 | +"web_url":"http://gitlab.example.com/root/merge-train-race-condition/-/merge_requests/1", |
| 22 | + }, |
| 23 | +"user": { |
| 24 | +"id":1, |
| 25 | +"name":"Administrator", |
| 26 | +"username":"root", |
| 27 | +"state":"active", |
| 28 | +"avatar_url":"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", |
| 29 | +"web_url":"http://gitlab.example.com/root", |
| 30 | + }, |
| 31 | +"pipeline": { |
| 32 | +"id":246, |
| 33 | +"sha":"bcc17a8ffd51be1afe45605e714085df28b80b13", |
| 34 | +"ref":"refs/merge-requests/1/train", |
| 35 | +"status":"success", |
| 36 | +"created_at":"2020-02-06T08:40:42.410Z", |
| 37 | +"updated_at":"2020-02-06T08:40:46.912Z", |
| 38 | +"web_url":"http://gitlab.example.com/root/merge-train-race-condition/pipelines/246", |
| 39 | + }, |
| 40 | +"created_at":"2020-02-06T08:39:47.217Z", |
| 41 | +"updated_at":"2020-02-06T08:40:57.720Z", |
| 42 | +"target_branch":"feature-1580973432", |
| 43 | +"status":"merged", |
| 44 | +"merged_at":"2020-02-06T08:40:57.719Z", |
| 45 | +"duration":70, |
| 46 | +} |
| 47 | + |
| 48 | + |
| 49 | +@pytest.fixture |
| 50 | +defresp_list_merge_trains(): |
| 51 | +withresponses.RequestsMock()asrsps: |
| 52 | +rsps.add( |
| 53 | +method=responses.GET, |
| 54 | +url="http://localhost/api/v4/projects/1/merge_trains", |
| 55 | +json=[mr_content], |
| 56 | +content_type="application/json", |
| 57 | +status=200, |
| 58 | + ) |
| 59 | +yieldrsps |
| 60 | + |
| 61 | + |
| 62 | +deftest_list_project_merge_requests(project,resp_list_merge_trains): |
| 63 | +merge_trains=project.merge_trains.list() |
| 64 | +assertisinstance(merge_trains[0],ProjectMergeTrain) |
| 65 | +assertmerge_trains[0].id==mr_content["id"] |