Skip to content

Commit f2415df

Browse files
committed
fix: move fixture / metdata for voucher to conftest.py
1 parent c61e420 commit f2415df

File tree

3 files changed

+70
-61
lines changed

3 files changed

+70
-61
lines changed

tests/unit/conftest.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,65 @@ def post(self, *_args, **_kwargs):
306306
client._http_session = http_session
307307

308308
return client
309+
310+
311+
@pytest.fixture
312+
def make_mock_aiohttp_session():
313+
def _make(mocked_json_response):
314+
mock_response = AsyncMock()
315+
mock_response.json.return_value = mocked_json_response
316+
mock_response.raise_for_status.return_value = None
317+
318+
session = MagicMock()
319+
320+
get_cm = AsyncMock()
321+
get_cm.__aenter__.return_value = mock_response
322+
session.get.return_value = get_cm
323+
324+
session_cm = AsyncMock()
325+
session_cm.__aenter__.return_value = session
326+
return session_cm
327+
328+
return _make
329+
330+
331+
# Constants needed for voucher tests
332+
MOCK_ADDRESS = "0x1234567890123456789012345678901234567890"
333+
MOCK_SOLANA_ADDRESS = "abcdefghijklmnopqrstuvwxyz123456789"
334+
MOCK_METADATA_ID = "metadata123"
335+
MOCK_VOUCHER_ID = "voucher123"
336+
MOCK_METADATA = {
337+
"name": "Test Voucher",
338+
"description": "A test voucher",
339+
"external_url": "https://example.com",
340+
"image": "https://example.com/image.png",
341+
"icon": "https://example.com/icon.png",
342+
"attributes": [
343+
{"trait_type": "Test Trait", "value": "Test Value"},
344+
{"trait_type": "Numeric Trait", "value": "123", "display_type": "number"},
345+
],
346+
}
347+
348+
MOCK_EVM_VOUCHER_DATA = [
349+
(MOCK_VOUCHER_ID, {"claimer": MOCK_ADDRESS, "metadata_id": MOCK_METADATA_ID})
350+
]
351+
352+
MOCK_SOLANA_REGISTRY = {
353+
"claimed_tickets": {
354+
"solticket123": {"claimer": MOCK_SOLANA_ADDRESS, "batch_id": "batch123"}
355+
},
356+
"batches": {"batch123": {"metadata_id": MOCK_METADATA_ID}},
357+
}
358+
359+
360+
@pytest.fixture
361+
def mock_post_response():
362+
mock_post = MagicMock()
363+
mock_post.content = {
364+
"nft_vouchers": {
365+
MOCK_VOUCHER_ID: {"claimer": MOCK_ADDRESS, "metadata_id": MOCK_METADATA_ID}
366+
}
367+
}
368+
posts_response = MagicMock()
369+
posts_response.posts = [mock_post]
370+
return posts_response

tests/unit/services/test_authenticated_voucher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from aleph.sdk.client.services.authenticated_voucher import AuthenticatedVoucher
66

7-
from .test_voucher import (
7+
from ..conftest import (
88
MOCK_ADDRESS,
99
MOCK_METADATA,
1010
MOCK_SOLANA_ADDRESS,

tests/unit/services/test_voucher.py

Lines changed: 7 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,13 @@
55

66
from aleph.sdk.client.services.voucher import Vouchers
77

8-
MOCK_ADDRESS = "0x1234567890123456789012345678901234567890"
9-
MOCK_SOLANA_ADDRESS = "abcdefghijklmnopqrstuvwxyz123456789"
10-
11-
MOCK_METADATA_ID = "metadata123"
12-
MOCK_VOUCHER_ID = "voucher123"
13-
MOCK_METADATA = {
14-
"name": "Test Voucher",
15-
"description": "A test voucher",
16-
"external_url": "https://example.com",
17-
"image": "https://example.com/image.png",
18-
"icon": "https://example.com/icon.png",
19-
"attributes": [
20-
{"trait_type": "Test Trait", "value": "Test Value"},
21-
{"trait_type": "Numeric Trait", "value": "123", "display_type": "number"},
22-
],
23-
}
24-
25-
MOCK_EVM_VOUCHER_DATA = [
26-
(MOCK_VOUCHER_ID, {"claimer": MOCK_ADDRESS, "metadata_id": MOCK_METADATA_ID})
27-
]
28-
29-
MOCK_SOLANA_REGISTRY = {
30-
"claimed_tickets": {
31-
"solticket123": {"claimer": MOCK_SOLANA_ADDRESS, "batch_id": "batch123"}
32-
},
33-
"batches": {"batch123": {"metadata_id": MOCK_METADATA_ID}},
34-
}
35-
36-
37-
@pytest.fixture
38-
def make_mock_aiohttp_session():
39-
def _make(mocked_json_response):
40-
mock_response = AsyncMock()
41-
mock_response.json.return_value = mocked_json_response
42-
mock_response.raise_for_status.return_value = None
43-
44-
session = MagicMock()
45-
46-
get_cm = AsyncMock()
47-
get_cm.__aenter__.return_value = mock_response
48-
session.get.return_value = get_cm
49-
50-
session_cm = AsyncMock()
51-
session_cm.__aenter__.return_value = session
52-
return session_cm
53-
54-
return _make
55-
56-
57-
@pytest.fixture
58-
def mock_post_response():
59-
mock_post = MagicMock()
60-
mock_post.content = {
61-
"nft_vouchers": {
62-
MOCK_VOUCHER_ID: {"claimer": MOCK_ADDRESS, "metadata_id": MOCK_METADATA_ID}
63-
}
64-
}
65-
posts_response = MagicMock()
66-
posts_response.posts = [mock_post]
67-
return posts_response
8+
from ..conftest import (
9+
MOCK_ADDRESS,
10+
MOCK_METADATA,
11+
MOCK_SOLANA_ADDRESS,
12+
MOCK_SOLANA_REGISTRY,
13+
MOCK_VOUCHER_ID,
14+
)
6815

6916

7017
@pytest.mark.asyncio

0 commit comments

Comments
 (0)