|
| 1 | +""" |
| 2 | +GitLab API: https://docs.gitlab.com/ee/api/jobs.html#list-pipeline-bridges |
| 3 | +""" |
| 4 | +import re |
| 5 | + |
| 6 | +import pytest |
| 7 | +import responses |
| 8 | + |
| 9 | +from gitlab.v4.objects import Project, ProjectPipelineBridge |
| 10 | + |
| 11 | + |
| 12 | +@pytest.fixture |
| 13 | +def resp_list_bridges(): |
| 14 | + export_bridges_content = { |
| 15 | + "commit": { |
| 16 | + "author_email": "admin@example.com", |
| 17 | + "author_name": "Administrator", |
| 18 | + "created_at": "2015-12-24T16:51:14.000+01:00", |
| 19 | + "id": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", |
| 20 | + "message": "Test the CI integration.", |
| 21 | + "short_id": "0ff3ae19", |
| 22 | + "title": "Test the CI integration.", |
| 23 | + }, |
| 24 | + "allow_failure": False, |
| 25 | + "created_at": "2015-12-24T15:51:21.802Z", |
| 26 | + "started_at": "2015-12-24T17:54:27.722Z", |
| 27 | + "finished_at": "2015-12-24T17:58:27.895Z", |
| 28 | + "duration": 240, |
| 29 | + "id": 7, |
| 30 | + "name": "teaspoon", |
| 31 | + "pipeline": { |
| 32 | + "id": 6, |
| 33 | + "ref": "master", |
| 34 | + "sha": "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd", |
| 35 | + "status": "pending", |
| 36 | + "created_at": "2015-12-24T15:50:16.123Z", |
| 37 | + "updated_at": "2015-12-24T18:00:44.432Z", |
| 38 | + "web_url": "https://example.com/foo/bar/pipelines/6", |
| 39 | + }, |
| 40 | + "ref": "master", |
| 41 | + "stage": "test", |
| 42 | + "status": "pending", |
| 43 | + "tag": False, |
| 44 | + "web_url": "https://example.com/foo/bar/-/jobs/7", |
| 45 | + "user": { |
| 46 | + "id": 1, |
| 47 | + "name": "Administrator", |
| 48 | + "username": "root", |
| 49 | + "state": "active", |
| 50 | + "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", |
| 51 | + "web_url": "http://gitlab.dev/root", |
| 52 | + "created_at": "2015-12-21T13:14:24.077Z", |
| 53 | + "public_email": "", |
| 54 | + "skype": "", |
| 55 | + "linkedin": "", |
| 56 | + "twitter": "", |
| 57 | + "website_url": "", |
| 58 | + "organization": "", |
| 59 | + }, |
| 60 | + "downstream_pipeline": { |
| 61 | + "id": 5, |
| 62 | + "sha": "f62a4b2fb89754372a346f24659212eb8da13601", |
| 63 | + "ref": "master", |
| 64 | + "status": "pending", |
| 65 | + "created_at": "2015-12-24T17:54:27.722Z", |
| 66 | + "updated_at": "2015-12-24T17:58:27.896Z", |
| 67 | + "web_url": "https://example.com/diaspora/diaspora-client/pipelines/5", |
| 68 | + }, |
| 69 | + } |
| 70 | + |
| 71 | + export_pipelines_content = [ |
| 72 | + { |
| 73 | + "id": 6, |
| 74 | + "status": "pending", |
| 75 | + "ref": "new-pipeline", |
| 76 | + "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a", |
| 77 | + "web_url": "https://example.com/foo/bar/pipelines/47", |
| 78 | + "created_at": "2016-08-11T11:28:34.085Z", |
| 79 | + "updated_at": "2016-08-11T11:32:35.169Z", |
| 80 | + }, |
| 81 | + ] |
| 82 | + |
| 83 | + with responses.RequestsMock() as rsps: |
| 84 | + rsps.add( |
| 85 | + method=responses.GET, |
| 86 | + url="http://localhost/api/v4/projects/1/pipelines/6/bridges", |
| 87 | + json=[export_bridges_content], |
| 88 | + content_type="application/json", |
| 89 | + status=200, |
| 90 | + ) |
| 91 | + rsps.add( |
| 92 | + method=responses.GET, |
| 93 | + url="http://localhost/api/v4/projects/1/pipelines", |
| 94 | + json=export_pipelines_content, |
| 95 | + content_type="application/json", |
| 96 | + status=200, |
| 97 | + ) |
| 98 | + yield rsps |
| 99 | + |
| 100 | + |
| 101 | +def test_list_projects_pipelines_bridges(project, resp_list_bridges): |
| 102 | + pipeline = project.pipelines.list()[0] |
| 103 | + bridges = pipeline.bridges.list() |
| 104 | + |
| 105 | + assert isinstance(bridges, list) |
| 106 | + assert isinstance(bridges[0], ProjectPipelineBridge) |
| 107 | + assert bridges[0].downstream_pipeline["id"] == 5 |
| 108 | + assert ( |
| 109 | + bridges[0].downstream_pipeline["sha"] |
| 110 | + == "f62a4b2fb89754372a346f24659212eb8da13601" |
| 111 | + ) |
0 commit comments