Skip to content

Commit af2a969

Browse files
committed
add unit tests for get_job_method
1 parent dbe3c0a commit af2a969

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
from pytest_mock import MockType
1212
from simcore_service_api_server._service_jobs import JobService
1313
from simcore_service_api_server._service_solvers import SolverService
14+
from simcore_service_api_server.exceptions.backend_errors import (
15+
JobForbiddenAccessError,
16+
JobNotFoundError,
17+
)
1418
from simcore_service_api_server.exceptions.custom_errors import (
1519
ServiceConfigurationError,
1620
)
@@ -107,20 +111,23 @@ async def test_job_service_get_job_success(
107111

108112

109113
@pytest.mark.parametrize(
110-
"exception_type",
111-
[ProjectForbiddenRpcError, ProjectNotFoundRpcError],
114+
"client_exception_type,api_exception_type",
115+
[
116+
(ProjectForbiddenRpcError, JobForbiddenAccessError),
117+
(ProjectNotFoundRpcError, JobNotFoundError),
118+
],
112119
)
113120
async def test_job_service_get_job_exceptions(
114-
mocker, job_service: JobService, exception_type
121+
mocker,
122+
job_service: JobService,
123+
client_exception_type: type[Exception],
124+
api_exception_type: type[Exception],
115125
):
116126
job_parent_resource_name = "solver-resource"
117127
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-
)
128+
# Patch the actual RPC interface method
129+
patch_path = "servicelib.rabbitmq.rpc_interfaces.webserver.projects.get_project_marked_as_job"
130+
mocker.patch(patch_path, side_effect=client_exception_type())
123131

124-
with pytest.raises(exception_type):
125-
await job_service.get_job(job_parent_resource_name, job_id)
132+
with pytest.raises(api_exception_type):
126133
await job_service.get_job(job_parent_resource_name, job_id)

0 commit comments

Comments
 (0)