|
15 | 15 | from fastapi.encoders import jsonable_encoder |
16 | 16 | from httpx import AsyncClient |
17 | 17 | from models_library.generics import Envelope |
18 | | -from pydantic import TypeAdapter |
19 | | -from pytest_mock import MockType |
| 18 | +from models_library.products import ProductName |
| 19 | +from models_library.projects import ProjectID |
| 20 | +from models_library.rpc.webserver.projects import ProjectJobRpcGet |
| 21 | +from models_library.users import UserID |
| 22 | +from pydantic import TypeAdapter, validate_call |
| 23 | +from pytest_mock import MockerFixture, MockType |
20 | 24 | from pytest_simcore.helpers.httpx_calls_capture_models import ( |
21 | 25 | CreateRespxMockCallback, |
22 | 26 | HttpApiCallCaptureModel, |
23 | 27 | SideEffectCallback, |
24 | 28 | ) |
25 | 29 | from respx import MockRouter |
| 30 | +from servicelib.rabbitmq import RabbitMQRPCClient |
26 | 31 | from simcore_service_api_server._meta import API_VTAG |
27 | 32 | from simcore_service_api_server.models.schemas.jobs import Job, JobStatus |
28 | 33 | from simcore_service_api_server.models.schemas.model_adapter import ( |
@@ -347,6 +352,84 @@ async def test_start_solver_job_conflict( |
347 | 352 | assert f"{job_status.job_id}" == _job_id |
348 | 353 |
|
349 | 354 |
|
| 355 | +@pytest.fixture |
| 356 | +def mocked_get_project_marked_as_job_storage_data_missing( |
| 357 | + mocked_app_dependencies: None, mocker: MockerFixture |
| 358 | +) -> dict[str, MockType]: |
| 359 | + """ |
| 360 | + Mocks the webserver's simcore service RPC API for testing purposes. |
| 361 | + """ |
| 362 | + from servicelib.rabbitmq.rpc_interfaces.webserver import ( |
| 363 | + projects as projects_rpc, # keep import here |
| 364 | + ) |
| 365 | + |
| 366 | + @validate_call(config={"arbitrary_types_allowed": True}) |
| 367 | + async def _get_project_marked_as_job( |
| 368 | + rpc_client: RabbitMQRPCClient | MockType, |
| 369 | + *, |
| 370 | + product_name: ProductName, |
| 371 | + user_id: UserID, |
| 372 | + project_uuid: ProjectID, |
| 373 | + job_parent_resource_name: str, |
| 374 | + ) -> ProjectJobRpcGet: |
| 375 | + assert rpc_client |
| 376 | + assert product_name |
| 377 | + assert user_id |
| 378 | + assert project_uuid |
| 379 | + assert job_parent_resource_name |
| 380 | + |
| 381 | + # Return a valid example from the schema |
| 382 | + example = ProjectJobRpcGet.model_json_schema()["examples"][0] |
| 383 | + example["uuid"] = str(project_uuid) |
| 384 | + example["job_parent_resource_name"] = job_parent_resource_name |
| 385 | + example["storage_data_deleted"] = "true" |
| 386 | + project_job_rpc_get = ProjectJobRpcGet.model_validate(example) |
| 387 | + assert project_job_rpc_get.storage_data_deleted is True |
| 388 | + return project_job_rpc_get |
| 389 | + |
| 390 | + return { |
| 391 | + "get_project_marked_as_job": mocker.patch.object( |
| 392 | + projects_rpc, |
| 393 | + "get_project_marked_as_job", |
| 394 | + autospec=True, |
| 395 | + side_effect=_get_project_marked_as_job, |
| 396 | + ), |
| 397 | + } |
| 398 | + |
| 399 | + |
| 400 | +async def test_start_solver_job_storage_data_missing( |
| 401 | + client: AsyncClient, |
| 402 | + mocked_webserver_rest_api_base: MockRouter, |
| 403 | + mocked_directorv2_rest_api_base: MockRouter, |
| 404 | + mocked_get_project_marked_as_job_storage_data_missing: dict[str, MockType], |
| 405 | + create_respx_mock_from_capture: CreateRespxMockCallback, |
| 406 | + auth: httpx.BasicAuth, |
| 407 | + project_tests_dir: Path, |
| 408 | +): |
| 409 | + _solver_key: str = "simcore/services/comp/itis/sleeper" |
| 410 | + _version: str = "2.0.2" |
| 411 | + _job_id: str = "b9faf8d8-4928-4e50-af40-3690712c5481" |
| 412 | + |
| 413 | + create_respx_mock_from_capture( |
| 414 | + respx_mocks=[ |
| 415 | + mocked_directorv2_rest_api_base, |
| 416 | + mocked_webserver_rest_api_base, |
| 417 | + ], |
| 418 | + capture_path=project_tests_dir / "mocks" / "start_solver_job.json", |
| 419 | + side_effects_callbacks=[ |
| 420 | + _start_job_side_effect, |
| 421 | + _get_inspect_job_side_effect(job_id=_job_id), |
| 422 | + ], |
| 423 | + ) |
| 424 | + |
| 425 | + response = await client.post( |
| 426 | + f"{API_VTAG}/solvers/{_solver_key}/releases/{_version}/jobs/{_job_id}:start", |
| 427 | + auth=auth, |
| 428 | + ) |
| 429 | + |
| 430 | + assert response.status_code == status.HTTP_409_CONFLICT |
| 431 | + |
| 432 | + |
350 | 433 | async def test_stop_job( |
351 | 434 | client: AsyncClient, |
352 | 435 | mocked_directorv2_rest_api_base: MockRouter, |
|
0 commit comments