33 lines
961 B
Python
33 lines
961 B
Python
import asyncio
|
|
import unittest
|
|
from types import SimpleNamespace
|
|
from unittest.mock import patch
|
|
|
|
from assistant_bot.jobs import post_init, post_shutdown
|
|
|
|
|
|
class ReminderJobLifecycleTests(unittest.IsolatedAsyncioTestCase):
|
|
async def test_reminder_task_is_cancelled_on_shutdown(self) -> None:
|
|
started = asyncio.Event()
|
|
|
|
async def fake_reminder_loop(application) -> None:
|
|
started.set()
|
|
await asyncio.Event().wait()
|
|
|
|
application = SimpleNamespace(bot_data={})
|
|
with patch("assistant_bot.jobs.reminder_loop", fake_reminder_loop):
|
|
await post_init(application)
|
|
await started.wait()
|
|
|
|
task = application.bot_data["reminder_task"]
|
|
self.assertFalse(task.done())
|
|
|
|
await post_shutdown(application)
|
|
|
|
self.assertTrue(task.cancelled())
|
|
self.assertNotIn("reminder_task", application.bot_data)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|