@@ -191,6 +191,33 @@ def _wait(timeout=30, step=0.5):
191
191
return _wait
192
192
193
193
194
+ def wait_for_deleted (
195
+ * ,
196
+ pg_manager : gitlab .base .RESTManager ,
197
+ object_id : int ,
198
+ description : str ,
199
+ hard_delete : bool = False ,
200
+ ) -> None :
201
+ """Ensure the object specified can not be retrieved. If object still exists after
202
+ timeout period, fail the test"""
203
+ max_iterations = int (TIMEOUT / SLEEP_INTERVAL )
204
+
205
+ for _ in range (max_iterations ):
206
+ try :
207
+ object = pg_manager .get (object_id )
208
+ except gitlab .exceptions .GitlabGetError :
209
+ return
210
+ try :
211
+ if hard_delete :
212
+ object .delete (hard_delete = True )
213
+ else :
214
+ object .delete ()
215
+ except gitlab .exceptions .GitlabDeleteError :
216
+ pass
217
+ time .sleep (SLEEP_INTERVAL )
218
+ pytest .fail (f"{ description } { object_id } was not deleted" )
219
+
220
+
194
221
@pytest .fixture (scope = "session" )
195
222
def gitlab_config (check_is_alive , docker_ip , docker_services , temp_dir , fixture_dir ):
196
223
config_file = temp_dir / "python-gitlab.cfg"
@@ -277,6 +304,7 @@ def group(gl):
277
304
"path" : f"group-{ _id } " ,
278
305
}
279
306
group = gl .groups .create (data )
307
+ group_id = group .id
280
308
281
309
yield group
282
310
@@ -285,6 +313,8 @@ def group(gl):
285
313
except gitlab .exceptions .GitlabDeleteError as e :
286
314
print (f"Group already deleted: { e } " )
287
315
316
+ wait_for_deleted (pg_manager = gl .groups , object_id = group_id , description = "Group" )
317
+
288
318
289
319
@pytest .fixture (scope = "module" )
290
320
def project (gl ):
@@ -293,6 +323,7 @@ def project(gl):
293
323
name = f"test-project-{ _id } "
294
324
295
325
project = gl .projects .create (name = name )
326
+ project_id = project .id
296
327
297
328
yield project
298
329
@@ -301,6 +332,10 @@ def project(gl):
301
332
except gitlab .exceptions .GitlabDeleteError as e :
302
333
print (f"Project already deleted: { e } " )
303
334
335
+ wait_for_deleted (
336
+ pg_manager = gl .projects , object_id = project_id , description = "Project"
337
+ )
338
+
304
339
305
340
@pytest .fixture (scope = "function" )
306
341
def merge_request (project , wait_for_sidekiq ):
@@ -372,6 +407,18 @@ def _merge_request(*, source_branch: str):
372
407
# Ignore if branch was already deleted
373
408
pass
374
409
410
+ for mr_iid , source_branch in to_delete :
411
+ wait_for_deleted (
412
+ pg_manager = project .mergerequests ,
413
+ object_id = mr_iid ,
414
+ description = "Project mergerequest" ,
415
+ )
416
+ wait_for_deleted (
417
+ pg_manager = project .branches ,
418
+ object_id = source_branch ,
419
+ description = "Project branch" ,
420
+ )
421
+
375
422
376
423
@pytest .fixture (scope = "module" )
377
424
def project_file (project ):
@@ -431,6 +478,7 @@ def user(gl):
431
478
password = "fakepassword"
432
479
433
480
user = gl .users .create (email = email , username = username , name = name , password = password )
481
+ user_id = user .id
434
482
435
483
yield user
436
484
@@ -440,6 +488,10 @@ def user(gl):
440
488
except gitlab .exceptions .GitlabDeleteError as e :
441
489
print (f"User already deleted: { e } " )
442
490
491
+ wait_for_deleted (
492
+ pg_manager = gl .users , object_id = user_id , description = "User" , hard_delete = True
493
+ )
494
+
443
495
444
496
@pytest .fixture (scope = "module" )
445
497
def issue (project ):
0 commit comments