diff --git a/services/api-server/tests/unit/api_solvers/conftest.py b/services/api-server/tests/unit/api_solvers/conftest.py index 62974eb1ed9c..49be43bd01aa 100644 --- a/services/api-server/tests/unit/api_solvers/conftest.py +++ b/services/api-server/tests/unit/api_solvers/conftest.py @@ -3,7 +3,10 @@ # pylint: disable=unused-variable -from typing import Iterator +import json +from copy import deepcopy +from pathlib import Path +from typing import Any, Iterator import pytest import respx @@ -13,18 +16,34 @@ from simcore_service_api_server.core.settings import ApplicationSettings +@pytest.fixture(scope="session") +def catalog_service_openapi_specs(osparc_simcore_services_dir: Path) -> dict[str, Any]: + + openapi_path = osparc_simcore_services_dir / "catalog" / "openapi.json" + openapi_specs = json.loads(openapi_path.read_text()) + return openapi_specs + + @pytest.fixture -def mocked_catalog_service_api(app: FastAPI) -> Iterator[MockRouter]: +def mocked_catalog_service_api( + app: FastAPI, catalog_service_openapi_specs: dict[str, Any] +) -> Iterator[MockRouter]: settings: ApplicationSettings = app.state.settings assert settings.API_SERVER_CATALOG + openapi = deepcopy(catalog_service_openapi_specs) + schemas = openapi["components"]["schemas"] + # pylint: disable=not-context-manager with respx.mock( - base_url=settings.API_SERVER_CATALOG.base_url, + base_url=settings.API_SERVER_CATALOG.api_base_url, assert_all_called=False, assert_all_mocked=True, ) as respx_mock: + respx_mock.get("/meta").respond(200, json=schemas["Meta"]["example"]) + + # ---- respx_mock.get( "/services?user_id=1&details=false", name="list_services" ).respond( @@ -42,4 +61,19 @@ def mocked_catalog_service_api(app: FastAPI) -> Iterator[MockRouter]: ], ) + # ----- + # NOTE: we could use https://python-jsonschema.readthedocs.io/en/stable/ + # + + # https://regex101.com/r/drVAGr/1 + respx_mock.get( + path__regex=r"/services/(?P[\w%]+)/(?P[\d\.]+)/ports\?user_id=(?P\d+)", + name="list_service_ports", + ).respond( + 200, + json=[ + schemas["ServicePortGet"]["example"], + ], + ) + yield respx_mock diff --git a/services/api-server/tests/unit/api_solvers/test_api_routers_solvers.py b/services/api-server/tests/unit/api_solvers/test_api_routers_solvers.py index 59c789c385b9..893095e5de63 100644 --- a/services/api-server/tests/unit/api_solvers/test_api_routers_solvers.py +++ b/services/api-server/tests/unit/api_solvers/test_api_routers_solvers.py @@ -6,6 +6,7 @@ import httpx import pytest import simcore_service_api_server.api.routes.solvers +from pytest_mock import MockFixture from respx import MockRouter from simcore_service_api_server.models.schemas.solvers import Solver from starlette import status @@ -15,7 +16,7 @@ async def test_list_solvers( client: httpx.AsyncClient, mocked_catalog_service_api: MockRouter, - mocker, + mocker: MockFixture, ): warn = mocker.patch.object( simcore_service_api_server.api.routes.solvers.logger, "warning" @@ -60,3 +61,29 @@ async def test_list_solvers( assert f"GET latest {solver.id}" in resp2.json()["errors"][0] # assert Solver(**resp2.json()) == Solver(**resp3.json()) + + +async def test_list_solver_ports( + client: httpx.AsyncClient, + auth: httpx.BasicAuth, + mocked_catalog_service_api: MockRouter, +): + resp = await client.get( + "/v0/solvers/simcore/services/comp/itis/sleeper/releases/2.1.4/ports", + auth=auth, + ) + assert resp.status_code == status.HTTP_200_OK + + assert resp.json() == [ + { + "name": "input_1", + "kind": "input", + "content_schema": { + "title": "Sleep interval", + "type": "integer", + "x_unit": "second", + "minimum": 0, + "maximum": 5, + }, + } + ]