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:
@@ -25,6 +25,7 @@ from app.models.favorite import Favorite # noqa: F401
|
||||
from app.models.plan import Plan
|
||||
from app.models.playlist import Playlist # noqa: F401
|
||||
from app.models.playlist_sound import PlaylistSound # noqa: F401
|
||||
from app.models.scheduled_task import ScheduledTask # noqa: F401
|
||||
from app.models.sound import Sound # noqa: F401
|
||||
from app.models.sound_played import SoundPlayed # noqa: F401
|
||||
from app.models.user import User
|
||||
@@ -346,3 +347,29 @@ async def admin_cookies(admin_user: User) -> dict[str, str]:
|
||||
access_token = JWTUtils.create_access_token(token_data)
|
||||
|
||||
return {"access_token": access_token}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_user_id(test_user: User):
|
||||
"""Get test user ID."""
|
||||
return test_user.id
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_sound_id():
|
||||
"""Create a test sound ID."""
|
||||
import uuid
|
||||
return uuid.uuid4()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_playlist_id():
|
||||
"""Create a test playlist ID."""
|
||||
import uuid
|
||||
return uuid.uuid4()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def db_session(test_session: AsyncSession) -> AsyncSession:
|
||||
"""Alias for test_session to match test expectations."""
|
||||
return test_session
|
||||
|
||||
Reference in New Issue
Block a user