88import  asyncio 
99from  asyncio  import  Future 
1010from  collections .abc  import  AsyncIterator , Awaitable , Callable 
11- from  copy  import  deepcopy 
1211from  pathlib  import  Path 
1312from  typing  import  Any 
1413from  unittest  import  mock 
2827from  pytest_mock  import  MockerFixture 
2928from  pytest_simcore .helpers .assert_checks  import  assert_status 
3029from  pytest_simcore .helpers .monkeypatch_envs  import  setenvs_from_dict 
30+ from  pytest_simcore .helpers .typing_env  import  EnvVarsDict 
3131from  pytest_simcore .helpers .webserver_login  import  UserInfoDict 
3232from  pytest_simcore .helpers .webserver_parametrizations  import  MockedStorageSubsystem 
3333from  pytest_simcore .helpers .webserver_projects  import  NewProject 
3737from  servicelib .aiohttp .application_setup  import  is_setup_completed 
3838from  servicelib .common_headers  import  UNDEFINED_DEFAULT_SIMCORE_USER_AGENT_VALUE 
3939from  simcore_postgres_database .models .users  import  UserRole 
40- from  simcore_service_webserver ._meta  import  API_VTAG 
4140from  simcore_service_webserver .application_settings  import  setup_settings 
41+ from  simcore_service_webserver .application_settings_utils  import  AppConfigDict 
4242from  simcore_service_webserver .db .plugin  import  setup_db 
4343from  simcore_service_webserver .director_v2 .plugin  import  setup_director_v2 
4444from  simcore_service_webserver .garbage_collector  import  _core  as  gc_core 
@@ -104,45 +104,44 @@ async def _open_project(client, project_uuid: str, client_session_id: str) -> No
104104
105105@pytest .fixture  
106106def  app_environment (
107-     app_environment : dict [str , str ], monkeypatch : pytest .MonkeyPatch 
108- ) ->  dict [str , str ]:
109-     overrides  =  setenvs_from_dict (
107+     monkeypatch : pytest .MonkeyPatch ,
108+     app_environment : EnvVarsDict ,
109+ ) ->  EnvVarsDict :
110+ 
111+     # NOTE: undos some app_environment settings 
112+     monkeypatch .delenv ("WEBSERVER_GARBAGE_COLLECTOR" , raising = False )
113+     app_environment .pop ("WEBSERVER_GARBAGE_COLLECTOR" , None )
114+ 
115+     return  app_environment  |  setenvs_from_dict (
110116        monkeypatch ,
111117        {
112118            "WEBSERVER_COMPUTATION" : "1" ,
113119            "WEBSERVER_NOTIFICATIONS" : "1" ,
120+             # sets TTL of a resource after logout 
121+             "RESOURCE_MANAGER_RESOURCE_TTL_S" : f"{ SERVICE_DELETION_DELAY }  " ,
122+             "GARBAGE_COLLECTOR_INTERVAL_S" : "30" ,
114123        },
115124    )
116-     return  app_environment  |  overrides 
117125
118126
119127@pytest .fixture  
120128def  client (
121129    event_loop : asyncio .AbstractEventLoop ,
122130    aiohttp_client : Callable ,
123-     app_cfg : dict [str , Any ],
131+     app_cfg : AppConfigDict ,
132+     app_environment : EnvVarsDict ,
124133    postgres_db : sa .engine .Engine ,
125134    mock_orphaned_services ,
126135    redis_client : Redis ,
127-     monkeypatch_setenv_from_app_config : Callable ,
128136    mock_dynamic_scheduler_rabbitmq : None ,
129137) ->  TestClient :
130-     cfg  =  deepcopy (app_cfg )
131-     assert  cfg ["rest" ]["version" ] ==  API_VTAG 
132-     assert  cfg ["rest" ]["enabled" ]
133-     cfg ["projects" ]["enabled" ] =  True 
134- 
135-     # sets TTL of a resource after logout 
136-     cfg ["resource_manager" ][
137-         "resource_deletion_timeout_seconds" 
138-     ] =  SERVICE_DELETION_DELAY 
139- 
140-     monkeypatch_setenv_from_app_config (cfg )
141-     app  =  create_safe_application (cfg )
138+     app  =  create_safe_application ()
142139
143-     # activates only security+restAPI sub-modules 
140+     assert   "WEBSERVER_GARBAGE_COLLECTOR"   not   in   app_environment 
144141
145-     assert  setup_settings (app )
142+     settings  =  setup_settings (app )
143+     assert  settings .WEBSERVER_GARBAGE_COLLECTOR  is  not   None 
144+     assert  settings .WEBSERVER_PROJECTS  is  not   None 
146145
147146    setup_db (app )
148147    setup_session (app )
@@ -151,7 +150,7 @@ def client(
151150    setup_login (app )
152151    setup_users (app )
153152    setup_socketio (app )
154-     setup_projects (app )
153+     assert   setup_projects (app )
155154    setup_director_v2 (app )
156155    assert  setup_resource_manager (app )
157156    setup_rabbitmq (app )
@@ -167,7 +166,10 @@ def client(
167166    return  event_loop .run_until_complete (
168167        aiohttp_client (
169168            app ,
170-             server_kwargs = {"port" : cfg ["main" ]["port" ], "host" : cfg ["main" ]["host" ]},
169+             server_kwargs = {
170+                 "port" : app_cfg ["main" ]["port" ],
171+                 "host" : app_cfg ["main" ]["host" ],
172+             },
171173        )
172174    )
173175
0 commit comments