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:
@@ -52,7 +52,9 @@ class TestExtractionService:
|
||||
|
||||
@patch("app.services.extraction.yt_dlp.YoutubeDL")
|
||||
@pytest.mark.asyncio
|
||||
async def test_detect_service_info_youtube(self, mock_ydl_class, extraction_service):
|
||||
async def test_detect_service_info_youtube(
|
||||
self, mock_ydl_class, extraction_service
|
||||
):
|
||||
"""Test service detection for YouTube."""
|
||||
mock_ydl = Mock()
|
||||
mock_ydl_class.return_value.__enter__.return_value = mock_ydl
|
||||
@@ -75,7 +77,9 @@ class TestExtractionService:
|
||||
|
||||
@patch("app.services.extraction.yt_dlp.YoutubeDL")
|
||||
@pytest.mark.asyncio
|
||||
async def test_detect_service_info_failure(self, mock_ydl_class, extraction_service):
|
||||
async def test_detect_service_info_failure(
|
||||
self, mock_ydl_class, extraction_service
|
||||
):
|
||||
"""Test service detection failure."""
|
||||
mock_ydl = Mock()
|
||||
mock_ydl_class.return_value.__enter__.return_value = mock_ydl
|
||||
@@ -169,7 +173,7 @@ class TestExtractionService:
|
||||
async def test_process_extraction_with_service_detection(self, extraction_service):
|
||||
"""Test extraction processing with service detection."""
|
||||
extraction_id = 1
|
||||
|
||||
|
||||
# Mock extraction without service info
|
||||
mock_extraction = Extraction(
|
||||
id=extraction_id,
|
||||
@@ -180,7 +184,7 @@ class TestExtractionService:
|
||||
title=None,
|
||||
status="pending",
|
||||
)
|
||||
|
||||
|
||||
extraction_service.extraction_repo.get_by_id = AsyncMock(
|
||||
return_value=mock_extraction
|
||||
)
|
||||
@@ -188,21 +192,25 @@ class TestExtractionService:
|
||||
extraction_service.extraction_repo.get_by_service_and_id = AsyncMock(
|
||||
return_value=None
|
||||
)
|
||||
|
||||
|
||||
# Mock service detection
|
||||
service_info = {
|
||||
"service": "youtube",
|
||||
"service_id": "test123",
|
||||
"service_id": "test123",
|
||||
"title": "Test Video",
|
||||
}
|
||||
|
||||
|
||||
with (
|
||||
patch.object(
|
||||
extraction_service, "_detect_service_info", return_value=service_info
|
||||
),
|
||||
patch.object(extraction_service, "_extract_media") as mock_extract,
|
||||
patch.object(extraction_service, "_move_files_to_final_location") as mock_move,
|
||||
patch.object(extraction_service, "_create_sound_record") as mock_create_sound,
|
||||
patch.object(
|
||||
extraction_service, "_move_files_to_final_location"
|
||||
) as mock_move,
|
||||
patch.object(
|
||||
extraction_service, "_create_sound_record"
|
||||
) as mock_create_sound,
|
||||
patch.object(extraction_service, "_normalize_sound") as mock_normalize,
|
||||
patch.object(extraction_service, "_add_to_main_playlist") as mock_playlist,
|
||||
):
|
||||
@@ -210,17 +218,17 @@ class TestExtractionService:
|
||||
mock_extract.return_value = (Path("/fake/audio.mp3"), None)
|
||||
mock_move.return_value = (Path("/final/audio.mp3"), None)
|
||||
mock_create_sound.return_value = mock_sound
|
||||
|
||||
|
||||
result = await extraction_service.process_extraction(extraction_id)
|
||||
|
||||
|
||||
# Verify service detection was called
|
||||
extraction_service._detect_service_info.assert_called_once_with(
|
||||
"https://www.youtube.com/watch?v=test123"
|
||||
)
|
||||
|
||||
|
||||
# Verify extraction was updated with service info
|
||||
extraction_service.extraction_repo.update.assert_called()
|
||||
|
||||
|
||||
assert result["status"] == "completed"
|
||||
assert result["service"] == "youtube"
|
||||
assert result["service_id"] == "test123"
|
||||
@@ -288,7 +296,6 @@ class TestExtractionService:
|
||||
"app.services.extraction.get_file_hash", return_value="test_hash"
|
||||
),
|
||||
):
|
||||
|
||||
extraction_service.sound_repo.create = AsyncMock(
|
||||
return_value=mock_sound
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user