1111from copy import deepcopy
1212from pathlib import Path
1313from typing import Any
14+ from unittest import mock
1415
1516import pytest
1617import sqlalchemy as sa
18+ from _pytest .mark .structures import ParameterSet
1719from aiohttp .test_utils import TestClient
1820from models_library .folders import FolderID
1921from models_library .projects import ProjectID , ProjectTemplateType
3436from simcore_service_webserver .projects .models import ProjectDict
3537
3638
37- def standard_user_role () -> tuple [str , tuple [UserRole , ExpectedResponse ]]:
38- all_roles = standard_role_response ()
39+ def standard_user_role () -> tuple [str , list [ParameterSet ]]:
40+ parameters , all_roles_expected_responses = standard_role_response ()
41+ standard_user , standard_user_expected_response = all_roles_expected_responses [2 ]
3942
40- return (all_roles [0 ], [pytest .param (* all_roles [1 ][2 ], id = "standard_user_role" )])
43+ return (
44+ parameters ,
45+ [
46+ pytest .param (
47+ standard_user , standard_user_expected_response , id = "standard_user_role"
48+ )
49+ ],
50+ )
4151
4252
43- def standard_and_tester_user_roles () -> tuple [str , tuple [ UserRole , ExpectedResponse ]]:
53+ def standard_and_tester_user_roles () -> tuple [str , list [ ParameterSet ]]:
4454 all_roles = standard_role_response ()
4555
4656 return (
@@ -58,6 +68,7 @@ async def _new_project(
5868 product_name : str ,
5969 tests_data_dir : Path ,
6070 project_data : dict [str , Any ],
71+ * ,
6172 as_template : bool = False ,
6273):
6374 """returns a project for the given user"""
@@ -89,7 +100,7 @@ def _assert_response_data(
89100
90101def _pick_random_substring (text , length ):
91102 length = min (length , len (text ))
92- start_index = random .randint (0 , len (text ) - length )
103+ start_index = random .randint (0 , len (text ) - length ) # noqa: S311
93104 end_index = start_index + length
94105 return text [start_index :end_index ]
95106
@@ -101,7 +112,8 @@ class _ProjectInfo(BaseModel):
101112
102113
103114@pytest .mark .parametrize (* standard_user_role ())
104- async def test_list_projects_with_search_parameter (
115+ async def test_list_projects_with_search_parameter ( # noqa: PLR0915
116+ mocked_dynamic_services_interface : dict [str , mock .MagicMock ],
105117 client : TestClient ,
106118 logged_user : UserDict ,
107119 expected : ExpectedResponse ,
@@ -112,27 +124,27 @@ async def test_list_projects_with_search_parameter(
112124):
113125 projects_info = [
114126 _ProjectInfo (
115- uuid = "d4d0eca3-d210-4db6-84f9-63670b07176b" ,
127+ uuid = ProjectID ( "d4d0eca3-d210-4db6-84f9-63670b07176b" ) ,
116128 name = "Name 1" ,
117129 description = "Description 1" ,
118130 ),
119131 _ProjectInfo (
120- uuid = "2f3ef868-fe1b-11ed-b038-cdb13a78a6f3" ,
132+ uuid = ProjectID ( "2f3ef868-fe1b-11ed-b038-cdb13a78a6f3" ) ,
121133 name = "Name 2" ,
122134 description = "Description 2" ,
123135 ),
124136 _ProjectInfo (
125- uuid = "9cd66c12-fe1b-11ed-b038-cdb13a78a6f3" ,
137+ uuid = ProjectID ( "9cd66c12-fe1b-11ed-b038-cdb13a78a6f3" ) ,
126138 name = "Name 3" ,
127139 description = "Description 3" ,
128140 ),
129141 _ProjectInfo (
130- uuid = "b9e32426-fe1b-11ed-b038-cdb13a78a6f3" ,
142+ uuid = ProjectID ( "b9e32426-fe1b-11ed-b038-cdb13a78a6f3" ) ,
131143 name = "Yoda 4" ,
132144 description = "Description 4" ,
133145 ),
134146 _ProjectInfo (
135- uuid = "bc57aff6-fe1b-11ed-b038-cdb13a78a6f3" ,
147+ uuid = ProjectID ( "bc57aff6-fe1b-11ed-b038-cdb13a78a6f3" ) ,
136148 name = "Name 5" ,
137149 description = "Yoda 5" ,
138150 ),
@@ -291,6 +303,7 @@ async def test_list_projects_with_search_parameter(
291303
292304@pytest .mark .parametrize (* standard_user_role ())
293305async def test_list_projects_with_order_by_parameter (
306+ mocked_dynamic_services_interface : dict [str , mock .MagicMock ],
294307 client : TestClient ,
295308 logged_user : UserDict ,
296309 expected : ExpectedResponse ,
@@ -301,27 +314,27 @@ async def test_list_projects_with_order_by_parameter(
301314):
302315 projects_info = [
303316 _ProjectInfo (
304- uuid = "aaa0eca3-d210-4db6-84f9-63670b07176b" ,
317+ uuid = ProjectID ( "aaa0eca3-d210-4db6-84f9-63670b07176b" ) ,
305318 name = "d" ,
306319 description = "c" ,
307320 ),
308321 _ProjectInfo (
309- uuid = "cccef868-fe1b-11ed-b038-cdb13a78a6f3" ,
322+ uuid = ProjectID ( "cccef868-fe1b-11ed-b038-cdb13a78a6f3" ) ,
310323 name = "b" ,
311324 description = "e" ,
312325 ),
313326 _ProjectInfo (
314- uuid = "eee66c12-fe1b-11ed-b038-cdb13a78a6f3" ,
327+ uuid = ProjectID ( "eee66c12-fe1b-11ed-b038-cdb13a78a6f3" ) ,
315328 name = "a" ,
316329 description = "a" ,
317330 ),
318331 _ProjectInfo (
319- uuid = "ddd32426-fe1b-11ed-b038-cdb13a78a6f3" ,
332+ uuid = ProjectID ( "ddd32426-fe1b-11ed-b038-cdb13a78a6f3" ) ,
320333 name = "c" ,
321334 description = "b" ,
322335 ),
323336 _ProjectInfo (
324- uuid = "bbb7aff6-fe1b-11ed-b038-cdb13a78a6f3" ,
337+ uuid = ProjectID ( "bbb7aff6-fe1b-11ed-b038-cdb13a78a6f3" ) ,
325338 name = "e" ,
326339 description = "d" ,
327340 ),
@@ -412,7 +425,9 @@ def setup_folders_db(
412425 )
413426 .returning (folders_v2 .c .folder_id )
414427 )
415- _folder_id = result .fetchone ()[0 ]
428+ row = result .fetchone ()
429+ assert row is not None
430+ _folder_id = row [0 ]
416431
417432 con .execute (
418433 projects_to_folders .insert ().values (
@@ -422,14 +437,15 @@ def setup_folders_db(
422437 )
423438 )
424439
425- yield FolderID ( _folder_id )
440+ yield _folder_id
426441
427442 con .execute (projects_to_folders .delete ())
428443 con .execute (folders_v2 .delete ())
429444
430445
431446@pytest .mark .parametrize (* standard_user_role ())
432447async def test_list_projects_for_specific_folder_id (
448+ mocked_dynamic_services_interface : dict [str , mock .MagicMock ],
433449 client : TestClient ,
434450 logged_user : UserDict ,
435451 expected : ExpectedResponse ,
@@ -441,17 +457,17 @@ async def test_list_projects_for_specific_folder_id(
441457):
442458 projects_info = [
443459 _ProjectInfo (
444- uuid = "d4d0eca3-d210-4db6-84f9-63670b07176b" ,
460+ uuid = ProjectID ( "d4d0eca3-d210-4db6-84f9-63670b07176b" ) ,
445461 name = "Name 1" ,
446462 description = "Description 1" ,
447463 ),
448464 _ProjectInfo (
449- uuid = "2f3ef868-fe1b-11ed-b038-cdb13a78a6f3" ,
465+ uuid = ProjectID ( "2f3ef868-fe1b-11ed-b038-cdb13a78a6f3" ) ,
450466 name = "Name 2" ,
451467 description = "Description 2" ,
452468 ),
453469 _ProjectInfo (
454- uuid = "9cd66c12-fe1b-11ed-b038-cdb13a78a6f3" ,
470+ uuid = ProjectID ( "9cd66c12-fe1b-11ed-b038-cdb13a78a6f3" ) ,
455471 name = "Name 3" ,
456472 description = "Description 3" ,
457473 ),
@@ -511,7 +527,8 @@ async def test_list_projects_for_specific_folder_id(
511527
512528
513529@pytest .mark .parametrize (* standard_and_tester_user_roles ())
514- async def test_list_and_patch_projects_with_template_type (
530+ async def test_list_and_patch_projects_with_template_type ( # noqa: PLR0915
531+ mocked_dynamic_services_interface : dict [str , mock .MagicMock ],
515532 client : TestClient ,
516533 logged_user : UserDict ,
517534 expected : ExpectedResponse ,
0 commit comments