mirror of
https://github.com/bohd4nx/FragmentAPI.git
synced 2026-07-25 06:14:29 +00:00
3e14a01c92
- Security & validation: tighten hash regex, add HTTP timeouts to all requests, pass client.timeout through get_fragment_hash and AsyncClient - Constants: move all constants to types/constants.py; remove re-exports from types/__init__.py; add DEFAULT_TIMEOUT, REQUIRED_COOKIE_KEYS - FragmentClient: add timeout param (default 30 s); async-context-manager support; remove WALLET_CLASSES from public API - Exceptions: remove dead INVALID_USERNAME constant (Fragment validates server-side); keep full hierarchy intact - Tests: add 006_test_methods_mock.py (6 mock tests for all 3 methods); DRY-refactor 004_test_balance.py (_patch_wallet context manager); clean up 005_test_methods.py (remove fragile network test, rename tests) - Examples: switch all 4 examples to async-with; align error messages; replace %-format with f-strings - README: rewrite usage section with single comprehensive async-with example covering all 3 methods and full exception hierarchy - CI: add mypy step to lint job; add pytest-mock and mypy to dev deps; set FORCE_JAVASCRIPT_ACTIONS_TO_NODE24 on all jobs; fix COOKIES_JSON to job-level env var
57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
"""Unit tests for method-level input validation — no network calls."""
|
|
|
|
import pytest
|
|
|
|
from pyfragment import FragmentClient
|
|
from pyfragment.types import ConfigurationError
|
|
|
|
VALID_SEED = "abandon " * 23 + "about"
|
|
VALID_API_KEY = "A" * 68
|
|
VALID_COOKIES = {
|
|
"stel_ssid": "x",
|
|
"stel_dt": "x",
|
|
"stel_token": "x",
|
|
"stel_ton_token": "x",
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def client() -> FragmentClient:
|
|
return FragmentClient(seed=VALID_SEED, api_key=VALID_API_KEY, cookies=VALID_COOKIES)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_purchase_premium_invalid_months(client: FragmentClient) -> None:
|
|
with pytest.raises(ConfigurationError):
|
|
await client.purchase_premium("@user", months=5)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_purchase_stars_amount_too_low(client: FragmentClient) -> None:
|
|
with pytest.raises(ConfigurationError):
|
|
await client.purchase_stars("@user", amount=49)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_purchase_stars_amount_too_high(client: FragmentClient) -> None:
|
|
with pytest.raises(ConfigurationError):
|
|
await client.purchase_stars("@user", amount=1_000_001)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_purchase_stars_float_amount(client: FragmentClient) -> None:
|
|
with pytest.raises(ConfigurationError):
|
|
await client.purchase_stars("@user", amount=100.5) # type: ignore[arg-type]
|
|
|
|
|
|
@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)
|