-
Notifications
You must be signed in to change notification settings - Fork 676
Expand file tree
/
Copy pathtest_status_checks.py
More file actions
127 lines (107 loc) · 3.87 KB
/
test_status_checks.py
File metadata and controls
127 lines (107 loc) · 3.87 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""
GitLab API: https://docs.gitlab.com/ee/api/status_checks.html
"""
import pytest
import responses
@pytest.fixture
def external_status_check():
return {
"id": 1,
"name": "MR blocker",
"project_id": 1,
"external_url": "https://example.com/mr-blocker",
"hmac": True,
"protected_branches": [
{
"id": 1,
"project_id": 1,
"name": "main",
"created_at": "2020-10-12T14:04:50.787Z",
"updated_at": "2020-10-12T14:04:50.787Z",
"code_owner_approval_required": False,
}
],
}
@pytest.fixture
def updated_external_status_check():
return {
"id": 1,
"name": "Updated MR blocker",
"project_id": 1,
"external_url": "https://example.com/mr-blocker",
"hmac": True,
"protected_branches": [
{
"id": 1,
"project_id": 1,
"name": "main",
"created_at": "2020-10-12T14:04:50.787Z",
"updated_at": "2020-10-12T14:04:50.787Z",
"code_owner_approval_required": False,
}
],
}
@pytest.fixture
def resp_list_external_status_checks(external_status_check):
with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
rsps.add(
method=responses.GET,
url="http://localhost/api/v4/projects/1/external_status_checks",
json=[external_status_check],
content_type="application/json",
status=200,
)
yield rsps
@pytest.fixture
def resp_create_external_status_checks(external_status_check):
with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
rsps.add(
method=responses.POST,
url="http://localhost/api/v4/projects/1/external_status_checks",
json=external_status_check,
content_type="application/json",
status=200,
)
yield rsps
@pytest.fixture
def resp_update_external_status_checks(updated_external_status_check):
with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
rsps.add(
method=responses.PUT,
url="http://localhost/api/v4/groups/1/external_status_checks",
json=updated_external_status_check,
content_type="application/json",
status=200,
)
yield rsps
@pytest.fixture
def resp_delete_external_status_checks():
content = []
with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
rsps.add(
method=responses.DELETE,
url="http://localhost/api/v4/projects/1/external_status_checks/1",
status=204,
)
rsps.add(
method=responses.GET,
url="http://localhost/api/v4/projects/1/external_status_checks",
json=content,
content_type="application/json",
status=200,
)
yield rsps
def test_list_external_status_checks(gl, resp_list_external_status_checks):
status_checks = gl.projects.get(1, lazy=True).external_status_checks.list()
assert len(status_checks) == 1
assert status_checks[0].name == "MR blocker"
def test_create_external_status_checks(gl, resp_create_external_status_checks):
access_token = gl.projects.get(1, lazy=True).external_status_checks.create(
{"name": "MR blocker", "external_url": "https://example.com/mr-blocker"}
)
assert access_token.name == "MR blocker"
assert access_token.external_url == "https://example.com/mr-blocker"
def test_delete_external_status_checks(gl, resp_delete_external_status_checks):
gl.projects.get(1, lazy=True).external_status_checks.delete(1)
status_checks = gl.projects.get(1, lazy=True).external_status_checks.list()
assert len(status_checks) == 0