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.
76 lines
2.4 KiB
Python
76 lines
2.4 KiB
Python
"""Cover GRAM (ex TON) top-up through Telegram Ads, including recipient lookup and transaction building."""
|
|
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
|
|
import pyfragment.domains.ads.tonup as _topup_gram_mod
|
|
from pyfragment import AdsTopupResult, ConfigurationError, FragmentClient, UserNotFoundError
|
|
from pyfragment.core.constants import GRAM_TOPUP_MAX, GRAM_TOPUP_MIN
|
|
from tests.shared import FAKE_ACCOUNT, FAKE_RECIPIENT, FAKE_REQ_ID, FAKE_TRANSACTION, FAKE_TX_HASH
|
|
|
|
# Topup GRAM (ex TON) validation tests
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_topup_gram_amount_zero(client: FragmentClient) -> None:
|
|
with pytest.raises(ConfigurationError):
|
|
await client.topup_gram("@user", amount=GRAM_TOPUP_MIN - 1)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_topup_gram_amount_too_high(client: FragmentClient) -> None:
|
|
with pytest.raises(ConfigurationError):
|
|
await client.topup_gram("@user", amount=GRAM_TOPUP_MAX + 1)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_topup_gram_float_amount(client: FragmentClient) -> None:
|
|
with pytest.raises(ConfigurationError):
|
|
await client.topup_gram("@user", amount=1.5) # type: ignore[arg-type]
|
|
|
|
|
|
# Topup GRAM (ex TON) mocked tests
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_topup_gram_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.object(_topup_gram_mod, "get_account_info", AsyncMock(return_value=FAKE_ACCOUNT)),
|
|
patch.object(_topup_gram_mod, "process_transaction", AsyncMock(return_value=FAKE_TX_HASH)),
|
|
):
|
|
result = await client.topup_gram("@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_gram_user_not_found(client: FragmentClient) -> None:
|
|
with patch.object(
|
|
client,
|
|
"call",
|
|
AsyncMock(
|
|
side_effect=[
|
|
{}, # updateAdsTopupState
|
|
{"found": {}},
|
|
]
|
|
),
|
|
):
|
|
with pytest.raises(UserNotFoundError):
|
|
await client.topup_gram("@ghost", amount=10)
|