mirror of
https://github.com/bohd4nx/FragmentAPI.git
synced 2026-07-25 14:24:31 +00:00
01a5befd87
- Removed wallet transaction and transfer logic from the wallet domain. - Introduced a new tonapi module to handle transactions and balance checks. - Updated tests to reflect the new structure and ensure functionality remains intact. - Added functionality for sending TON and USDT transfers through the tonapi module. - Improved error handling and validation for payment balances. - Cleaned up and organized imports across the codebase.
88 lines
3.1 KiB
Python
88 lines
3.1 KiB
Python
"""Verify anonymous number search parsing and query forwarding."""
|
|
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
|
|
from pyfragment import FragmentClient, NumbersResult
|
|
|
|
FAKE_HTML = """
|
|
<tr class="tm-row-selectable">
|
|
<td><a href="/number/8880000888" class="table-cell">
|
|
<div class="table-cell-value tm-value">+888 0000 888</div>
|
|
<div class="table-cell-status-thin thin-only tm-status-avail">For sale</div>
|
|
</a></td>
|
|
<td><div class="table-cell-value tm-value icon-before icon-ton">150</div>
|
|
<time datetime="2026-05-15T10:00:00+00:00" data-relative="short-text">May 15</time>
|
|
</td>
|
|
<td><div class="table-cell-value tm-value tm-status-avail">For sale</div></td>
|
|
</tr>
|
|
"""
|
|
|
|
|
|
# search_numbers result parsing tests
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_search_numbers_basic(client: FragmentClient) -> None:
|
|
with patch.object(client, "call", AsyncMock(return_value={"ok": True, "html": FAKE_HTML})):
|
|
result = await client.search_numbers("888")
|
|
|
|
assert isinstance(result, NumbersResult)
|
|
assert len(result.items) == 1
|
|
assert result.items[0]["slug"] == "number/8880000888"
|
|
assert result.items[0]["name"] == "+888 0000 888"
|
|
assert result.items[0]["date"] == "2026-05-15T10:00:00+00:00"
|
|
assert result.next_offset_id is None
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_search_numbers_empty_html(client: FragmentClient) -> None:
|
|
with patch.object(client, "call", AsyncMock(return_value={"ok": True})):
|
|
result = await client.search_numbers("zzz_no_results")
|
|
|
|
assert isinstance(result, NumbersResult)
|
|
assert result.items == []
|
|
assert result.next_offset_id is None
|
|
|
|
|
|
# search_numbers parameter forwarding tests
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_search_numbers_with_sort_and_filter(client: FragmentClient) -> None:
|
|
mock_call = AsyncMock(return_value={"ok": True, "html": FAKE_HTML})
|
|
with patch.object(client, "call", mock_call):
|
|
result = await client.search_numbers("888", sort="price_asc", filter="sale")
|
|
|
|
assert isinstance(result, NumbersResult)
|
|
call_data = mock_call.call_args[0][1]
|
|
assert call_data["type"] == "numbers"
|
|
assert call_data["sort"] == "price_asc"
|
|
assert call_data["filter"] == "sale"
|
|
assert call_data["query"] == "888"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_search_numbers_with_offset_id(client: FragmentClient) -> None:
|
|
mock_call = AsyncMock(return_value={"ok": True, "html": FAKE_HTML, "next_offset_id": "offset_50"})
|
|
with patch.object(client, "call", mock_call):
|
|
result = await client.search_numbers("888", offset_id="offset_50")
|
|
|
|
assert isinstance(result, NumbersResult)
|
|
assert result.next_offset_id == "offset_50"
|
|
call_data = mock_call.call_args[0][1]
|
|
assert call_data["offset_id"] == "offset_50"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_search_numbers_default_query(client: FragmentClient) -> None:
|
|
mock_call = AsyncMock(return_value={"ok": True, "html": FAKE_HTML})
|
|
with patch.object(client, "call", mock_call):
|
|
result = await client.search_numbers()
|
|
|
|
assert isinstance(result, NumbersResult)
|
|
call_data = mock_call.call_args[0][1]
|
|
assert call_data["query"] == ""
|
|
assert call_data["type"] == "numbers"
|