Skip to content

Commit a4862d2

Browse files
committed
Fix: only mock the get_posts from client and use real client
1 parent 153eb97 commit a4862d2

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

tests/unit/services/test_voucher.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from unittest.mock import AsyncMock, MagicMock, patch
22

3+
from aleph.sdk.client.http import AlephHttpClient
34
import pytest
45
from aleph_message.models import Chain
56

@@ -16,12 +17,15 @@
1617

1718
@pytest.mark.asyncio
1819
async def test_get_evm_vouchers(mock_post_response, make_mock_aiohttp_session):
19-
mock_client = MagicMock()
20-
mock_client.get_posts = AsyncMock(return_value=mock_post_response)
21-
voucher_service = Vouchers(client=mock_client)
20+
client = AlephHttpClient(api_server="http://localhost")
21+
22+
# Patch only the get_posts who is used to fetch voucher update for EVM
23+
client.get_posts = AsyncMock(return_value=mock_post_response)
24+
voucher_service = Vouchers(client=client)
2225

2326
session = make_mock_aiohttp_session(MOCK_METADATA)
2427

28+
# Here we patch the client sessions who gonna fetch the metdata of the NFT
2529
with patch("aiohttp.ClientSession", return_value=session):
2630
vouchers = await voucher_service.get_evm_vouchers(MOCK_ADDRESS)
2731

@@ -32,12 +36,16 @@ async def test_get_evm_vouchers(mock_post_response, make_mock_aiohttp_session):
3236

3337
@pytest.mark.asyncio
3438
async def test_get_solana_vouchers(make_mock_aiohttp_session):
35-
mock_client = MagicMock()
36-
voucher_service = Vouchers(client=mock_client)
39+
client = AlephHttpClient(api_server="http://localhost")
40+
voucher_service = Vouchers(client=client)
3741

3842
registry_session = make_mock_aiohttp_session(MOCK_SOLANA_REGISTRY)
3943
metadata_session = make_mock_aiohttp_session(MOCK_METADATA)
4044

45+
# Here we patch the fetch of the registry made on
46+
# https://api.claim.twentysix.cloud/v1/registry/solanna
47+
# and we also patch the fetch of the metadata
48+
# https://claim.twentysix.cloud/sbt/metadata/{}.json
4149
with patch(
4250
"aiohttp.ClientSession", side_effect=[registry_session, metadata_session]
4351
):
@@ -52,9 +60,9 @@ async def test_get_solana_vouchers(make_mock_aiohttp_session):
5260
async def test_fetch_vouchers_by_chain_for_evm(
5361
mock_post_response, make_mock_aiohttp_session
5462
):
55-
mock_client = MagicMock()
56-
mock_client.get_posts = AsyncMock(return_value=mock_post_response)
57-
voucher_service = Vouchers(client=mock_client)
63+
client = AlephHttpClient(api_server="http://localhost")
64+
client.get_posts = AsyncMock(return_value=mock_post_response)
65+
voucher_service = Vouchers(client=client)
5866

5967
metadata_session = make_mock_aiohttp_session(MOCK_METADATA)
6068
with patch("aiohttp.ClientSession", return_value=metadata_session):
@@ -89,9 +97,9 @@ async def test_fetch_vouchers_by_chain_for_solana(make_mock_aiohttp_session):
8997
async def test_get_vouchers_detects_chain(
9098
make_mock_aiohttp_session, mock_post_response
9199
):
92-
mock_client = MagicMock()
93-
mock_client.get_posts = AsyncMock(return_value=mock_post_response)
94-
voucher_service = Vouchers(client=mock_client)
100+
client = AlephHttpClient(api_server="http://localhost")
101+
client.get_posts = AsyncMock(return_value=mock_post_response)
102+
voucher_service = Vouchers(client=client)
95103

96104
# EVM
97105
metadata_session = make_mock_aiohttp_session(MOCK_METADATA)

0 commit comments

Comments
 (0)