Fix test "test_dispatcher.test_dispatcher.TestDispatcher::test_feed_raw_update"

This commit is contained in:
Alex Root Junior 2019-12-09 21:39:06 +02:00
parent 2d6fc85dc0
commit 38c725db46

View file

@ -2,7 +2,6 @@ import datetime
import time import time
import pytest import pytest
from asynctest import MagicMock, patch
from aiogram import Bot from aiogram import Bot
from aiogram.api.types import Chat, Message, Update, User from aiogram.api.types import Chat, Message, Update, User
@ -55,24 +54,28 @@ class TestDispatcher:
dp = Dispatcher() dp = Dispatcher()
bot = Bot("42:TEST") bot = Bot("42:TEST")
with patch( @dp.message_handler()
"aiogram.dispatcher.dispatcher.Dispatcher.feed_update", new_callable=MagicMock async def my_handler(message: Message):
) as patched_feed_update: assert message.text == "test"
patched_feed_update.__aiter__.return_value = ["test"] return message.text
async for result in dp.feed_raw_update(
bot=bot, handled = False
update={ async for result in dp.feed_raw_update(
"update_id": 42, bot=bot,
"message": { update={
"message_id": 42, "update_id": 42,
"date": int(time.time()), "message": {
"text": "test", "message_id": 42,
"chat": {"id": 42, "type": "private"}, "date": int(time.time()),
"user": {"id": 42, "is_bot": False, "first_name": "Test"}, "text": "test",
}, "chat": {"id": 42, "type": "private"},
"user": {"id": 42, "is_bot": False, "first_name": "Test"},
}, },
): },
assert result == "test" ):
handled = True
assert result == "test"
assert handled
@pytest.mark.skip @pytest.mark.skip
@pytest.mark.asyncio @pytest.mark.asyncio