diff options
| author | salmonik <raisersoft@proton.me> | 2026-04-29 14:47:32 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-04-29 14:47:32 +0200 |
| commit | 8a4352ebb5e15ff4be82a9b4e111c1535aab349e (patch) | |
| tree | 2c4d5b4b65bdc8308b35c411cffa7f17b1bfeb4d /tests/cogs/test_cron_integration.py | |
| parent | fix: fallback to plaintext if no json is provided for assistant.py (diff) | |
| parent | proper context for settings (diff) | |
| download | senator-sperma-8a4352ebb5e15ff4be82a9b4e111c1535aab349e.tar.gz senator-sperma-8a4352ebb5e15ff4be82a9b4e111c1535aab349e.zip | |
Merge branch 'dev'
Signed-off-by: salmonik <raisersoft@proton.me>
Diffstat (limited to 'tests/cogs/test_cron_integration.py')
| -rw-r--r-- | tests/cogs/test_cron_integration.py | 39 |
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 @@ | |||
| 1 | import pytest | ||
| 2 | import time | ||
| 3 | from unittest.mock import MagicMock, AsyncMock, patch | ||
| 4 | |||
| 5 | |||
| 6 | @pytest.fixture | ||
| 7 | def 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 | ||
| 17 | async 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 | ||
