66# pylint: disable=unused-variable
77
88
9- import contextlib
10- from collections .abc import AsyncIterator
119from unittest .mock import MagicMock
1210
1311import pytest
1614from pytest_simcore .helpers .assert_checks import assert_status
1715from pytest_simcore .helpers .monkeypatch_envs import setenvs_from_dict
1816from pytest_simcore .helpers .typing_env import EnvVarsDict
19- from pytest_simcore .helpers .webserver_login import UserInfoDict
17+ from pytest_simcore .helpers .webserver_login import (
18+ UserInfoDict ,
19+ switch_client_session_to ,
20+ )
2021from servicelib .aiohttp import status
2122from simcore_service_webserver .db .models import UserRole
2223from simcore_service_webserver .projects import _trash_service
@@ -44,30 +45,6 @@ def user_role() -> UserRole:
4445 return UserRole .USER
4546
4647
47- @contextlib .asynccontextmanager
48- async def _switch_client_session_to (
49- client : TestClient , user : UserInfoDict
50- ) -> AsyncIterator [TestClient ]:
51- assert client .app
52-
53- await client .post (f'{ client .app .router ["auth_logout" ].url_for ()} ' )
54- # sometimes 4xx if user already logged out. Ignore
55-
56- resp = await client .post (
57- f'{ client .app .router ["auth_login" ].url_for ()} ' ,
58- json = {
59- "email" : user ["email" ],
60- "password" : user ["raw_password" ],
61- },
62- )
63- await assert_status (resp , status .HTTP_200_OK )
64-
65- yield client
66-
67- resp = await client .post (f'{ client .app .router ["auth_logout" ].url_for ()} ' )
68- await assert_status (resp , status .HTTP_200_OK )
69-
70-
7148async def test_trash_service__delete_expired_trash (
7249 client : TestClient ,
7350 logged_user : UserInfoDict ,
@@ -116,7 +93,7 @@ async def test_trash_service__delete_expired_trash(
11693 await assert_status (resp , status .HTTP_404_NOT_FOUND )
11794
11895 # ASSERT: other_user tries to get the project and expects 404
119- async with _switch_client_session_to (client , other_user ):
96+ async with switch_client_session_to (client , other_user ):
12097 resp = await client .get (f"/v0/projects/{ other_user_project_id } " )
12198 await assert_status (resp , status .HTTP_404_NOT_FOUND )
12299
@@ -134,7 +111,7 @@ async def test_trash_nested_folders_and_projects(
134111 assert client .app
135112 assert logged_user ["id" ] != other_user ["id" ]
136113
137- async with _switch_client_session_to (client , logged_user ):
114+ async with switch_client_session_to (client , logged_user ):
138115 # CREATE folders hierarchy for logged_user
139116 resp = await client .post ("/v0/folders" , json = {"name" : "Root Folder" })
140117 data , _ = await assert_status (resp , status .HTTP_201_CREATED )
@@ -162,7 +139,7 @@ async def test_trash_nested_folders_and_projects(
162139 )
163140 await assert_status (resp , status .HTTP_204_NO_CONTENT )
164141
165- async with _switch_client_session_to (client , other_user ):
142+ async with switch_client_session_to (client , other_user ):
166143 # CREATE folders hierarchy for other_user
167144 resp = await client .post ("/v0/folders" , json = {"name" : "Root Folder" })
168145 data , _ = await assert_status (resp , status .HTTP_201_CREATED )
@@ -193,7 +170,7 @@ async def test_trash_nested_folders_and_projects(
193170 # UNDER TEST
194171 await trash_service .safe_delete_expired_trash_as_admin (client .app )
195172
196- async with _switch_client_session_to (client , logged_user ):
173+ async with switch_client_session_to (client , logged_user ):
197174 # Verify logged_user's resources are gone
198175 resp = await client .get (f"/v0/folders/{ logged_user_root_folder ['folderId' ]} " )
199176 await assert_status (resp , status .HTTP_403_FORBIDDEN )
@@ -205,7 +182,7 @@ async def test_trash_nested_folders_and_projects(
205182 await assert_status (resp , status .HTTP_404_NOT_FOUND )
206183
207184 # Verify other_user's resources are gone
208- async with _switch_client_session_to (client , other_user ):
185+ async with switch_client_session_to (client , other_user ):
209186 resp = await client .get (f"/v0/folders/{ other_user_root_folder ['folderId' ]} " )
210187 await assert_status (resp , status .HTTP_403_FORBIDDEN )
211188
0 commit comments