4747 }
4848]
4949
50+ project_allowlist_created_content = {
51+ "target_project_id" : 2 ,
52+ "project_id" : 1 ,
53+ }
54+
5055groups_allowlist_content = [
5156 {
5257 "id" : 4 ,
5560 }
5661]
5762
63+ group_allowlist_created_content = {
64+ "target_group_id" : 4 ,
65+ "project_id" : 1 ,
66+ }
67+
5868
5969@pytest .fixture
6070def resp_get_job_token_scope ():
@@ -82,6 +92,19 @@ def resp_get_allowlist():
8292 yield rsps
8393
8494
95+ @pytest .fixture
96+ def resp_add_to_allowlist ():
97+ with responses .RequestsMock (assert_all_requests_are_fired = False ) as rsps :
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+ yield rsps
106+
107+
85108@pytest .fixture
86109def resp_get_groups_allowlist ():
87110 with responses .RequestsMock (assert_all_requests_are_fired = False ) as rsps :
@@ -95,6 +118,19 @@ def resp_get_groups_allowlist():
95118 yield rsps
96119
97120
121+ @pytest .fixture
122+ def resp_add_to_groups_allowlist ():
123+ with responses .RequestsMock (assert_all_requests_are_fired = False ) as rsps :
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+ yield rsps
132+
133+
98134@pytest .fixture
99135def resp_patch_job_token_scope ():
100136 with responses .RequestsMock (assert_all_requests_are_fired = False ) as rsps :
@@ -140,9 +176,25 @@ def test_get_projects_allowlist(job_token_scope, resp_get_allowlist):
140176 assert isinstance (allowlist_content , list )
141177
142178
179+ def test_add_project_to_allowlist (job_token_scope , resp_add_to_allowlist ):
180+ allowlist = job_token_scope .allowlist
181+ assert isinstance (allowlist , AllowlistedProjectManager )
182+
183+ resp = allowlist .create ({"target_project_id" : 2 })
184+ assert resp .get_id () == 2
185+
186+
143187def test_get_groups_allowlist (job_token_scope , resp_get_groups_allowlist ):
144188 allowlist = job_token_scope .groups_allowlist
145189 assert isinstance (allowlist , AllowlistedGroupManager )
146190
147191 allowlist_content = allowlist .list ()
148192 assert isinstance (allowlist_content , list )
193+
194+
195+ def test_add_group_to_allowlist (job_token_scope , resp_add_to_groups_allowlist ):
196+ allowlist = job_token_scope .groups_allowlist
197+ assert isinstance (allowlist , AllowlistedGroupManager )
198+
199+ resp = allowlist .create ({"target_group_id" : 4 })
200+ assert resp .get_id () == 4
0 commit comments