Add comprehensive tests for playlist service and refactor socket service tests

- Introduced a new test suite for the PlaylistService covering various functionalities including creation, retrieval, updating, and deletion of playlists.
- Added tests for handling sounds within playlists, ensuring correct behavior when adding/removing sounds and managing current playlists.
- Refactored socket service tests for improved readability by adjusting function signatures.
- Cleaned up unnecessary whitespace in sound normalizer and sound scanner tests for consistency.
- Enhanced audio utility tests to ensure accurate hash and size calculations, including edge cases for nonexistent files.
- Removed redundant blank lines in cookie utility tests for cleaner code.
This commit is contained in:
JSC
2025-07-29 19:25:46 +02:00
parent 301b5dd794
commit 5ed19c8f0f
31 changed files with 4248 additions and 194 deletions

View File

@@ -14,6 +14,7 @@ from app.models.extraction import Extraction
from app.models.sound import Sound
from app.repositories.extraction import ExtractionRepository
from app.repositories.sound import SoundRepository
from app.services.playlist import PlaylistService
from app.services.sound_normalizer import SoundNormalizerService
from app.utils.audio import get_audio_duration, get_file_hash, get_file_size
@@ -41,6 +42,7 @@ class ExtractionService:
self.session = session
self.extraction_repo = ExtractionRepository(session)
self.sound_repo = SoundRepository(session)
self.playlist_service = PlaylistService(session)
# Ensure required directories exist
self._ensure_directories()
@@ -447,20 +449,18 @@ class ExtractionService:
async def _add_to_main_playlist(self, sound: Sound, user_id: int) -> None:
"""Add the sound to the user's main playlist."""
try:
# This is a placeholder - implement based on your playlist logic
# For now, we'll just log that we would add it to the main playlist
await self.playlist_service.add_sound_to_main_playlist(sound.id, user_id)
logger.info(
"Would add sound %d to main playlist for user %d",
"Added sound %d to main playlist for user %d",
sound.id,
user_id,
)
except Exception as e:
except Exception:
logger.exception(
"Error adding sound %d to main playlist for user %d: %s",
"Error adding sound %d to main playlist for user %d",
sound.id,
user_id,
e,
)
# Don't fail the extraction if playlist addition fails