66import responses
77
88from gitlab .v4 .objects import ProjectJobTokenScope
9+ from gitlab .v4 .objects .job_token_scope import (
10+ AllowlistedGroupManager ,
11+ AllowlistedProjectManager ,
12+ )
913
1014job_token_scope_content = {
1115 "inbound_enabled" : True ,
1216 "outbound_enabled" : False ,
1317}
1418
19+ project_allowlist_content = [
20+ {
21+ "id" : 4 ,
22+ "description" : "" ,
23+ "name" : "Diaspora Client" ,
24+ "name_with_namespace" : "Diaspora / Diaspora Client" ,
25+ "path" : "diaspora-client" ,
26+ "path_with_namespace" : "diaspora/diaspora-client" ,
27+ "created_at" : "2013-09-30T13:46:02Z" ,
28+ "default_branch" : "main" ,
29+ "tag_list" : ["example" , "disapora client" ],
30+ "topics" : ["example" , "disapora client" ],
31+ "ssh_url_to_repo" :
"[email protected] :diaspora/diaspora-client.git" ,
32+ "http_url_to_repo" : "https://gitlab.example.com/diaspora/diaspora-client.git" ,
33+ "web_url" : "https://gitlab.example.com/diaspora/diaspora-client" ,
34+ "avatar_url" : "https://gitlab.example.com/uploads/project/avatar/4/uploads/avatar.png" ,
35+ "star_count" : 0 ,
36+ "last_activity_at" : "2013-09-30T13:46:02Z" ,
37+ "namespace" : {
38+ "id" : 2 ,
39+ "name" : "Diaspora" ,
40+ "path" : "diaspora" ,
41+ "kind" : "group" ,
42+ "full_path" : "diaspora" ,
43+ "parent_id" : "" ,
44+ "avatar_url" : "" ,
45+ "web_url" : "https://gitlab.example.com/diaspora" ,
46+ },
47+ }
48+ ]
49+
50+ groups_allowlist_content = [
51+ {
52+ "id" : 4 ,
53+ "web_url" : "https://gitlab.example.com/groups/diaspora/diaspora-group" ,
54+ "name" : "namegroup" ,
55+ }
56+ ]
57+
1558
1659@pytest .fixture
1760def resp_get_job_token_scope ():
@@ -26,6 +69,32 @@ def resp_get_job_token_scope():
2669 yield rsps
2770
2871
72+ @pytest .fixture
73+ def resp_get_allowlist ():
74+ with responses .RequestsMock (assert_all_requests_are_fired = False ) as rsps :
75+ rsps .add (
76+ method = responses .GET ,
77+ url = "http://localhost/api/v4/projects/1/job_token_scope/allowlist" ,
78+ json = project_allowlist_content ,
79+ content_type = "application/json" ,
80+ status = 200 ,
81+ )
82+ yield rsps
83+
84+
85+ @pytest .fixture
86+ def resp_get_groups_allowlist ():
87+ with responses .RequestsMock (assert_all_requests_are_fired = False ) as rsps :
88+ rsps .add (
89+ method = responses .GET ,
90+ url = "http://localhost/api/v4/projects/1/job_token_scope/groups_allowlist" ,
91+ json = groups_allowlist_content ,
92+ content_type = "application/json" ,
93+ status = 200 ,
94+ )
95+ yield rsps
96+
97+
2998@pytest .fixture
3099def resp_patch_job_token_scope ():
31100 with responses .RequestsMock (assert_all_requests_are_fired = False ) as rsps :
@@ -61,3 +130,19 @@ def test_save_job_token_scope(job_token_scope, resp_patch_job_token_scope):
61130
62131def test_update_job_token_scope (project , resp_patch_job_token_scope ):
63132 project .job_token_scope .update (new_data = {"enabled" : False })
133+
134+
135+ def test_get_projects_allowlist (job_token_scope , resp_get_allowlist ):
136+ allowlist = job_token_scope .allowlist
137+ assert isinstance (allowlist , AllowlistedProjectManager )
138+
139+ allowlist_content = allowlist .list ()
140+ assert isinstance (allowlist_content , list )
141+
142+
143+ def test_get_groups_allowlist (job_token_scope , resp_get_groups_allowlist ):
144+ allowlist = job_token_scope .groups_allowlist
145+ assert isinstance (allowlist , AllowlistedGroupManager )
146+
147+ allowlist_content = allowlist .list ()
148+ assert isinstance (allowlist_content , list )
0 commit comments