Skip to content

Commit b690189

Browse files
committed
test cleanup
1 parent 89bdc4b commit b690189

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/webserver/projects.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,12 @@ async def mark_project_as_job(
2323
job_parent_resource_name: str,
2424
) -> None:
2525

26-
assert not job_parent_resource_name.startswith("/") # nosec
27-
assert "/" in job_parent_resource_name # nosec
28-
assert not job_parent_resource_name.endswith("/") # nosec
29-
3026
result = await rpc_client.request(
3127
WEBSERVER_RPC_NAMESPACE,
3228
TypeAdapter(RPCMethodName).validate_python("mark_project_as_job"),
3329
product_name=product_name,
3430
user_id=user_id,
3531
project_uuid=project_uuid,
3632
job_parent_resource_name=job_parent_resource_name,
37-
timeout_s=None, # TODO: remove after testing
3833
)
3934
assert result is None

services/web/server/src/simcore_service_webserver/projects/_controller/projects_rpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from ...rabbitmq import get_rabbitmq_rpc_server
1414
from .. import _jobs_service
15-
from ..exceptions import ProjectInvalidRightsError
15+
from ..exceptions import ProjectInvalidRightsError, ProjectNotFoundError
1616

1717
router = RPCRouter()
1818

@@ -46,6 +46,9 @@ async def mark_project_as_job(
4646
except ProjectInvalidRightsError as err:
4747
raise ProjectForbiddenRpcError.from_domain_error(err) from err
4848

49+
except ProjectNotFoundError as err:
50+
raise ProjectNotFoundRpcError.from_domain_error(err) from err
51+
4952

5053
async def register_rpc_routes_on_startup(app: web.Application):
5154
rpc_server = get_rabbitmq_rpc_server(app)

services/web/server/tests/unit/with_dbs/02/test_projects_rpc.py

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@
1212
from common_library.users_enums import UserRole
1313
from models_library.products import ProductName
1414
from models_library.projects import ProjectID
15+
from pydantic import ValidationError
1516
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
1617
from pytest_simcore.helpers.typing_env import EnvVarsDict
1718
from pytest_simcore.helpers.webserver_login import NewUser, UserInfoDict
1819
from servicelib.rabbitmq import RabbitMQRPCClient
1920
from 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+
)
2125
from settings_library.rabbit import RabbitSettings
2226
from simcore_service_webserver.application_settings import ApplicationSettings
2327
from 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
6891
async 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

Comments
 (0)