|
| 1 | +""" |
| 2 | +GitLab API: |
| 3 | +https://docs.gitlab.com/ee/api/resource_groups.html |
| 4 | +""" |
| 5 | +import pytest |
| 6 | +import responses |
| 7 | + |
| 8 | +from gitlab.v4.objects import ProjectResourceGroup, ProjectResourceGroupUpcomingJob |
| 9 | + |
| 10 | +from .test_jobs import job_content |
| 11 | + |
| 12 | +resource_group_content = { |
| 13 | + "id": 3, |
| 14 | + "key": "production", |
| 15 | + "process_mode": "unordered", |
| 16 | + "created_at": "2021-09-01T08:04:59.650Z", |
| 17 | + "updated_at": "2021-09-01T08:04:59.650Z", |
| 18 | +} |
| 19 | + |
| 20 | + |
| 21 | +@pytest.fixture |
| 22 | +def resp_list_resource_groups(): |
| 23 | + with responses.RequestsMock() as rsps: |
| 24 | + rsps.add( |
| 25 | + method=responses.GET, |
| 26 | + url="http://localhost/api/v4/projects/1/resource_groups", |
| 27 | + json=[resource_group_content], |
| 28 | + content_type="application/json", |
| 29 | + status=200, |
| 30 | + ) |
| 31 | + yield rsps |
| 32 | + |
| 33 | + |
| 34 | +@pytest.fixture |
| 35 | +def resp_get_resource_group(): |
| 36 | + with responses.RequestsMock() as rsps: |
| 37 | + rsps.add( |
| 38 | + method=responses.GET, |
| 39 | + url="http://localhost/api/v4/projects/1/resource_groups/production", |
| 40 | + json=resource_group_content, |
| 41 | + content_type="application/json", |
| 42 | + status=200, |
| 43 | + ) |
| 44 | + yield rsps |
| 45 | + |
| 46 | + |
| 47 | +@pytest.fixture |
| 48 | +def resp_list_upcoming_jobs(): |
| 49 | + with responses.RequestsMock() as rsps: |
| 50 | + rsps.add( |
| 51 | + method=responses.GET, |
| 52 | + url="http://localhost/api/v4/projects/1/resource_groups/production/upcoming_jobs", |
| 53 | + json=[job_content], |
| 54 | + content_type="application/json", |
| 55 | + status=200, |
| 56 | + ) |
| 57 | + yield rsps |
| 58 | + |
| 59 | + |
| 60 | +def test_list_project_resource_groups(project, resp_list_resource_groups): |
| 61 | + resource_groups = project.resource_groups.list() |
| 62 | + assert isinstance(resource_groups, list) |
| 63 | + assert isinstance(resource_groups[0], ProjectResourceGroup) |
| 64 | + assert resource_groups[0].process_mode == "unordered" |
| 65 | + |
| 66 | + |
| 67 | +def test_get_project_resource_group(project, resp_get_resource_group): |
| 68 | + resource_group = project.resource_groups.get("production") |
| 69 | + assert isinstance(resource_group, ProjectResourceGroup) |
| 70 | + assert resource_group.process_mode == "unordered" |
| 71 | + |
| 72 | + |
| 73 | +def test_list_resource_group_upcoming_jobs(project, resp_list_upcoming_jobs): |
| 74 | + resource_group = project.resource_groups.get("production", lazy=True) |
| 75 | + upcoming_jobs = resource_group.upcoming_jobs.list() |
| 76 | + |
| 77 | + assert isinstance(upcoming_jobs, list) |
| 78 | + assert isinstance(upcoming_jobs[0], ProjectResourceGroupUpcomingJob) |
| 79 | + assert upcoming_jobs[0].ref == "main" |
0 commit comments