Skip to content

Commit dbe3c0a

Browse files
committed
add tests for get_project_marked_as_job
1 parent ee3ab9d commit dbe3c0a

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

packages/pytest-simcore/src/pytest_simcore/helpers/webserver_rpc_server.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,25 @@ async def list_projects_marked_as_jobs(
8686
limit=limit,
8787
offset=offset,
8888
)
89+
90+
@validate_call(config={"arbitrary_types_allowed": True})
91+
async def get_project_marked_as_job(
92+
self,
93+
rpc_client: RabbitMQRPCClient | MockType,
94+
*,
95+
product_name: ProductName,
96+
user_id: UserID,
97+
project_uuid: ProjectID,
98+
job_parent_resource_name: str,
99+
) -> ProjectJobRpcGet:
100+
assert rpc_client
101+
assert product_name
102+
assert user_id
103+
assert project_uuid
104+
assert job_parent_resource_name
105+
106+
# Return a valid example from the schema
107+
example = ProjectJobRpcGet.model_json_schema()["examples"][0]
108+
example["uuid"] = str(project_uuid)
109+
example["job_parent_resource_name"] = job_parent_resource_name
110+
return ProjectJobRpcGet.model_validate(example)

services/api-server/tests/unit/service/test_service_solvers.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import pytest
77
from models_library.products import ProductName
8+
from models_library.projects import ProjectID
9+
from models_library.rpc.webserver.projects import ProjectJobRpcGet
810
from models_library.users import UserID
911
from pytest_mock import MockType
1012
from simcore_service_api_server._service_jobs import JobService
@@ -14,6 +16,10 @@
1416
)
1517
from simcore_service_api_server.models.schemas.solvers import Solver
1618
from simcore_service_api_server.services_rpc.catalog import CatalogService
19+
from simcore_service_api_server.services_rpc.wb_api_server import (
20+
ProjectForbiddenRpcError,
21+
ProjectNotFoundRpcError,
22+
)
1723

1824

1925
async def test_get_solver(
@@ -73,3 +79,48 @@ async def test_solver_service_init_raises_configuration_error(
7379
)
7480
# Verify the RPC call was made to check consistency
7581
assert not mocked_rpc_client.request.called
82+
83+
84+
async def test_job_service_get_job_success(
85+
mocked_rpc_client: MockType,
86+
job_service: JobService,
87+
):
88+
job_parent_resource_name = "solver-resource"
89+
job_id = ProjectID("123e4567-e89b-12d3-a456-426614174000")
90+
91+
# Act
92+
result = await job_service.get_job(job_parent_resource_name, job_id)
93+
94+
# Assert
95+
assert isinstance(result, ProjectJobRpcGet)
96+
assert result.job_parent_resource_name.startswith(job_parent_resource_name)
97+
assert mocked_rpc_client.request.called
98+
assert mocked_rpc_client.request.call_args.args == (
99+
"webserver",
100+
"get_project_marked_as_job",
101+
)
102+
assert (
103+
mocked_rpc_client.request.call_args.kwargs["job_parent_resource_name"]
104+
== job_parent_resource_name
105+
)
106+
assert mocked_rpc_client.request.call_args.kwargs["project_uuid"] == job_id
107+
108+
109+
@pytest.mark.parametrize(
110+
"exception_type",
111+
[ProjectForbiddenRpcError, ProjectNotFoundRpcError],
112+
)
113+
async def test_job_service_get_job_exceptions(
114+
mocker, job_service: JobService, exception_type
115+
):
116+
job_parent_resource_name = "solver-resource"
117+
job_id = ProjectID("123e4567-e89b-12d3-a456-426614174000")
118+
mocker.patch.object(
119+
job_service._web_rpc_client,
120+
"get_project_marked_as_job",
121+
side_effect=exception_type("error"),
122+
)
123+
124+
with pytest.raises(exception_type):
125+
await job_service.get_job(job_parent_resource_name, job_id)
126+
await job_service.get_job(job_parent_resource_name, job_id)

0 commit comments

Comments
 (0)