1515
1616import pytest
1717import simcore_service_webserver
18+ import tenacity
1819from aiohttp .test_utils import TestClient
1920from common_library .json_serialization import json_dumps
2021from faker import Faker
@@ -191,9 +192,9 @@ async def logged_user(
191192 },
192193 check_if_succeeds = user_role != UserRole .ANONYMOUS ,
193194 ) as user :
194- print ("-----> logged in user" , user ["name" ], user_role )
195+ logging . info ("-----> logged in user %s %s " , user ["name" ], user_role )
195196 yield user
196- print ("<----- logged out user" , user ["name" ], user_role )
197+ logging . info ("<----- logged out user %s %s " , user ["name" ], user_role )
197198
198199
199200@pytest .fixture
@@ -206,14 +207,16 @@ def monkeypatch_setenv_from_app_config(
206207 def _patch (app_config : dict ) -> EnvVarsDict :
207208 assert isinstance (app_config , dict )
208209
209- print (" - app_config=\n " , json_dumps (app_config , indent = 1 , sort_keys = True ))
210+ logging .info (
211+ " - app_config=\n %s" , json_dumps (app_config , indent = 1 , sort_keys = True )
212+ )
210213 envs : EnvVarsDict = {
211214 env_key : f"{ env_value } "
212215 for env_key , env_value in convert_to_environ_vars (app_config ).items ()
213216 }
214217
215- print (
216- " - convert_to_environ_vars(app_cfg)=\n " ,
218+ logging . info (
219+ " - convert_to_environ_vars(app_cfg)=\n %s " ,
217220 json_dumps (envs , indent = 1 , sort_keys = True ),
218221 )
219222 return setenvs_from_dict (monkeypatch , envs )
@@ -351,7 +354,7 @@ async def _creator( # noqa: PLR0915
351354 resp = await client .post (
352355 f"{ url } " , json = project_data , headers = headers
353356 ) # NOTE: MD <-- here is project created!
354- print ( f "<-- created project response: { resp = } " )
357+ logging . info ( "<-- created project response: %r" , resp )
355358 data , error = await assert_status (resp , expected_accepted_response )
356359 if error :
357360 assert not data
@@ -371,31 +374,32 @@ async def _creator( # noqa: PLR0915
371374 retry = retry_if_exception_type (AssertionError ),
372375 ):
373376 with attempt :
374- print (
375- f "--> waiting for creation { attempt . retry_state . attempt_number } ..."
377+ logging . info (
378+ "--> waiting for creation %s..." , attempt . retry_state . attempt_number
376379 )
377380 result = await client .get (urlparse (status_url ).path )
378381 data , error = await assert_status (result , status .HTTP_200_OK )
379382 assert data
380383 assert not error
381384 task_status = TaskStatus .model_validate (data )
382385 assert task_status
383- print ( f "<-- status: { task_status .model_dump_json (indent = 2 )} " )
386+ logging . info ( "<-- status: %s" , task_status .model_dump_json (indent = 2 ))
384387 assert task_status .done , "task incomplete"
385- print (
386- f"-- project creation completed: { json .dumps (attempt .retry_state .retry_object .statistics , indent = 2 )} "
388+ logging .info (
389+ "-- project creation completed: %s" ,
390+ json .dumps (attempt .retry_state .retry_object .statistics , indent = 2 ),
387391 )
388392
389393 # get result GET /{task_id}/result
390- print ("--> getting project creation result..." )
394+ logging . info ("--> getting project creation result..." )
391395 result = await client .get (urlparse (result_url ).path )
392396 data , error = await assert_status (result , expected_creation_response )
393397 if error :
394398 assert not data
395399 return {}
396400 assert data
397401 assert not error
398- print ( f "<-- result: { data } " )
402+ logging . info ( "<-- result: %r" , data )
399403 new_project = data
400404
401405 # Setup access rights to the project
@@ -415,11 +419,11 @@ async def _creator( # noqa: PLR0915
415419 delete = permissions ["delete" ],
416420 )
417421 # Get project with already added access rights
418- print ("--> getting project groups after access rights change..." )
422+ logging . info ("--> getting project groups after access rights change..." )
419423 url = client .app .router ["list_project_groups" ].url_for (project_id = data ["uuid" ])
420424 resp = await client .get (url .path )
421425 data , error = await assert_status (resp , status .HTTP_200_OK )
422- print ( f "<-- result: { data } " )
426+ logging . info ( "<-- result: %r" , data )
423427 new_project_access_rights = {}
424428 for item in data :
425429 new_project_access_rights .update (
@@ -493,8 +497,35 @@ async def _creator( # noqa: PLR0915
493497
494498 # cleanup projects
495499 for client , project_uuid in zip (used_clients , created_project_uuids , strict = True ):
500+ # NOTE: delete does not wait for completion
496501 url = client .app .router ["delete_project" ].url_for (project_id = project_uuid )
497- await client .delete (url .path )
502+ resp = await client .delete (url .path )
503+
504+ if resp .ok :
505+ # NOTE: If deleted OK, then let's wait until project is really gone
506+ url = client .app .router ["get_project" ].url_for (project_id = project_uuid )
507+ async for attempt in AsyncRetrying (
508+ wait = wait_fixed (0.1 ),
509+ stop = stop_after_delay (10 ),
510+ reraise = True ,
511+ retry = retry_if_exception_type (tenacity .TryAgain ),
512+ ):
513+ with attempt :
514+ logging .info (
515+ "--> waiting for deletion %s..." ,
516+ attempt .retry_state .attempt_number ,
517+ )
518+ resp = await client .get (url .path )
519+ if resp .status == status .HTTP_200_OK :
520+ raise tenacity .TryAgain
521+
522+ await assert_status (resp , status .HTTP_404_NOT_FOUND )
523+ logging .info (
524+ "-- project deletion completed: %s" ,
525+ json .dumps (
526+ attempt .retry_state .retry_object .statistics , indent = 2
527+ ),
528+ )
498529
499530
500531@pytest .fixture
0 commit comments