Skip to content

Commit

Permalink
✨ add default wallet getter (#4985)
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgaard-itis authored Nov 8, 2023
1 parent 5ebdd6e commit b7f43af
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
router = APIRouter()


@router.get(
"/default",
response_model=WalletGetWithAvailableCredits,
include_in_schema=API_SERVER_DEV_FEATURES_ENABLED,
)
async def get_default_wallet(
webserver_api: Annotated[AuthSession, Depends(get_webserver_session)],
):
return await webserver_api.get_default_wallet()


@router.get(
"/{wallet_id}",
response_model=WalletGetWithAvailableCredits,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,17 @@ async def start_project(

# WALLETS -------------------------------------------------

async def get_default_wallet(self) -> WalletGetWithAvailableCredits:
with _handle_webserver_api_errors():
response = await self.client.get(
"/wallets/default",
cookies=self.session_cookies,
)
response.raise_for_status()
data = Envelope[WalletGetWithAvailableCredits].parse_raw(response.text).data
assert data # nosec
return data

async def get_wallet(self, wallet_id: int) -> WalletGetWithAvailableCredits:
with _handle_webserver_api_errors():
response = await self.client.get(
Expand Down
28 changes: 28 additions & 0 deletions services/api-server/tests/mocks/get_default_wallet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[
{
"name": "GET /wallets/default",
"description": "<Request('GET', 'http://webserver:8080/v0/wallets/default')>",
"method": "GET",
"host": "webserver",
"path": {
"path": "/v0/wallets/default",
"path_parameters": []
},
"query": null,
"request_payload": null,
"response_body": {
"data": {
"walletId": 1,
"name": "Bisgaard Credits",
"description": "Credits purchased by Bisgaard end up in here",
"owner": 3,
"thumbnail": null,
"status": "ACTIVE",
"created": "2023-11-06T11:23:38.559362+00:00",
"modified": "2023-11-06T11:23:38.559362+00:00",
"availableCredits": 0.0
}
},
"status_code": 200
}
]
23 changes: 23 additions & 0 deletions services/api-server/tests/unit/test_api_wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import httpx
import pytest
import respx
from fastapi import status
from httpx import AsyncClient
from models_library.api_schemas_webserver.wallets import WalletGetWithAvailableCredits
from pydantic import parse_obj_as
Expand Down Expand Up @@ -59,3 +60,25 @@ def _get_wallet_side_effect(
elif "failure" in capture:
assert response.status_code == 403
assert response.json().get("errors") is not None


async def test_get_default_wallet(
client: AsyncClient,
mocked_webserver_service_api_base,
respx_mock_from_capture: Callable[
[list[respx.MockRouter], Path, list[SideEffectCallback]],
list[respx.MockRouter],
],
auth: httpx.BasicAuth,
project_tests_dir: Path,
):

respx_mock = respx_mock_from_capture(
[mocked_webserver_service_api_base],
project_tests_dir / "mocks" / "get_default_wallet.json",
[],
)

response = await client.get(f"{API_VTAG}/wallets/default", auth=auth)
assert response.status_code == status.HTTP_200_OK
_ = parse_obj_as(WalletGetWithAvailableCredits, response.json())

0 comments on commit b7f43af

Please sign in to comment.