Add Dispatcher.feed_raw_update for processing raw updates

This commit is contained in:
Alex Root Junior 2019-11-28 23:48:33 +02:00
parent 57f6d7d9a5
commit 6fadb8feb2
2 changed files with 37 additions and 4 deletions

View file

@ -1,11 +1,12 @@
import datetime
import time
import pytest
from aiogram import Bot
from aiogram.api.types import Chat, Message, Update, User
from aiogram.dispatcher.dispatcher import Dispatcher
from aiogram.dispatcher.router import Router
from asynctest import MagicMock, patch
class TestDispatcher:
@ -48,6 +49,30 @@ class TestDispatcher:
assert results_count == 1
@pytest.mark.asyncio
async def test_feed_raw_update(self):
dp = Dispatcher()
bot = Bot("42:TEST")
with patch(
"aiogram.dispatcher.dispatcher.Dispatcher.feed_update", new_callable=MagicMock
) as patched_feed_update:
patched_feed_update.__aiter__.return_value = ["test"]
async for result in dp.feed_raw_update(
bot=bot,
update={
"update_id": 42,
"message": {
"message_id": 42,
"date": int(time.time()),
"text": "test",
"chat": {"id": 42, "type": "private"},
"user": {"id": 42, "is_bot": False, "first_name": "Test"},
},
},
):
assert result == "test"
@pytest.mark.skip
@pytest.mark.asyncio
async def test_listen_updates(self):