Added detection of API Errors and fixed coverage

This commit is contained in:
Alex Root Junior 2021-08-01 00:34:50 +03:00
parent 4f2cc75951
commit c3844bb18f
17 changed files with 179 additions and 216 deletions

View file

@ -49,6 +49,10 @@ async def invalid_message_handler(message: Message):
raise Exception(42)
async def anext(ait):
return await ait.__anext__()
RAW_UPDATE = {
"update_id": 42,
"message": {
@ -147,6 +151,21 @@ class TestDispatcher:
break
assert index == 42
@pytest.mark.asyncio
async def test_listen_update_with_error(self, bot: MockedBot):
dispatcher = Dispatcher()
listen = dispatcher._listen_updates(bot=bot)
bot.add_result_for(
GetUpdates, ok=True, result=[Update(update_id=update_id) for update_id in range(42)]
)
bot.add_result_for(GetUpdates, ok=False, error_code=500, description="restarting")
with patch(
"aiogram.utils.backoff.Backoff.asleep",
new_callable=CoroutineMock,
) as mocked_asleep:
assert isinstance(await anext(listen), Update)
assert mocked_asleep.awaited
@pytest.mark.asyncio
async def test_silent_call_request(self, bot: MockedBot, caplog):
dispatcher = Dispatcher()