@@ -118,14 +118,12 @@ async def test_add_remove_users_from_group(
118118 # we get all rights on the group since we are the creator
119119 assert assigned_group ["accessRights" ] == _DEFAULT_GROUP_OWNER_ACCESS_RIGHTS
120120
121+ group_id = assigned_group ["gid" ]
122+
121123 # check that our user is in the group of users
122- get_group_users_url = client .app .router ["get_all_group_users" ].url_for (
123- gid = f"{ assigned_group ['gid' ]} "
124- )
125- assert (
126- f"{ get_group_users_url } " == f"/{ API_VTAG } /groups/{ assigned_group ['gid' ]} /users"
127- )
128- resp = await client .get (f"{ get_group_users_url } " )
124+ url = client .app .router ["get_all_group_users" ].url_for (gid = f"{ group_id } " )
125+ assert f"{ url } " == f"/{ API_VTAG } /groups/{ group_id } /users"
126+ resp = await client .get (f"{ url } " )
129127 data , error = await assert_status (resp , expected .ok )
130128
131129 if not error :
@@ -140,15 +138,8 @@ async def test_add_remove_users_from_group(
140138 )
141139
142140 # create a random number of users and put them in the group
143- add_group_user_url = client .app .router ["add_group_user" ].url_for (
144- gid = f"{ assigned_group ['gid' ]} "
145- )
146- assert (
147- f"{ add_group_user_url } " == f"/{ API_VTAG } /groups/{ assigned_group ['gid' ]} /users"
148- )
149141 num_new_users = faker .random_int (1 , 10 )
150142 created_users_list = []
151-
152143 async with AsyncExitStack () as users_stack :
153144 for i in range (num_new_users ):
154145
@@ -164,31 +155,27 @@ async def test_add_remove_users_from_group(
164155 user_id = created_users_list [i ]["id" ]
165156 user_email = created_users_list [i ]["email" ]
166157
158+ # ADD
159+ url = client .app .router ["add_group_user" ].url_for (gid = f"{ group_id } " )
160+ assert f"{ url } " == f"/{ API_VTAG } /groups/{ group_id } /users"
167161 if is_private :
168162 # only if privacy allows
169- resp = await client .post (
170- f"{ add_group_user_url } " , json = {"email" : user_email }
171- )
163+ resp = await client .post (f"{ url } " , json = {"email" : user_email })
172164 data , error = await assert_status (resp , expected .not_found )
173165
174166 # always allowed
175- resp = await client .post (f"{ add_group_user_url } " , json = {"uid" : user_id })
167+ resp = await client .post (f"{ url } " , json = {"uid" : user_id })
176168 await assert_status (resp , expected .no_content )
177169 else :
178170 # both work
179- resp = await client .post (
180- f"{ add_group_user_url } " , json = {"email" : user_email }
181- )
171+ resp = await client .post (f"{ url } " , json = {"email" : user_email })
182172 await assert_status (resp , expected .no_content )
183173
184174 # GET
185175 url = client .app .router ["get_group_user" ].url_for (
186- gid = f"{ assigned_group ['gid' ]} " , uid = f"{ created_users_list [i ]['id' ]} "
187- )
188- assert (
189- f"{ url } "
190- == f"/{ API_VTAG } /groups/{ assigned_group ['gid' ]} /users/{ created_users_list [i ]['id' ]} "
176+ gid = f"{ group_id } " , uid = f"{ user_id } "
191177 )
178+ assert f"{ url } " == f"/{ API_VTAG } /groups/{ group_id } /users/{ user_id } "
192179 resp = await client .get (f"{ url } " )
193180 data , error = await assert_status (resp , expected .ok )
194181 if not error :
@@ -199,37 +186,37 @@ async def test_add_remove_users_from_group(
199186 group_owner_id = the_owner ["id" ] if is_private else user_id ,
200187 )
201188
202- # check list is correct
203- resp = await client .get (f"{ get_group_users_url } " )
189+ # LIST: check list is correct
190+ url = client .app .router ["get_all_group_users" ].url_for (gid = f"{ group_id } " )
191+ resp = await client .get (f"{ url } " )
204192 data , error = await assert_status (resp , expected .ok )
205193 if not error :
206194 list_of_users = data
207195
208196 # now we should have all the users in the group + the owner
209197 all_created_users = [* created_users_list , logged_user ]
210- assert len (list_of_users ) == len (all_created_users )
211- for actual_user in list_of_users :
212- expected_users_list = [
213- usr for usr in all_created_users if usr ["id" ] == actual_user ["id" ]
214- ]
215- assert len (expected_users_list ) == 1
216- expected_user = expected_users_list [0 ]
217198
218- expected_access_rigths = _DEFAULT_GROUP_READ_ACCESS_RIGHTS
219- if actual_user ["id" ] == logged_user ["id" ]:
220- expected_access_rigths = _DEFAULT_GROUP_OWNER_ACCESS_RIGHTS
199+ assert len (list_of_users ) == len (all_created_users )
200+ for user in list_of_users :
201+ expected_user : UserInfoDict = next (
202+ u for u in all_created_users if int (u ["id" ]) == int (user ["id" ])
203+ )
204+ expected_access_rigths = (
205+ _DEFAULT_GROUP_OWNER_ACCESS_RIGHTS
206+ if int (user ["id" ]) == int (logged_user ["id" ])
207+ else _DEFAULT_GROUP_READ_ACCESS_RIGHTS
208+ )
221209
222210 _assert__group_user (
223211 expected_user ,
224212 expected_access_rigths ,
225- actual_user ,
213+ user ,
226214 group_owner_id = the_owner ["id" ]
227- if actual_user .get ("is_private" , False )
228- else actual_user ["id" ],
215+ if expected_user .get ("is_private" , False )
216+ else user ["id" ],
229217 )
230- all_created_users .remove (expected_users_list [0 ])
231218
232- # modify the user and remove them from the group
219+ # PATCH the user and REMOVE them from the group
233220 MANAGER_ACCESS_RIGHTS : AccessRightsDict = {
234221 "read" : True ,
235222 "write" : True ,
@@ -240,6 +227,7 @@ async def test_add_remove_users_from_group(
240227 user_id = created_users_list [i ]["id" ]
241228 is_private = created_users_list [i ].get ("is_private" , False )
242229
230+ # PATCH access-rights
243231 url = client .app .router ["update_group_user" ].url_for (
244232 gid = f"{ group_id } " , uid = f"{ user_id } "
245233 )
@@ -255,7 +243,7 @@ async def test_add_remove_users_from_group(
255243 group_owner_id = the_owner ["id" ] if is_private else user_id ,
256244 )
257245
258- # check it is there
246+ # GET: check it is there
259247 url = client .app .router ["get_group_user" ].url_for (
260248 gid = f"{ group_id } " , uid = f"{ user_id } "
261249 )
@@ -269,18 +257,18 @@ async def test_add_remove_users_from_group(
269257 group_owner_id = the_owner ["id" ] if is_private else user_id ,
270258 )
271259
272- # remove the user from the group
260+ # REMOVE the user from the group
273261 url = client .app .router ["delete_group_user" ].url_for (
274262 gid = f"{ group_id } " , uid = f"{ user_id } "
275263 )
276264 resp = await client .delete (f"{ url } " )
277265 data , error = await assert_status (resp , expected .no_content )
278266
279- # do it again to check it is not found anymore
267+ # REMOVE: do it again to check it is not found anymore
280268 resp = await client .delete (f"{ url } " )
281269 data , error = await assert_status (resp , expected .not_found )
282270
283- # check it is not there anymore
271+ # GET check it is not there anymore
284272 url = client .app .router ["get_group_user" ].url_for (
285273 gid = f"{ group_id } " , uid = f"{ user_id } "
286274 )
0 commit comments