-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check input params of get_info and add tests
- Loading branch information
1 parent
0f30fd2
commit 08da17d
Showing
4 changed files
with
53 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright ©, 2022, Lightspark Group, Inc. - All Rights Reserved | ||
# pyre-strict | ||
|
||
import json | ||
from secrets import token_hex | ||
from unittest.mock import ANY, AsyncMock, Mock, patch | ||
|
||
import aiohttp | ||
|
||
from nwc_backend.event_handlers.get_info_handler import get_info | ||
from nwc_backend.models.nip47_request import Nip47Request | ||
from nwc_backend.models.nip47_request_method import Nip47RequestMethod | ||
|
||
|
||
@patch.object(aiohttp.ClientSession, "get") | ||
async def test_get_info_success(mock_get: Mock) -> None: | ||
vasp_response = { | ||
"pubkey": token_hex(), | ||
"network": "mainnet", | ||
"methods": [ | ||
Nip47RequestMethod.FETCH_QUOTE.value, | ||
Nip47RequestMethod.EXECUTE_QUOTE.value, | ||
], | ||
"lud16": "$alice@uma.me", | ||
"currencies": [ | ||
{ | ||
"code": "USD", | ||
"symbol": "$", | ||
"name": "US Dollar", | ||
"multiplier": 15351.4798, | ||
"decimals": 2, | ||
"min": 1, | ||
"max": 1000_00, | ||
} | ||
], | ||
} | ||
mock_response = AsyncMock() | ||
mock_response.text = AsyncMock(return_value=json.dumps(vasp_response)) | ||
mock_response.raise_for_status = Mock() | ||
mock_get.return_value.__aenter__.return_value = mock_response | ||
|
||
response = await get_info( | ||
access_token=token_hex(), | ||
request=Nip47Request(params={}), | ||
) | ||
mock_get.assert_called_once_with(url="/info", params=None, headers=ANY) | ||
|
||
assert response.to_dict() == vasp_response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,11 @@ | ||
# Copyright ©, 2022, Lightspark Group, Inc. - All Rights Reserved | ||
# pyre-strict | ||
|
||
import logging | ||
from typing import Any | ||
|
||
from aiohttp import ClientResponseError | ||
from nostr_sdk import ErrorCode, Nip47Error | ||
from uma_auth.models.get_info_response import GetInfoResponse | ||
|
||
from nwc_backend.models.nip47_request import Nip47Request | ||
from nwc_backend.vasp_client import vasp_uma_client | ||
|
||
|
||
async def get_info( | ||
access_token: str, request: Nip47Request | ||
) -> dict[str, Any] | Nip47Error: | ||
try: | ||
response = await vasp_uma_client.get_info(access_token=access_token) | ||
return response.to_dict() | ||
except ClientResponseError as ex: | ||
logging.exception("Request get_info %s failed", str(request.id)) | ||
# TODO: more granular error code | ||
return Nip47Error(code=ErrorCode.OTHER, message=ex.message) | ||
async def get_info(access_token: str, request: Nip47Request) -> GetInfoResponse: | ||
return await vasp_uma_client.get_info(access_token=access_token) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters