示例#1
0
def test_perform_api_call():
    vkontakte = Vkontakte(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.perform_api_call("method", {"arg": "val"}))

    assert result == 1
示例#2
0
def test_perform_send_string():
    vkontakte = Vkontakte(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.perform_send(1, "text", ("hey", "hoy"), {}))

    assert result == 1
示例#3
0
def test_perform_send_sticker():
    vkontakte = Vkontakte(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.perform_send(1, "text", sticker_attachment, {}))

    assert result == 1
示例#4
0
def test_perform_send_new():
    vkontakte = Vkontakte(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.perform_send(1, "text", attachment, {}))

    assert result == 1