diff --git a/services/api-server/tests/mocks/get_wallet_failure.json b/services/api-server/tests/mocks/get_wallet_failure.json index 88a68577fb8..598acd66bcc 100644 --- a/services/api-server/tests/mocks/get_wallet_failure.json +++ b/services/api-server/tests/mocks/get_wallet_failure.json @@ -51,5 +51,5 @@ } }, "status_code": 403 - }, + } ] diff --git a/services/api-server/tests/mocks/get_wallet_success.json b/services/api-server/tests/mocks/get_wallet_success.json index b94a535e019..d5cbcaba734 100644 --- a/services/api-server/tests/mocks/get_wallet_success.json +++ b/services/api-server/tests/mocks/get_wallet_success.json @@ -42,5 +42,5 @@ } }, "status_code": 200 - }, + } ] diff --git a/services/api-server/tests/unit/conftest.py b/services/api-server/tests/unit/conftest.py index 33d24c2e02b..337672dc542 100644 --- a/services/api-server/tests/unit/conftest.py +++ b/services/api-server/tests/unit/conftest.py @@ -258,7 +258,7 @@ def mocked_webserver_service_api_base( # pylint: disable=not-context-manager with respx.mock( - base_url=settings.API_SERVER_WEBSERVER.api_base_url, + base_url=settings.API_SERVER_WEBSERVER.base_url, assert_all_called=False, assert_all_mocked=True, ) as respx_mock: diff --git a/services/api-server/tests/unit/test_api_wallets.py b/services/api-server/tests/unit/test_api_wallets.py new file mode 100644 index 00000000000..a66fae13714 --- /dev/null +++ b/services/api-server/tests/unit/test_api_wallets.py @@ -0,0 +1,55 @@ +from pathlib import Path +from typing import Any, Callable + +import httpx +import pytest +import respx +from httpx import AsyncClient +from models_library.api_schemas_webserver.wallets import WalletGet +from pydantic import parse_obj_as +from simcore_service_api_server._meta import API_VTAG +from simcore_service_api_server.utils.http_calls_capture import HttpApiCallCaptureModel +from unit.conftest import SideEffectCallback + + +def _get_wallet_side_effect( + request: httpx.Request, + path_params: dict[str, Any], + capture: HttpApiCallCaptureModel, +) -> Any: + response = capture.response_body + assert isinstance(response, dict) + if isinstance(response.get("data"), dict): + assert response.get("data").get("walletId") is not None + response["data"]["walletId"] = path_params["wallet_id"] + return response + + +@pytest.mark.parametrize( + "capture", ["get_wallet_success.json", "get_wallet_failure.json"] +) +async def test_get_wallet( + client: AsyncClient, + mocked_webserver_service_api_base, + respx_mock_from_capture: Callable[ + [respx.MockRouter, Path, list[SideEffectCallback] | None], respx.MockRouter + ], + auth: httpx.BasicAuth, + project_tests_dir: Path, + capture: str, +): + respx_mock = respx_mock_from_capture( + mocked_webserver_service_api_base, + project_tests_dir / "mocks" / capture, + [_get_wallet_side_effect], + ) + + wallet_id: int = 159873 + response = await client.get(f"{API_VTAG}/wallets/{wallet_id}", auth=auth) + if "success" in capture: + assert response.status_code == 200 + wallet: WalletGet = parse_obj_as(WalletGet, response.json()) + assert wallet.wallet_id == wallet_id + elif "failure" in capture: + assert response.status_code == 403 + assert response.json().get("errors") is not None