From dba3388567818cb5c60be9d406d3e1cccc84b3ea Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 29 Apr 2026 14:22:03 +0200 Subject: Refactor database connections and add integration tests - Use context managers for sqlite3 connections in cron, vclogs, and database utils - Add URL helper utility for yt-dlp with clean_url_for_ytdlp function - Add slow integration test markers and new integration test files - Fix test imports to use conftest directly instead of tests.conftest - Improve downloader error handling and use COPYPARTY_URL_UPLOAD env var - Update pytest.ini with slow test markers and warning filters - Document slow test usage in AGENTS.md --- tests/cogs/test_cron_integration.py | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/cogs/test_cron_integration.py (limited to 'tests/cogs/test_cron_integration.py') 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 @@ +import pytest +import time +from unittest.mock import MagicMock, AsyncMock, patch + + +@pytest.fixture +def cron_cog(bot): + # Patch create_task to prevent background task creation + with patch.object(bot.loop, 'create_task', return_value=MagicMock()): + from cogs.cron import Cron + cog = Cron(bot) + yield cog + + +@pytest.mark.slow +@pytest.mark.asyncio +async def test_cron_job_execution(cron_cog): + """Test cron job executes when due.""" + cog = cron_cog + + job = { + "id": "test_job", + "cron_expression": "* * * * *", + "type": "message", + "channel_id": 456, + "active": True, + "message": "Test", + } + cog.scheduled_tasks.append(job) + + # Mock the execute_task method + with patch.object(cog, 'execute_task', new_callable=AsyncMock) as mock_exec: + # Mock should_run_task to return True + with patch.object(cog, 'should_run_task', return_value=True): + # Test single iteration of schedule_checker logic + for task in cog.scheduled_tasks: + if task.get("active", True) and cog.should_run_task(task, None): + await cog.execute_task(task) + mock_exec.assert_called_once_with(job) \ No newline at end of file -- cgit v1.2.3