6
6
import responses
7
7
8
8
from gitlab .v4 .objects import ProjectJobTokenScope
9
+ from gitlab .v4 .objects .job_token_scope import (
10
+ AllowlistedGroupManager ,
11
+ AllowlistedProjectManager ,
12
+ )
9
13
10
14
job_token_scope_content = {
11
15
"inbound_enabled" : True ,
12
16
"outbound_enabled" : False ,
13
17
}
14
18
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" : "git@gitlab.example.com: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
+
15
58
16
59
@pytest .fixture
17
60
def resp_get_job_token_scope ():
@@ -26,6 +69,32 @@ def resp_get_job_token_scope():
26
69
yield rsps
27
70
28
71
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
+
29
98
@pytest .fixture
30
99
def resp_patch_job_token_scope ():
31
100
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):
61
130
62
131
def test_update_job_token_scope (project , resp_patch_job_token_scope ):
63
132
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