mirror of
https://github.com/bohd4nx/FragmentAPI.git
synced 2026-07-25 06:14:29 +00:00
ebd45d2991
- Implement tests for Stars methods: purchase_stars and giveaway_stars, including validation and success scenarios. - Add tests for Premium methods: purchase_premium and giveaway_premium, covering validation and success cases. - Create tests for topup_ton functionality, validating input and mocking successful operations. - Introduce wallet tests to verify get_wallet() functionality, ensuring correct wallet info retrieval. - Add tests for FragmentClient.call() method, validating API response handling and data merging. - Implement tests for anonymous number methods, including login codes and session management. - Create recharge_ads tests for self-service Telegram Ads recharge, validating input and success scenarios. - Add username search tests for the Fragment marketplace, ensuring correct result parsing and parameter forwarding. - Implement number search tests for the Fragment marketplace, validating result parsing and parameter handling. - Create gift search tests for the Fragment gifts marketplace, ensuring correct result parsing and parameter forwarding. - Add cookie extraction tests for get_cookies_from_browser(), validating successful extraction and error handling.
75 lines
2.2 KiB
Python
75 lines
2.2 KiB
Python
"""Unit tests for topup_ton — TON Ads balance top-up."""
|
|
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
|
|
from pyfragment import FragmentClient
|
|
from pyfragment.types import AdsTopupResult, ConfigurationError, UserNotFoundError
|
|
from tests.shared import FAKE_ACCOUNT, FAKE_RECIPIENT, FAKE_REQ_ID, FAKE_TRANSACTION, FAKE_TX_HASH
|
|
|
|
# Topup TON validation tests
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_topup_ton_amount_zero(client: FragmentClient) -> None:
|
|
with pytest.raises(ConfigurationError):
|
|
await client.topup_ton("@user", amount=0)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_topup_ton_amount_too_high(client: FragmentClient) -> None:
|
|
with pytest.raises(ConfigurationError):
|
|
await client.topup_ton("@user", amount=1_000_000_001)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_topup_ton_float_amount(client: FragmentClient) -> None:
|
|
with pytest.raises(ConfigurationError):
|
|
await client.topup_ton("@user", amount=1.5) # type: ignore[arg-type]
|
|
|
|
|
|
# Topup TON mocked tests
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_topup_ton_success(client: FragmentClient) -> None:
|
|
with (
|
|
patch.object(
|
|
client,
|
|
"call",
|
|
AsyncMock(
|
|
side_effect=[
|
|
{}, # updateAdsTopupState
|
|
{"found": {"recipient": FAKE_RECIPIENT}},
|
|
{"req_id": FAKE_REQ_ID},
|
|
FAKE_TRANSACTION,
|
|
]
|
|
),
|
|
),
|
|
patch("pyfragment.methods.topup_ton.get_account_info", AsyncMock(return_value=FAKE_ACCOUNT)),
|
|
patch("pyfragment.methods.topup_ton.process_transaction", AsyncMock(return_value=FAKE_TX_HASH)),
|
|
):
|
|
result = await client.topup_ton("@user", amount=10)
|
|
|
|
assert isinstance(result, AdsTopupResult)
|
|
assert result.transaction_id == FAKE_TX_HASH
|
|
assert result.username == "@user"
|
|
assert result.amount == 10
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_topup_ton_user_not_found(client: FragmentClient) -> None:
|
|
with patch.object(
|
|
client,
|
|
"call",
|
|
AsyncMock(
|
|
side_effect=[
|
|
{}, # updateAdsTopupState
|
|
{"found": {}},
|
|
]
|
|
),
|
|
):
|
|
with pytest.raises(UserNotFoundError):
|
|
await client.topup_ton("@ghost", amount=10)
|