示例#1
0
def test_execute_request():
    vkontakte = VkontakteLongpoll(token="token")

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

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

    assert result == 1
示例#2
0
def test_execute_send_string():
    vkontakte = VkontakteLongpoll(token="token")

    async def req(method, kwargs):
        assert method == "messages.send"
        assert kwargs["attachment"] == "hey,hoy"
        return 1
    vkontakte._request = req

    result = asyncio.get_event_loop().run_until_complete(
        vkontakte.execute_send(1, "text", ("hey", "hoy"), {})
    )

    assert result == 1
示例#3
0
def test_execute_send_sticker():
    vkontakte = VkontakteLongpoll(token="token")

    async def req(method, kwargs):
        assert method == "messages.send"
        assert "attachment" not in kwargs
        assert kwargs["sticker_id"] == "123"
        return 1
    vkontakte._request = req

    sticker_attachment = Attachment.existing("123", "sticker")

    result = asyncio.get_event_loop().run_until_complete(
        vkontakte.execute_send(1, "text", sticker_attachment, {})
    )

    assert result == 1
示例#4
0
def test_execute_send_new():
    vkontakte = VkontakteLongpoll(token="token")

    async def _upl_att(attachment, peer_id):
        return attachment._replace(id=1, raw={"ok": "ok"})
    vkontakte.upload_attachment = _upl_att

    async def req(method, kwargs):
        assert method == "messages.send"
        assert kwargs["attachment"] == "1"
        return 1
    vkontakte._request = req

    attachment = Attachment.new(b"content", "image")

    result = asyncio.get_event_loop().run_until_complete(
        vkontakte.execute_send(1, "text", attachment, {})
    )

    assert result == 1