Telethon/client/tests/mtsender_test.py

59 lines
1.6 KiB
Python
Raw Permalink Normal View History

2023-08-31 11:48:59 +03:00
import asyncio
import logging
2023-09-01 15:09:53 +03:00
from pytest import LogCaptureFixture, mark
from telethon._impl.mtproto import Full
from telethon._impl.mtsender import connect
from telethon._impl.tl import LAYER, abcs, functions, types
2023-08-31 11:48:59 +03:00
TELEGRAM_TEST_DC = 2, "149.154.167.40:443"
2023-08-31 11:48:59 +03:00
TEST_TIMEOUT = 10000
2023-09-01 15:09:53 +03:00
@mark.net
async def test_invoke_encrypted_method(caplog: LogCaptureFixture) -> None:
2023-08-31 11:48:59 +03:00
caplog.set_level(logging.DEBUG)
deadline = asyncio.get_running_loop().time() + TEST_TIMEOUT
def timeout() -> float:
return deadline - asyncio.get_running_loop().time()
2023-10-12 22:10:00 +03:00
sender = await asyncio.wait_for(
2023-10-29 23:45:21 +03:00
connect(
Full(),
*TELEGRAM_TEST_DC,
auth_key=None,
base_logger=logging.getLogger(__file__),
connector=lambda ip, port: asyncio.open_connection(ip, port),
),
2023-10-12 22:10:00 +03:00
timeout(),
)
rx = sender.enqueue(
functions.invoke_with_layer(
layer=LAYER,
query=functions.init_connection(
api_id=1,
device_model="Test",
system_version="0.1",
app_version="0.1",
system_lang_code="en",
lang_pack="",
lang_code="",
proxy=None,
params=None,
query=functions.help.get_nearest_dc(),
),
)
)
while True:
await asyncio.wait_for(sender.step(), timeout=timeout())
if rx.done():
nearest = abcs.NearestDc.from_bytes(rx.result())
assert isinstance(nearest, types.NearestDc)
break