mirror of
https://github.com/bohd4nx/FragmentAPI.git
synced 2026-07-25 06:14:29 +00:00
dc9661134d
- Removed the old CookieResult model from pyfragment.core.models and created a new one in pyfragment.services.cookies.models. - Implemented get_cookies_from_browser function in pyfragment.services.cookies.service to extract cookies directly from supported browsers. - Updated imports across various modules to reflect the new structure and removed unused imports. - Cleaned up models in ads, anonymous_numbers, giveaways, marketplace, and purchases domains by removing unnecessary __all__ declarations. - Added new example scripts for cookie extraction and various purchase functionalities. - Consolidated constants into a new pyfragment.core.constants module for better organization.
58 lines
2.0 KiB
Python
58 lines
2.0 KiB
Python
"""Cover Telegram Ads recharge flow, including request preparation and KYC handling."""
|
|
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
|
|
import pyfragment.domains.ads.recharge as _recharge_ads_mod
|
|
from pyfragment import AdsRechargeResult, ConfigurationError, FragmentClient
|
|
from pyfragment.core.constants import GRAM_TOPUP_MAX, GRAM_TOPUP_MIN
|
|
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=GRAM_TOPUP_MIN - 1)
|
|
|
|
|
|
@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=GRAM_TOPUP_MAX + 1)
|
|
|
|
|
|
@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
|