Telethon/client/tests/client_test.py

28 lines
664 B
Python
Raw Normal View History

2023-09-01 14:42:23 +03:00
import os
import random
2023-09-01 18:41:47 +03:00
from pytest import mark
2024-06-07 23:14:17 +03:00
from telethon import Client
from telethon import _tl as tl
2023-09-01 14:42:23 +03:00
2023-09-01 15:09:53 +03:00
@mark.api
@mark.net
async def test_ping_pong() -> None:
api_id = os.getenv("TG_ID")
api_hash = os.getenv("TG_HASH")
assert api_id and api_id.isdigit()
assert api_hash
2023-09-10 20:54:05 +03:00
client = Client(None, int(api_id), api_hash)
assert not client.connected
await client.connect()
assert client.connected
2023-09-01 14:42:23 +03:00
ping_id = random.randrange(-(2**63), 2**63)
pong = await client(tl.mtproto.functions.ping(ping_id=ping_id))
assert isinstance(pong, tl.mtproto.types.Pong)
assert pong.ping_id == ping_id
await client.disconnect()