2023-09-01 14:42:23 +03:00
|
|
|
import os
|
|
|
|
import random
|
|
|
|
|
2023-09-01 18:41:47 +03:00
|
|
|
from pytest import mark
|
2023-09-01 14:42:23 +03:00
|
|
|
from telethon._impl.client.client.client import Client
|
|
|
|
from telethon._impl.client.client.net import Config
|
|
|
|
from telethon._impl.session.message_box.defs import Session
|
|
|
|
from telethon._impl.tl.mtproto import functions, types
|
|
|
|
|
|
|
|
|
2023-09-01 15:09:53 +03:00
|
|
|
@mark.api
|
|
|
|
@mark.net
|
2023-09-01 15:02:24 +03:00
|
|
|
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
|
|
|
|
client = Client(
|
|
|
|
Config(
|
2023-09-02 01:48:26 +03:00
|
|
|
session=Session(),
|
2023-09-01 15:02:24 +03:00
|
|
|
api_id=int(api_id),
|
|
|
|
api_hash=api_hash,
|
2023-09-01 14:42:23 +03:00
|
|
|
)
|
2023-09-01 15:02:24 +03:00
|
|
|
)
|
|
|
|
assert not client.connected
|
|
|
|
await client.connect()
|
|
|
|
assert client.connected
|
2023-09-01 14:42:23 +03:00
|
|
|
|
2023-09-01 15:02:24 +03:00
|
|
|
ping_id = random.randrange(-(2**63), 2**63)
|
|
|
|
pong = await client(functions.ping(ping_id=ping_id))
|
|
|
|
assert isinstance(pong, types.Pong)
|
|
|
|
assert pong.ping_id == ping_id
|