aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cogs/test_cron_integration.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cogs/test_cron_integration.py')
-rw-r--r--tests/cogs/test_cron_integration.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/cogs/test_cron_integration.py b/tests/cogs/test_cron_integration.py
new file mode 100644
index 0000000..f56fc46
--- /dev/null
+++ b/tests/cogs/test_cron_integration.py
@@ -0,0 +1,39 @@
1import pytest
2import time
3from unittest.mock import MagicMock, AsyncMock, patch
4
5
6@pytest.fixture
7def cron_cog(bot):
8 # Patch create_task to prevent background task creation
9 with patch.object(bot.loop, 'create_task', return_value=MagicMock()):
10 from cogs.cron import Cron
11 cog = Cron(bot)
12 yield cog
13
14
15@pytest.mark.slow
16@pytest.mark.asyncio
17async def test_cron_job_execution(cron_cog):
18 """Test cron job executes when due."""
19 cog = cron_cog
20
21 job = {
22 "id": "test_job",
23 "cron_expression": "* * * * *",
24 "type": "message",
25 "channel_id": 456,
26 "active": True,
27 "message": "Test",
28 }
29 cog.scheduled_tasks.append(job)
30
31 # Mock the execute_task method
32 with patch.object(cog, 'execute_task', new_callable=AsyncMock) as mock_exec:
33 # Mock should_run_task to return True
34 with patch.object(cog, 'should_run_task', return_value=True):
35 # Test single iteration of schedule_checker logic
36 for task in cog.scheduled_tasks:
37 if task.get("active", True) and cog.should_run_task(task, None):
38 await cog.execute_task(task)
39 mock_exec.assert_called_once_with(job) \ No newline at end of file