Add comprehensive tests for scheduled task repository, scheduler service, and task handlers
- Implemented tests for ScheduledTaskRepository covering task creation, retrieval, filtering, and status updates. - Developed tests for SchedulerService including task creation, cancellation, user task retrieval, and maintenance jobs. - Created tests for TaskHandlerRegistry to validate task execution for various types, including credit recharge and sound playback. - Ensured proper error handling and edge cases in task execution scenarios. - Added fixtures and mocks to facilitate isolated testing of services and repositories.
This commit is contained in:
31
test_task.py
Normal file
31
test_task.py
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Create a test task for scheduler testing."""
|
||||
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
|
||||
from app.core.database import get_session_factory
|
||||
from app.repositories.scheduled_task import ScheduledTaskRepository
|
||||
from app.models.scheduled_task import TaskType, RecurrenceType
|
||||
|
||||
async def create_test_task():
|
||||
session_factory = get_session_factory()
|
||||
|
||||
async with session_factory() as session:
|
||||
repo = ScheduledTaskRepository(session)
|
||||
|
||||
task_data = {
|
||||
"name": "Live Test Task",
|
||||
"task_type": TaskType.PLAY_SOUND,
|
||||
"scheduled_at": datetime(2025, 8, 28, 15, 21, 0), # 15:21:00 UTC
|
||||
"timezone": "UTC",
|
||||
"parameters": {"sound_id": 1},
|
||||
"user_id": 1,
|
||||
"recurrence_type": RecurrenceType.NONE,
|
||||
}
|
||||
|
||||
task = await repo.create(task_data)
|
||||
print(f"Created task: {task.name} (ID: {task.id}) scheduled for {task.scheduled_at}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(create_test_task())
|
||||
Reference in New Issue
Block a user