Exemplo n.º 1
0
def test_execute_send_exception():
    vkontakte = VkontakteLongpoll(token="token")

    attachment = vkontakte._make_attachment(ATTACHMENTS["image"])
    attachment = attachment._replace(id=None)

    with pytest.raises(ValueError):
        asyncio.get_event_loop().run_until_complete(
            vkontakte.execute_send(1, "text", attachment, {}))
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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