|
2 | 2 | # pylint: disable=redefined-outer-name |
3 | 3 | # pylint: disable=unused-argument |
4 | 4 | # pylint: disable=unused-variable |
| 5 | +# pylint: disable=broad-exception-caught |
5 | 6 |
|
6 | 7 | import json |
7 | 8 | import subprocess |
8 | | -from collections.abc import AsyncIterator, Callable, Iterable, Iterator |
| 9 | +from collections.abc import AsyncIterator, Callable, Iterator |
9 | 10 | from copy import deepcopy |
10 | 11 | from pathlib import Path |
11 | 12 | from typing import Any |
|
45 | 46 | from pytest_simcore.simcore_webserver_projects_rest_api import GET_PROJECT |
46 | 47 | from requests.auth import HTTPBasicAuth |
47 | 48 | from respx import MockRouter |
48 | | -from servicelib.rabbitmq._client_rpc import RabbitMQRPCClient |
49 | | -from servicelib.rabbitmq.rpc_interfaces.catalog import services as catalog_rpc |
50 | | -from simcore_service_api_server.api.dependencies.rabbitmq import get_rabbitmq_rpc_client |
51 | 49 | from simcore_service_api_server.core.application import init_app |
52 | 50 | from simcore_service_api_server.core.settings import ApplicationSettings |
53 | 51 | from simcore_service_api_server.repository.api_keys import UserAndProductTuple |
@@ -92,10 +90,19 @@ def app_environment( |
92 | 90 | def mock_missing_plugins(app_environment: EnvVarsDict, mocker: MockerFixture): |
93 | 91 | settings = ApplicationSettings.create_from_envs() |
94 | 92 | if settings.API_SERVER_RABBITMQ is None: |
95 | | - mocker.patch("simcore_service_api_server.core.application.setup_rabbitmq") |
96 | | - mocker.patch( |
97 | | - "simcore_service_api_server.core._prometheus_instrumentation.setup_prometheus_instrumentation" |
| 93 | + import simcore_service_api_server.core.application |
| 94 | + |
| 95 | + mocker.patch.object( |
| 96 | + simcore_service_api_server.core.application, |
| 97 | + "setup_rabbitmq", |
| 98 | + autospec=True, |
98 | 99 | ) |
| 100 | + mocker.patch.object( |
| 101 | + simcore_service_api_server.core.application, |
| 102 | + "setup_prometheus_instrumentation", |
| 103 | + autospec=True, |
| 104 | + ) |
| 105 | + |
99 | 106 | return app_environment |
100 | 107 |
|
101 | 108 |
|
@@ -331,34 +338,27 @@ def mocked_webserver_rest_api_base( |
331 | 338 |
|
332 | 339 |
|
333 | 340 | @pytest.fixture |
334 | | -def mocked_webserver_rpc_api( |
335 | | - app: FastAPI, mocker: MockerFixture |
336 | | -) -> dict[str, MockType]: |
337 | | - from servicelib.rabbitmq.rpc_interfaces.webserver import projects as projects_rpc |
338 | | - from simcore_service_api_server.services_rpc import wb_api_server |
339 | | - |
340 | | - # NOTE: mock_missing_plugins patches `setup_rabbitmq` |
341 | | - try: |
342 | | - wb_api_server.WbApiRpcClient.get_from_app_state(app) |
343 | | - except AttributeError: |
344 | | - wb_api_server.setup( |
345 | | - app, RabbitMQRPCClient("fake_rpc_client", settings=mocker.MagicMock()) |
346 | | - ) |
347 | | - |
348 | | - settings: ApplicationSettings = app.state.settings |
349 | | - assert settings.API_SERVER_WEBSERVER |
| 341 | +def mocked_webserver_rpc_api(mocker: MockerFixture) -> dict[str, MockType]: |
| 342 | + """ |
| 343 | + Mocks the webserver's simcore service RPC API for testing purposes. |
| 344 | + """ |
| 345 | + from servicelib.rabbitmq.rpc_interfaces.webserver import ( |
| 346 | + projects as projects_rpc, # keep import here |
| 347 | + ) |
350 | 348 |
|
351 | 349 | side_effects = WebserverRpcSideEffects() |
352 | 350 |
|
353 | 351 | return { |
354 | 352 | "mark_project_as_job": mocker.patch.object( |
355 | 353 | projects_rpc, |
356 | 354 | "mark_project_as_job", |
| 355 | + autospec=True, |
357 | 356 | side_effect=side_effects.mark_project_as_job, |
358 | 357 | ), |
359 | 358 | "list_projects_marked_as_jobs": mocker.patch.object( |
360 | 359 | projects_rpc, |
361 | 360 | "list_projects_marked_as_jobs", |
| 361 | + autospec=True, |
362 | 362 | side_effect=side_effects.list_projects_marked_as_jobs, |
363 | 363 | ), |
364 | 364 | } |
@@ -458,20 +458,16 @@ def mocked_catalog_rest_api_base( |
458 | 458 |
|
459 | 459 |
|
460 | 460 | @pytest.fixture |
461 | | -def mocked_catalog_rpc_api( |
462 | | - app: FastAPI, mocker: MockerFixture |
463 | | -) -> Iterable[dict[str, MockType]]: |
| 461 | +def mocked_catalog_rpc_api(mocker: MockerFixture) -> dict[str, MockType]: |
464 | 462 | """ |
465 | | - Mocks the RPC catalog service API for testing purposes. |
| 463 | + Mocks the catalog's simcore service RPC API for testing purposes. |
466 | 464 | """ |
| 465 | + from servicelib.rabbitmq.rpc_interfaces.catalog import ( |
| 466 | + services as catalog_rpc, # keep import here |
| 467 | + ) |
467 | 468 |
|
468 | | - def get_mock_rabbitmq_rpc_client(): |
469 | | - return MagicMock() |
470 | | - |
471 | | - app.dependency_overrides[get_rabbitmq_rpc_client] = get_mock_rabbitmq_rpc_client |
472 | 469 | side_effects = CatalogRpcSideEffects() |
473 | | - |
474 | | - yield { |
| 470 | + return { |
475 | 471 | "list_services_paginated": mocker.patch.object( |
476 | 472 | catalog_rpc, |
477 | 473 | "list_services_paginated", |
@@ -503,7 +499,6 @@ def get_mock_rabbitmq_rpc_client(): |
503 | 499 | side_effect=side_effects.get_service_ports, |
504 | 500 | ), |
505 | 501 | } |
506 | | - app.dependency_overrides.pop(get_rabbitmq_rpc_client) |
507 | 502 |
|
508 | 503 |
|
509 | 504 | # |
@@ -633,6 +628,7 @@ def clone_project_task(self, request: httpx.Request, *, project_id: str): |
633 | 628 | return self._set_result_and_get_reponse(project_get) |
634 | 629 |
|
635 | 630 | def get_result(self, request: httpx.Request, *, task_id: str): |
| 631 | + assert request |
636 | 632 | return httpx.Response( |
637 | 633 | status.HTTP_200_OK, json={"data": self._results[task_id]} |
638 | 634 | ) |
|
0 commit comments