1+ # pylint: disable=redefined-outer-name
2+ # pylint: disable=unused-argument
3+ # pylint: disable=unused-variable
4+ # pylint: disable=too-many-arguments
5+
6+ from dataclasses import dataclass
7+
18import pytest
29from aiohttp .test_utils import TestClient
310from common_library .users_enums import UserRole
411from models_library .products import ProductName
512from models_library .projects import ProjectID
13+ from models_library .users import UserID
614from pytest_simcore .helpers .webserver_login import UserInfoDict
715from simcore_service_webserver .projects ._jobs_service import (
816 list_my_projects_marked_as_jobs ,
1119from simcore_service_webserver .projects .models import ProjectDict
1220
1321
22+ @dataclass
23+ class ProjectJobFixture :
24+ user_id : UserID
25+ project_uuid : ProjectID
26+ job_parent_resource_name : str
27+
28+
1429@pytest .fixture
1530def user_role () -> UserRole :
1631 # for logged_user
1732 return UserRole .USER
1833
1934
35+ @pytest .fixture
36+ async def project_job_fixture (
37+ client : TestClient ,
38+ logged_user : UserInfoDict ,
39+ user_project : ProjectDict ,
40+ osparc_product_name : ProductName ,
41+ ) -> ProjectJobFixture :
42+ assert client .app
43+
44+ user_id = logged_user ["id" ]
45+ project_uuid = ProjectID (user_project ["uuid" ])
46+ job_parent_resource_name = "test/resource"
47+
48+ await set_project_as_job (
49+ app = client .app ,
50+ product_name = osparc_product_name ,
51+ user_id = user_id ,
52+ project_uuid = project_uuid ,
53+ job_parent_resource_name = job_parent_resource_name ,
54+ )
55+ return ProjectJobFixture (
56+ user_id = user_id ,
57+ project_uuid = project_uuid ,
58+ job_parent_resource_name = job_parent_resource_name ,
59+ )
60+
61+
2062async def test_list_my_projects_marked_as_jobs_empty (
2163 client : TestClient ,
2264 logged_user : UserInfoDict , # owns `user_project`
@@ -35,45 +77,37 @@ async def test_list_my_projects_marked_as_jobs_empty(
3577 assert result == []
3678
3779
38- async def test_list_my_projects_marked_as_jobs_with_one_marked (
80+ async def test_user_can_see_marked_project (
3981 client : TestClient ,
40- logged_user : UserInfoDict , # owns `user_project`
41- user_project : ProjectDict ,
42- user : UserInfoDict ,
4382 osparc_product_name : ProductName ,
83+ project_job_fixture : ProjectJobFixture ,
4484):
4585 assert client .app
46-
47- user_id = logged_user ["id" ]
48- project_uuid = ProjectID (user_project ["uuid" ])
49- other_user_id = user ["id" ]
50-
51- assert user_id != other_user_id
52- assert user_project ["prjOwner" ] == logged_user ["email" ] # owns `user_project`
53-
54- job_parent_resource_name = "test/resource"
55- await set_project_as_job (
56- app = client .app ,
57- product_name = osparc_product_name ,
58- user_id = user_id ,
59- project_uuid = project_uuid ,
60- job_parent_resource_name = job_parent_resource_name ,
61- )
62-
63- # user can see the project
6486 total_count , result = await list_my_projects_marked_as_jobs (
6587 app = client .app ,
6688 product_name = osparc_product_name ,
67- user_id = user_id ,
89+ user_id = project_job_fixture . user_id ,
6890 )
6991 assert total_count == 1
7092 assert len (result ) == 1
7193
7294 project = result [0 ]
73- assert project .uuid == project_uuid
74- assert project .job_parent_resource_name == job_parent_resource_name
95+ assert project .uuid == project_job_fixture .project_uuid
96+ assert (
97+ project .job_parent_resource_name == project_job_fixture .job_parent_resource_name
98+ )
99+
100+
101+ async def test_other_user_cannot_see_marked_project (
102+ client : TestClient ,
103+ user : UserInfoDict ,
104+ osparc_product_name : ProductName ,
105+ project_job_fixture : ProjectJobFixture ,
106+ ):
107+ assert client .app
108+ other_user_id = user ["id" ]
109+ assert project_job_fixture .user_id != other_user_id
75110
76- # other-user cannot see the project even if it is marked as a job
77111 total_count , result = await list_my_projects_marked_as_jobs (
78112 app = client .app ,
79113 product_name = osparc_product_name ,
@@ -82,39 +116,51 @@ async def test_list_my_projects_marked_as_jobs_with_one_marked(
82116 assert total_count == 0
83117 assert len (result ) == 0
84118
85- # user can see the project with a filter
119+
120+ async def test_user_can_filter_marked_project (
121+ client : TestClient ,
122+ osparc_product_name : ProductName ,
123+ project_job_fixture : ProjectJobFixture ,
124+ ):
125+ assert client .app
126+
127+ # Exact filter
86128 total_count , result = await list_my_projects_marked_as_jobs (
87129 app = client .app ,
88130 product_name = osparc_product_name ,
89- user_id = user_id ,
90- job_parent_resource_name_filter = job_parent_resource_name ,
131+ user_id = project_job_fixture . user_id ,
132+ job_parent_resource_name_filter = project_job_fixture . job_parent_resource_name ,
91133 )
92134 assert total_count == 1
93135 assert len (result ) == 1
94136
95137 project = result [0 ]
96- assert project .uuid == project_uuid
97- assert project .job_parent_resource_name == job_parent_resource_name
138+ assert project .uuid == project_job_fixture .project_uuid
139+ assert (
140+ project .job_parent_resource_name == project_job_fixture .job_parent_resource_name
141+ )
98142
99- # user can see the project with a wildcard filter
143+ # Wildcard filter
100144 total_count , result = await list_my_projects_marked_as_jobs (
101145 app = client .app ,
102146 product_name = osparc_product_name ,
103- user_id = user_id ,
147+ user_id = project_job_fixture . user_id ,
104148 job_parent_resource_name_filter = "test/%" ,
105149 )
106150 assert total_count == 1
107151 assert len (result ) == 1
108152
109153 project = result [0 ]
110- assert project .uuid == project_uuid
111- assert project .job_parent_resource_name == job_parent_resource_name
154+ assert project .uuid == project_job_fixture .project_uuid
155+ assert (
156+ project .job_parent_resource_name == project_job_fixture .job_parent_resource_name
157+ )
112158
113- # user cannot see the project with another wildcard filter
159+ # Non-matching filter
114160 total_count , result = await list_my_projects_marked_as_jobs (
115161 app = client .app ,
116162 product_name = osparc_product_name ,
117- user_id = user_id ,
163+ user_id = project_job_fixture . user_id ,
118164 job_parent_resource_name_filter = "other/%" ,
119165 )
120166 assert total_count == 0
0 commit comments