Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0481c52

Browse files
committed
test: add unit tests for job_token_scope
Signed-off-by: Tim Knight <tim.knight1@engineering.digital.dwp.gov.uk>
1 parent3c210c3 commit0481c52

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

‎gitlab/v4/objects/job_token_scope.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class AllowlistedGroup(ObjectDeleteMixin, RESTObject):
6262

6363
defget_id(self)->int:
6464
"""Returns the id of the resource. This override deals with
65-
the fact that either an `id` or a `target_project_id` attribute
65+
the fact that either an `id` or a `target_group_id` attribute
6666
is returned by the server depending on the endpoint called."""
6767
try:
6868
returncast(int,getattr(self,self._id_attr))

‎tests/unit/objects/test_job_token_scope.py‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747
}
4848
]
4949

50+
project_allowlist_created_content= {
51+
"target_project_id":2,
52+
"project_id":1,
53+
}
54+
5055
groups_allowlist_content= [
5156
{
5257
"id":4,
@@ -55,6 +60,11 @@
5560
}
5661
]
5762

63+
group_allowlist_created_content= {
64+
"target_group_id":4,
65+
"project_id":1,
66+
}
67+
5868

5969
@pytest.fixture
6070
defresp_get_job_token_scope():
@@ -82,6 +92,19 @@ def resp_get_allowlist():
8292
yieldrsps
8393

8494

95+
@pytest.fixture
96+
defresp_add_to_allowlist():
97+
withresponses.RequestsMock(assert_all_requests_are_fired=False)asrsps:
98+
rsps.add(
99+
method=responses.POST,
100+
url="http://localhost/api/v4/projects/1/job_token_scope/allowlist",
101+
json=project_allowlist_created_content,
102+
content_type="application/json",
103+
status=200,
104+
)
105+
yieldrsps
106+
107+
85108
@pytest.fixture
86109
defresp_get_groups_allowlist():
87110
withresponses.RequestsMock(assert_all_requests_are_fired=False)asrsps:
@@ -95,6 +118,19 @@ def resp_get_groups_allowlist():
95118
yieldrsps
96119

97120

121+
@pytest.fixture
122+
defresp_add_to_groups_allowlist():
123+
withresponses.RequestsMock(assert_all_requests_are_fired=False)asrsps:
124+
rsps.add(
125+
method=responses.POST,
126+
url="http://localhost/api/v4/projects/1/job_token_scope/groups_allowlist",
127+
json=group_allowlist_created_content,
128+
content_type="application/json",
129+
status=200,
130+
)
131+
yieldrsps
132+
133+
98134
@pytest.fixture
99135
defresp_patch_job_token_scope():
100136
withresponses.RequestsMock(assert_all_requests_are_fired=False)asrsps:
@@ -140,9 +176,25 @@ def test_get_projects_allowlist(job_token_scope, resp_get_allowlist):
140176
assertisinstance(allowlist_content,list)
141177

142178

179+
deftest_add_project_to_allowlist(job_token_scope,resp_add_to_allowlist):
180+
allowlist=job_token_scope.allowlist
181+
assertisinstance(allowlist,AllowlistedProjectManager)
182+
183+
resp=allowlist.create({"target_project_id":2})
184+
assertresp.get_id()==2
185+
186+
143187
deftest_get_groups_allowlist(job_token_scope,resp_get_groups_allowlist):
144188
allowlist=job_token_scope.groups_allowlist
145189
assertisinstance(allowlist,AllowlistedGroupManager)
146190

147191
allowlist_content=allowlist.list()
148192
assertisinstance(allowlist_content,list)
193+
194+
195+
deftest_add_group_to_allowlist(job_token_scope,resp_add_to_groups_allowlist):
196+
allowlist=job_token_scope.groups_allowlist
197+
assertisinstance(allowlist,AllowlistedGroupManager)
198+
199+
resp=allowlist.create({"target_group_id":4})
200+
assertresp.get_id()==4

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp