|
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 | from models_library.products import ProductName |
| 8 | +from models_library.projects import ProjectID |
| 9 | +from models_library.rpc.webserver.projects import ProjectJobRpcGet |
8 | 10 | from models_library.users import UserID |
9 | 11 | from pytest_mock import MockType |
10 | 12 | from simcore_service_api_server._service_jobs import JobService |
|
14 | 16 | ) |
15 | 17 | from simcore_service_api_server.models.schemas.solvers import Solver |
16 | 18 | 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 | +) |
17 | 23 |
|
18 | 24 |
|
19 | 25 | async def test_get_solver( |
@@ -73,3 +79,48 @@ async def test_solver_service_init_raises_configuration_error( |
73 | 79 | ) |
74 | 80 | # Verify the RPC call was made to check consistency |
75 | 81 | 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