1212from common_library .users_enums import UserRole
1313from models_library .products import ProductName
1414from models_library .projects import ProjectID
15+ from pydantic import ValidationError
1516from pytest_simcore .helpers .monkeypatch_envs import setenvs_from_dict
1617from pytest_simcore .helpers .typing_env import EnvVarsDict
1718from pytest_simcore .helpers .webserver_login import NewUser , UserInfoDict
1819from servicelib .rabbitmq import RabbitMQRPCClient
1920from servicelib .rabbitmq .rpc_interfaces .webserver import projects as projects_rpc
20- from servicelib .rabbitmq .rpc_interfaces .webserver .errors import ProjectForbiddenRpcError
21+ from servicelib .rabbitmq .rpc_interfaces .webserver .errors import (
22+ ProjectForbiddenRpcError ,
23+ ProjectNotFoundRpcError ,
24+ )
2125from settings_library .rabbit import RabbitSettings
2226from simcore_service_webserver .application_settings import ApplicationSettings
2327from simcore_service_webserver .projects .models import ProjectDict
@@ -64,6 +68,25 @@ async def rpc_client(
6468 return await rabbitmq_rpc_client ("client" )
6569
6670
71+ async def test_rpc_client_mark_project_as_job (
72+ rpc_client : RabbitMQRPCClient ,
73+ product_name : ProductName ,
74+ logged_user : UserInfoDict ,
75+ user_project : ProjectDict ,
76+ ):
77+ # `logged_user` OWNS the `user_project` but not `other_user`
78+ project_uuid : ProjectID = UUID (user_project ["uuid" ])
79+ user_id = logged_user ["id" ]
80+
81+ await projects_rpc .mark_project_as_job (
82+ rpc_client = rpc_client ,
83+ product_name = product_name ,
84+ user_id = user_id ,
85+ project_uuid = project_uuid ,
86+ job_parent_resource_name = "solvers/solver123/version/1.2.3" ,
87+ )
88+
89+
6790@pytest .fixture
6891async def other_user (
6992 client : TestClient ,
@@ -82,7 +105,7 @@ async def other_user(
82105 yield other_user_info
83106
84107
85- async def test_rpc_client_mark_project_as_job (
108+ async def test_errors_on_rpc_client_mark_project_as_job (
86109 rpc_client : RabbitMQRPCClient ,
87110 product_name : ProductName ,
88111 logged_user : UserInfoDict ,
@@ -94,15 +117,7 @@ async def test_rpc_client_mark_project_as_job(
94117 user_id = logged_user ["id" ]
95118 other_user_id = other_user ["id" ]
96119
97- await projects_rpc .mark_project_as_job (
98- rpc_client = rpc_client ,
99- product_name = product_name ,
100- user_id = user_id ,
101- project_uuid = project_uuid ,
102- job_parent_resource_name = "solvers/solver123/version/1.2.3" ,
103- )
104-
105- with pytest .raises (ProjectForbiddenRpcError ) as err_info :
120+ with pytest .raises (ProjectForbiddenRpcError ) as exc_info :
106121 await projects_rpc .mark_project_as_job (
107122 rpc_client = rpc_client ,
108123 product_name = product_name ,
@@ -111,13 +126,26 @@ async def test_rpc_client_mark_project_as_job(
111126 job_parent_resource_name = "solvers/solver123/version/1.2.3" ,
112127 )
113128
114- assert err_info .value .error_context ()["project_uuid" ] == project_uuid
129+ assert exc_info .value .error_context ()["project_uuid" ] == project_uuid
115130
116- with pytest .raises (Exception , match = "not found" ):
131+ with pytest .raises (ProjectNotFoundRpcError , match = "not found" ):
117132 await projects_rpc .mark_project_as_job (
118133 rpc_client = rpc_client ,
119134 product_name = product_name ,
120135 user_id = logged_user ["id" ],
121136 project_uuid = UUID ("00000000-0000-0000-0000-000000000000" ), # <-- wont find
122137 job_parent_resource_name = "solvers/solver123/version/1.2.3" ,
123138 )
139+
140+ with pytest .raises (ValidationError , match = "job_parent_resource_name" ) as exc_info :
141+ await projects_rpc .mark_project_as_job (
142+ rpc_client = rpc_client ,
143+ product_name = product_name ,
144+ user_id = user_id ,
145+ project_uuid = project_uuid ,
146+ job_parent_resource_name = "This is not a resource" , # <-- wrong format
147+ )
148+
149+ assert exc_info .value .error_count () == 1
150+ assert exc_info .value .errors ()[0 ]["loc" ] == ("job_parent_resource_name" ,)
151+ assert exc_info .value .errors ()[0 ]["type" ] == "value_error"
0 commit comments