async def test(): telegram = Telegram(token="token", session=aiohttp.ClientSession()) telegram.api_messages_lock = asyncio.Lock() async def req(method, kwargs): requests.append((method, kwargs)) telegram._request = req attachment = Attachment.new(b"file") await telegram.execute_send(1, "", attachment, {}) attachment = Attachment.new(b"file", type="doc") await telegram.execute_send(1, "", attachment, {}) attachment = Attachment.new(b"file", type="voice") await telegram.execute_send(1, "", attachment, {}) assert len(requests) == 3 assert requests[0] == ("sendPhoto", {"chat_id": "1", "photo": b"file"}) assert requests[1] == ("sendDocument", { "chat_id": '1', "document": b'file' }) assert requests[2] == ("sendVoice", {"chat_id": '1', "voice": b'file'})
async def test(): telegram = Telegram(token="token", session=aiohttp.ClientSession()) telegram.api_messages_lock = asyncio.Lock() attachment = Attachment.new(b"bruh", type="location") with pytest.raises(ValueError): await telegram.execute_send(1, "", attachment, {})
async def test(): mock.return_value = "OK" tg = Telegram("token") tg.api_messages_lock = asyncio.Lock() resp = await tg.request("method", arg1="val1") assert resp == "OK" mock.assert_awaited_with("method", {"arg1": "val1"}) resp = await tg.send_message("user1", "msg", arg1="val1") assert resp == ["OK"] mock.assert_awaited_with( "sendMessage", { "chat_id": "user1", "text": "msg", "arg1": "val1" }, )