summaryrefslogtreecommitdiff
path: root/tests/unit/objects/test_resource_groups.py
blob: dd579ac11ebd6d589ff037a77287b33242e5177e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
GitLab API:
https://docs.gitlab.com/ee/api/resource_groups.html
"""
import pytest
import responses

from gitlab.v4.objects import ProjectResourceGroup, ProjectResourceGroupUpcomingJob

from .test_jobs import job_content

resource_group_content = {
    "id": 3,
    "key": "production",
    "process_mode": "unordered",
    "created_at": "2021-09-01T08:04:59.650Z",
    "updated_at": "2021-09-01T08:04:59.650Z",
}


@pytest.fixture
def resp_list_resource_groups():
    with responses.RequestsMock() as rsps:
        rsps.add(
            method=responses.GET,
            url="http://localhost/api/v4/projects/1/resource_groups",
            json=[resource_group_content],
            content_type="application/json",
            status=200,
        )
        yield rsps


@pytest.fixture
def resp_get_resource_group():
    with responses.RequestsMock() as rsps:
        rsps.add(
            method=responses.GET,
            url="http://localhost/api/v4/projects/1/resource_groups/production",
            json=resource_group_content,
            content_type="application/json",
            status=200,
        )
        yield rsps


@pytest.fixture
def resp_list_upcoming_jobs():
    with responses.RequestsMock() as rsps:
        rsps.add(
            method=responses.GET,
            url="http://localhost/api/v4/projects/1/resource_groups/production/upcoming_jobs",
            json=[job_content],
            content_type="application/json",
            status=200,
        )
        yield rsps


def test_list_project_resource_groups(project, resp_list_resource_groups):
    resource_groups = project.resource_groups.list()
    assert isinstance(resource_groups, list)
    assert isinstance(resource_groups[0], ProjectResourceGroup)
    assert resource_groups[0].process_mode == "unordered"


def test_get_project_resource_group(project, resp_get_resource_group):
    resource_group = project.resource_groups.get("production")
    assert isinstance(resource_group, ProjectResourceGroup)
    assert resource_group.process_mode == "unordered"


def test_list_resource_group_upcoming_jobs(project, resp_list_upcoming_jobs):
    resource_group = project.resource_groups.get("production", lazy=True)
    upcoming_jobs = resource_group.upcoming_jobs.list()

    assert isinstance(upcoming_jobs, list)
    assert isinstance(upcoming_jobs[0], ProjectResourceGroupUpcomingJob)
    assert upcoming_jobs[0].ref == "main"