From dcbf9b27604771bc71c53a5bfa595f2b5deb6471 Mon Sep 17 00:00:00 2001 From: jrootjunior Date: Wed, 11 Dec 2019 15:39:50 +0200 Subject: [PATCH] Mock Dispatcher._polling --- tests/test_dispatcher/test_dispatcher.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/test_dispatcher/test_dispatcher.py b/tests/test_dispatcher/test_dispatcher.py index bc032d35..96360ec6 100644 --- a/tests/test_dispatcher/test_dispatcher.py +++ b/tests/test_dispatcher/test_dispatcher.py @@ -1,3 +1,4 @@ +import asyncio import datetime import time @@ -147,10 +148,21 @@ class TestDispatcher: assert len(log_records) == 1 assert "Cause exception while process update" in log_records[0] - @pytest.mark.skip @pytest.mark.asyncio - async def test_polling(self): - pass + async def test_polling(self, bot: MockedBot): + dispatcher = Dispatcher() + + async def _mock_updates(*_): + yield Update(update_id=42) + + with patch( + "aiogram.dispatcher.dispatcher.Dispatcher.process_update", new_callable=CoroutineMock + ) as mocked_process_update, patch( + "aiogram.dispatcher.dispatcher.Dispatcher._listen_updates" + ) as patched_listen_updates: + patched_listen_updates.return_value = _mock_updates() + await dispatcher._polling(bot=bot) + mocked_process_update.assert_awaited() @pytest.mark.skip @pytest.mark.asyncio