Beispiel #1
0
    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'})
Beispiel #2
0
    async def test():
        telegram = Telegram(token="token", session=aiohttp.ClientSession())

        async def req(method, kwargs={}):
            if method == "getFile" and kwargs["file_id"] == "file_id":
                return {"file_path": "123"}

        telegram._request = req

        assert await telegram._request_file("file_id") == b"content"
        assert await telegram._make_getter("file_id")() == b"content"
Beispiel #3
0
def test_execute_request():
    telegram = Telegram(token="token")

    async def req(method, kwargs):
        assert method == "method"
        assert kwargs["arg"] == "val"
        return 1

    telegram._request = req

    result = asyncio.get_event_loop().run_until_complete(
        telegram.execute_request("method", {"arg": "val"}))

    assert result == 1