@@ -135,6 +135,67 @@ def test_apply_role_assignment(admin_api_client, rando, inv_rd, inventory):
135135 assert response .status_code == 200 , response .data
136136
137137
138+ @pytest .mark .django_db
139+ def test_unassign_endpoint (rando , org_inv_rd , inventory , admin_api_client ):
140+ org_inv_rd .give_permission (rando , inventory .organization )
141+ assert rando .has_obj_perm (inventory , 'change' )
142+
143+ url = get_relative_url ('serviceuserassignment-unassign' )
144+ data = {
145+ "role_definition" : org_inv_rd .name ,
146+ "user_ansible_id" : str (rando .resource .ansible_id ),
147+ "object_ansible_id" : str (inventory .organization .resource .ansible_id ),
148+ }
149+ response = admin_api_client .post (url , data )
150+ assert response .status_code == 204 , response .data
151+ assert not rando .has_obj_perm (inventory , 'change' )
152+
153+ # second gets a 200 code
154+ response = admin_api_client .post (url , data )
155+ assert response .status_code == 200 , response .data
156+ assert not rando .has_obj_perm (inventory , 'change' )
157+
158+
159+ # teams
160+ @pytest .mark .django_db
161+ def test_apply_role_assignment_for_team (admin_api_client , inv_rd , inventory , team , member_rd , rando ):
162+ member_rd .give_permission (rando , team )
163+ url = get_relative_url ('serviceteamassignment-assign' )
164+
165+ data = {"role_definition" : inv_rd .name , "team_ansible_id" : str (team .resource .ansible_id ), "object_id" : inventory .pk }
166+
167+ assert not rando .has_obj_perm (inventory , 'change' )
168+ response = admin_api_client .post (url , data = data )
169+ assert response .status_code == 201 , response .data
170+ assert rando .has_obj_perm (inventory , 'change' )
171+
172+ # Second try, response code indicates assignment already exists
173+ response = admin_api_client .post (url , data = data )
174+ assert response .status_code == 200 , response .data
175+
176+
177+ @pytest .mark .django_db
178+ def test_unassign_endpoint_for_team (team , org_inv_rd , inventory , admin_api_client , member_rd , rando ):
179+ member_rd .give_permission (rando , team )
180+ org_inv_rd .give_permission (team , inventory .organization )
181+ assert rando .has_obj_perm (inventory , 'change' )
182+
183+ url = get_relative_url ('serviceteamassignment-unassign' )
184+ data = {
185+ "role_definition" : org_inv_rd .name ,
186+ "team_ansible_id" : str (team .resource .ansible_id ),
187+ "object_ansible_id" : str (inventory .organization .resource .ansible_id ),
188+ }
189+ response = admin_api_client .post (url , data )
190+ assert response .status_code == 204 , response .data
191+ assert not rando .has_obj_perm (inventory , 'change' )
192+
193+ # second gets a 200 code
194+ response = admin_api_client .post (url , data )
195+ assert response .status_code == 200 , response .data
196+ assert not rando .has_obj_perm (inventory , 'change' )
197+
198+
138199@pytest .mark .django_db
139200def test_filter_assignment_list (admin_api_client , rando , inv_rd , view_inv_rd , org_inv_rd , inventory ):
140201 inv_rd .give_permission (rando , inventory )
@@ -165,27 +226,6 @@ def test_filter_assignment_list(admin_api_client, rando, inv_rd, view_inv_rd, or
165226 assert response .data ['count' ] == 2
166227
167228
168- @pytest .mark .django_db
169- def test_unassign_endpoint (rando , org_inv_rd , inventory , admin_api_client ):
170- org_inv_rd .give_permission (rando , inventory .organization )
171- assert rando .has_obj_perm (inventory , 'change' )
172-
173- url = get_relative_url ('serviceuserassignment-unassign' )
174- data = {
175- "role_definition" : org_inv_rd .name ,
176- "user_ansible_id" : str (rando .resource .ansible_id ),
177- "object_ansible_id" : str (inventory .organization .resource .ansible_id ),
178- }
179- response = admin_api_client .post (url , data )
180- assert response .status_code == 204 , response .data
181- assert not rando .has_obj_perm (inventory , 'change' )
182-
183- # second gets a 200 code
184- response = admin_api_client .post (url , data )
185- assert response .status_code == 200 , response .data
186- assert not rando .has_obj_perm (inventory , 'change' )
187-
188-
189229@pytest .mark .django_db
190230@pytest .mark .parametrize (
191231 'reverse_name,normal_case,unauth_case' ,
@@ -194,8 +234,8 @@ def test_unassign_endpoint(rando, org_inv_rd, inventory, admin_api_client):
194234 ('dabpermission-list' , 200 , 401 ),
195235 ('resource-list' , 403 , 401 ),
196236 ('serviceuserassignment-list' , 403 , 401 ),
197- ('serviceteamassignment-list' , 403 , 401 )
198- ]
237+ ('serviceteamassignment-list' , 403 , 401 ),
238+ ],
199239)
200240def test_service_api_permissions (reverse_name , normal_case , unauth_case , admin_api_client , user_api_client , unauthenticated_api_client ):
201241 url = get_relative_url (reverse_name )
0 commit comments