Skip to content

Commit

Permalink
fix unit api-server tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgaard-itis committed Dec 13, 2024
1 parent f80853a commit 8a52ec3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@

from .. import exceptions
from .._meta import API_VERSION, API_VTAG, APP_NAME
from ..api.dependencies.rabbitmq import get_rabbitmq_rpc_client
from ..api.root import create_router
from ..api.routes.health import router as health_router
from ..services_http import catalog, director_v2, storage, webserver
from ..services_http.rabbitmq import setup_rabbitmq
from ..services_rpc import wb_api_server
from ._prometheus_instrumentation import setup_prometheus_instrumentation
from .events import create_start_app_handler, create_stop_app_handler
from .openapi import override_openapi_method, use_route_names_as_operation_ids
Expand Down Expand Up @@ -94,7 +92,6 @@ def init_app(settings: ApplicationSettings | None = None) -> FastAPI:
settings.API_SERVER_WEBSERVER,
tracing_settings=settings.API_SERVER_TRACING,
)
wb_api_server.setup(app, get_rabbitmq_rpc_client(app))

if settings.API_SERVER_CATALOG:
catalog.setup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from servicelib.rabbitmq import RabbitMQClient, wait_till_rabbitmq_responsive
from servicelib.rabbitmq._client_rpc import RabbitMQRPCClient
from settings_library.rabbit import RabbitSettings
from simcore_service_api_server.api.dependencies.rabbitmq import get_rabbitmq_rpc_client
from simcore_service_api_server.services_rpc import wb_api_server

from ..core.health_checker import ApiServerHealthChecker
from ..services_http.log_streaming import LogDistributor
Expand Down Expand Up @@ -36,6 +38,7 @@ async def _on_startup() -> None:
await app.state.health_checker.setup(
app.state.settings.API_SERVER_HEALTH_CHECK_TASK_PERIOD_SECONDS
)
wb_api_server.setup(app, get_rabbitmq_rpc_client(app))

async def _on_shutdown() -> None:
if app.state.health_checker:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def fake_project_for_streaming(
fake_project = ProjectGet.model_validate(data)
fake_project.workbench = {faker.uuid4(): faker.uuid4()}
mocker.patch(
"simcore_service_api_server.api.dependencies.webserver.AuthSession.get_project",
"simcore_service_api_server.api.dependencies.webserver_http.AuthSession.get_project",
return_value=fake_project,
)

Expand Down
33 changes: 14 additions & 19 deletions services/api-server/tests/unit/test_licensed_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import asyncio

import pytest
from fastapi import status
from fastapi import FastAPI, status
from httpx import AsyncClient, BasicAuth
from models_library.api_schemas_webserver.licensed_items import (
LicensedItemGet as _LicensedItemGet,
Expand All @@ -18,28 +18,17 @@
from servicelib.rabbitmq._client_rpc import RabbitMQRPCClient
from servicelib.rabbitmq._errors import RemoteMethodNotRegisteredError
from simcore_service_api_server._meta import API_VTAG
from simcore_service_api_server.api.dependencies.webserver_rpc import (
get_wb_api_rpc_client,
)
from simcore_service_api_server.models.pagination import Page
from simcore_service_api_server.models.schemas.model_adapter import LicensedItemGet


@pytest.fixture
async def mock_rabbitmq_rpc_client(mocker: MockerFixture) -> MockerFixture:
class DummyRabbitMqRpcClient:
pass

def _get_dummy_rpc_client():
return DummyRabbitMqRpcClient

mocker.patch(
"simcore_service_api_server.core.application.get_rabbitmq_rpc_client",
sideeffect=_get_dummy_rpc_client,
)
return mocker
from simcore_service_api_server.services_rpc.wb_api_server import WbApiRpcClient


@pytest.fixture
async def mock_wb_api_server_rcp(
mock_rabbitmq_rpc_client: MockerFixture, exception_to_raise: Exception | None
app: FastAPI, mocker: MockerFixture, exception_to_raise: Exception | None
) -> MockerFixture:
async def _get_backend_licensed_items(
rabbitmq_rpc_client: RabbitMQRPCClient,
Expand All @@ -59,12 +48,18 @@ async def _get_backend_licensed_items(
total=len(examples),
)

mock_rabbitmq_rpc_client.patch(
class DummyRpcClient:
pass

app.dependency_overrides[get_wb_api_rpc_client] = lambda: WbApiRpcClient(
_client=DummyRpcClient()
)
mocker.patch(
"simcore_service_api_server.services_rpc.wb_api_server._get_licensed_items",
_get_backend_licensed_items,
)

return mock_rabbitmq_rpc_client
return mocker


@pytest.mark.parametrize("exception_to_raise", [None])
Expand Down
2 changes: 1 addition & 1 deletion services/api-server/tests/unit/test_services_rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ async def deregister(self, job_id: None):

async def test_log_generator(mocker: MockFixture, faker: Faker):
mocker.patch(
"simcore_service_api_server.services.log_streaming.LogStreamer._project_done",
"simcore_service_api_server.services_http.log_streaming.LogStreamer._project_done",
return_value=True,
)
log_streamer = LogStreamer(user_id=3, director2_api=None, job_id=None, log_distributor=_MockLogDistributor(), log_check_timeout=1) # type: ignore
Expand Down

0 comments on commit 8a52ec3

Please sign in to comment.