|
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 |
|
46 | 47 | from pytest_simcore.simcore_webserver_projects_rest_api import GET_PROJECT |
47 | 48 | from requests.auth import HTTPBasicAuth |
48 | 49 | from respx import MockRouter |
49 | | -from servicelib.rabbitmq._client_rpc import RabbitMQRPCClient |
50 | | -from servicelib.rabbitmq.rpc_interfaces.catalog import services as catalog_rpc |
51 | | -from simcore_service_api_server.api.dependencies.rabbitmq import get_rabbitmq_rpc_client |
52 | 50 | from simcore_service_api_server.core.application import init_app |
53 | 51 | from simcore_service_api_server.core.settings import ApplicationSettings |
54 | 52 | from simcore_service_api_server.db.repositories.api_keys import UserAndProductTuple |
@@ -93,10 +91,19 @@ def app_environment( |
93 | 91 | def mock_missing_plugins(app_environment: EnvVarsDict, mocker: MockerFixture): |
94 | 92 | settings = ApplicationSettings.create_from_envs() |
95 | 93 | if settings.API_SERVER_RABBITMQ is None: |
96 | | - mocker.patch("simcore_service_api_server.core.application.setup_rabbitmq") |
97 | | - mocker.patch( |
98 | | - "simcore_service_api_server.core._prometheus_instrumentation.setup_prometheus_instrumentation" |
| 94 | + import simcore_service_api_server.core.application |
| 95 | + |
| 96 | + mocker.patch.object( |
| 97 | + simcore_service_api_server.core.application, |
| 98 | + "setup_rabbitmq", |
| 99 | + autospec=True, |
99 | 100 | ) |
| 101 | + mocker.patch.object( |
| 102 | + simcore_service_api_server.core.application, |
| 103 | + "setup_prometheus_instrumentation", |
| 104 | + autospec=True, |
| 105 | + ) |
| 106 | + |
100 | 107 | return app_environment |
101 | 108 |
|
102 | 109 |
|
@@ -346,34 +353,27 @@ def mocked_webserver_rest_api_base( |
346 | 353 |
|
347 | 354 |
|
348 | 355 | @pytest.fixture |
349 | | -def mocked_webserver_rpc_api( |
350 | | - app: FastAPI, mocker: MockerFixture |
351 | | -) -> dict[str, MockType]: |
352 | | - from servicelib.rabbitmq.rpc_interfaces.webserver import projects as projects_rpc |
353 | | - from simcore_service_api_server.services_rpc import wb_api_server |
354 | | - |
355 | | - # NOTE: mock_missing_plugins patches `setup_rabbitmq` |
356 | | - try: |
357 | | - wb_api_server.WbApiRpcClient.get_from_app_state(app) |
358 | | - except AttributeError: |
359 | | - wb_api_server.setup( |
360 | | - app, RabbitMQRPCClient("fake_rpc_client", settings=mocker.MagicMock()) |
361 | | - ) |
362 | | - |
363 | | - settings: ApplicationSettings = app.state.settings |
364 | | - assert settings.API_SERVER_WEBSERVER |
| 356 | +def mocked_webserver_rpc_api(mocker: MockerFixture) -> dict[str, MockType]: |
| 357 | + """ |
| 358 | + Mocks the webserver's simcore service RPC API for testing purposes. |
| 359 | + """ |
| 360 | + from servicelib.rabbitmq.rpc_interfaces.webserver import ( |
| 361 | + projects as projects_rpc, # keep import here |
| 362 | + ) |
365 | 363 |
|
366 | 364 | side_effects = WebserverRpcSideEffects() |
367 | 365 |
|
368 | 366 | return { |
369 | 367 | "mark_project_as_job": mocker.patch.object( |
370 | 368 | projects_rpc, |
371 | 369 | "mark_project_as_job", |
| 370 | + autospec=True, |
372 | 371 | side_effect=side_effects.mark_project_as_job, |
373 | 372 | ), |
374 | 373 | "list_projects_marked_as_jobs": mocker.patch.object( |
375 | 374 | projects_rpc, |
376 | 375 | "list_projects_marked_as_jobs", |
| 376 | + autospec=True, |
377 | 377 | side_effect=side_effects.list_projects_marked_as_jobs, |
378 | 378 | ), |
379 | 379 | } |
@@ -473,20 +473,16 @@ def mocked_catalog_rest_api_base( |
473 | 473 |
|
474 | 474 |
|
475 | 475 | @pytest.fixture |
476 | | -def mocked_catalog_rpc_api( |
477 | | - app: FastAPI, mocker: MockerFixture |
478 | | -) -> Iterable[dict[str, MockType]]: |
| 476 | +def mocked_catalog_rpc_api(mocker: MockerFixture) -> dict[str, MockType]: |
479 | 477 | """ |
480 | | - Mocks the RPC catalog service API for testing purposes. |
| 478 | + Mocks the catalog's simcore service RPC API for testing purposes. |
481 | 479 | """ |
| 480 | + from servicelib.rabbitmq.rpc_interfaces.catalog import ( |
| 481 | + services as catalog_rpc, # keep import here |
| 482 | + ) |
482 | 483 |
|
483 | | - def get_mock_rabbitmq_rpc_client(): |
484 | | - return MagicMock() |
485 | | - |
486 | | - app.dependency_overrides[get_rabbitmq_rpc_client] = get_mock_rabbitmq_rpc_client |
487 | 484 | side_effects = CatalogRpcSideEffects() |
488 | | - |
489 | | - yield { |
| 485 | + return { |
490 | 486 | "list_services_paginated": mocker.patch.object( |
491 | 487 | catalog_rpc, |
492 | 488 | "list_services_paginated", |
@@ -518,7 +514,6 @@ def get_mock_rabbitmq_rpc_client(): |
518 | 514 | side_effect=side_effects.get_service_ports, |
519 | 515 | ), |
520 | 516 | } |
521 | | - app.dependency_overrides.pop(get_rabbitmq_rpc_client) |
522 | 517 |
|
523 | 518 |
|
524 | 519 | # |
@@ -648,6 +643,7 @@ def clone_project_task(self, request: httpx.Request, *, project_id: str): |
648 | 643 | return self._set_result_and_get_reponse(project_get) |
649 | 644 |
|
650 | 645 | def get_result(self, request: httpx.Request, *, task_id: str): |
| 646 | + assert request |
651 | 647 | return httpx.Response( |
652 | 648 | status.HTTP_200_OK, json={"data": self._results[task_id]} |
653 | 649 | ) |
|
0 commit comments