Files
FragmentAPI/tests/010_test_recharge_ads.py
T
bohd4nx ae164d4fe7 feat: Implement marketplace and purchases services
- Added MarketplaceService for searching usernames, numbers, and gifts.
- Introduced PurchasesService for purchasing stars and premium subscriptions.
- Created WalletService for wallet operations including balance checks and top-ups.
- Developed transaction handling for TON and USDT transfers.
- Added models for payments, marketplace results, and wallet information.
- Implemented error handling for various operations including wallet and transaction errors.
- Established domain structure for purchases, marketplace, and wallet functionalities.
2026-05-20 23:33:01 +03:00

58 lines
1.9 KiB
Python

"""Unit tests for recharge_ads — self-service Telegram Ads recharge."""
import importlib
from unittest.mock import AsyncMock, patch
import pytest
_recharge_ads_mod = importlib.import_module("pyfragment.domains.ads.recharge")
from pyfragment import AdsRechargeResult, ConfigurationError, FragmentClient
from tests.shared import FAKE_ACCOUNT, FAKE_ADS_ACCOUNT, FAKE_REQ_ID, FAKE_TRANSACTION, FAKE_TX_HASH
# recharge_ads validation tests
@pytest.mark.asyncio
async def test_recharge_ads_amount_zero(client: FragmentClient) -> None:
with pytest.raises(ConfigurationError):
await client.recharge_ads(FAKE_ADS_ACCOUNT, amount=0)
@pytest.mark.asyncio
async def test_recharge_ads_amount_too_high(client: FragmentClient) -> None:
with pytest.raises(ConfigurationError):
await client.recharge_ads(FAKE_ADS_ACCOUNT, amount=1_000_000_001)
@pytest.mark.asyncio
async def test_recharge_ads_float_amount(client: FragmentClient) -> None:
with pytest.raises(ConfigurationError):
await client.recharge_ads(FAKE_ADS_ACCOUNT, amount=5.5) # type: ignore[arg-type]
# recharge_ads mocked tests
@pytest.mark.asyncio
async def test_recharge_ads_success(client: FragmentClient) -> None:
with (
patch.object(
client,
"call",
AsyncMock(
side_effect=[
{}, # updateAdsState
{"req_id": FAKE_REQ_ID}, # initAdsRechargeRequest
FAKE_TRANSACTION, # getAdsRechargeLink
]
),
),
patch.object(_recharge_ads_mod, "get_account_info", AsyncMock(return_value=FAKE_ACCOUNT)),
patch.object(_recharge_ads_mod, "process_transaction", AsyncMock(return_value=FAKE_TX_HASH)),
):
result = await client.recharge_ads(FAKE_ADS_ACCOUNT, amount=10)
assert isinstance(result, AdsRechargeResult)
assert result.transaction_id == FAKE_TX_HASH
assert result.amount == 10