Partially cover dispatcher

This commit is contained in:
jrootjunior 2019-11-26 11:41:23 +02:00
parent fa42dcdce2
commit 55496ab9ca
2 changed files with 61 additions and 2 deletions

View file

@ -37,11 +37,11 @@ class Dispatcher(Router):
update_id = update.update_id + 1
async def polling(self, bot: Bot):
self.emit_startup(bot=bot)
await self.emit_startup(bot=bot)
try:
async for update in self.listen_updates(bot):
async for result in self.feed_update(bot, update):
if isinstance(result, TelegramMethod):
await result
finally:
self.emit_shutdown(bot=bot)
await self.emit_shutdown(bot=bot)

View file

@ -0,0 +1,59 @@
import datetime
import pytest
from aiogram import Bot
from aiogram.api.types import Message, Update, Chat, User
from aiogram.dispatcher.dispatcher import Dispatcher
from aiogram.dispatcher.router import Router
class TestDispatcher:
def test_parent_router(self):
dp = Dispatcher()
with pytest.raises(RuntimeError):
dp.parent_router = Router()
assert dp.parent_router is None
dp._parent_router = Router()
assert dp.parent_router is None
@pytest.mark.asyncio
async def test_feed_update(self):
dp = Dispatcher()
bot = Bot("TOKEN")
@dp.message_handler()
async def my_handler(message: Message, **kwargs):
assert "bot" in kwargs
assert isinstance(kwargs["bot"], Bot)
assert kwargs["bot"] == bot
return message.text
results_count = 0
async for result in dp.feed_update(
bot=bot,
update=Update(
update_id=42,
message=Message(
message_id=42,
date=datetime.datetime.now(),
text="test",
chat=Chat(id=42, type="private"),
from_user=User(id=42, is_bot=False, first_name="Test"),
),
),
):
results_count += 1
assert result == "test"
assert results_count == 1
@pytest.mark.skip
@pytest.mark.asyncio
async def test_listen_updates(self):
pass
@pytest.mark.skip
@pytest.mark.asyncio
async def test_polling(self):
pass