-
Notifications
You must be signed in to change notification settings - Fork 675
Expand file tree
/
Copy pathtest_cluster_agents.py
More file actions
97 lines (78 loc) · 2.65 KB
/
test_cluster_agents.py
File metadata and controls
97 lines (78 loc) · 2.65 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""
GitLab API: https://docs.gitlab.com/ee/api/cluster_agents.html
"""
import pytest
import responses
from gitlab.v4.objects import ProjectClusterAgent
agent_content = {
"id": 1,
"name": "agent-1",
"config_project": {
"id": 20,
"description": "",
"name": "test",
"name_with_namespace": "Administrator / test",
"path": "test",
"path_with_namespace": "root/test",
"created_at": "2022-03-20T20:42:40.221Z",
},
"created_at": "2022-04-20T20:42:40.221Z",
"created_by_user_id": 42,
}
@pytest.fixture
def resp_list_project_cluster_agents():
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.GET,
url="http://localhost/api/v4/projects/1/cluster_agents",
json=[agent_content],
content_type="application/json",
status=200,
)
yield rsps
@pytest.fixture
def resp_get_project_cluster_agent():
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.GET,
url="http://localhost/api/v4/projects/1/cluster_agents/1",
json=agent_content,
content_type="application/json",
status=200,
)
yield rsps
@pytest.fixture
def resp_create_project_cluster_agent():
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.POST,
url="http://localhost/api/v4/projects/1/cluster_agents",
json=agent_content,
content_type="application/json",
status=201,
)
yield rsps
@pytest.fixture
def resp_delete_project_cluster_agent():
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.DELETE,
url="http://localhost/api/v4/projects/1/cluster_agents/1",
status=204,
)
yield rsps
def test_list_project_cluster_agents(project, resp_list_project_cluster_agents):
agent = project.cluster_agents.list()[0]
assert isinstance(agent, ProjectClusterAgent)
assert agent.name == "agent-1"
def test_get_project_cluster_agent(project, resp_get_project_cluster_agent):
agent = project.cluster_agents.get(1)
assert isinstance(agent, ProjectClusterAgent)
assert agent.name == "agent-1"
def test_create_project_cluster_agent(project, resp_create_project_cluster_agent):
agent = project.cluster_agents.create({"name": "agent-1"})
assert isinstance(agent, ProjectClusterAgent)
assert agent.name == "agent-1"
def test_delete_project_cluster_agent(project, resp_delete_project_cluster_agent):
agent = project.cluster_agents.get(1, lazy=True)
agent.delete()