Refactor test cases for improved readability and consistency
- Adjusted function signatures in various test files to enhance clarity by aligning parameters. - Updated patching syntax for better readability across test cases. - Improved formatting and spacing in test assertions and mock setups. - Ensured consistent use of async/await patterns in async test functions. - Enhanced comments for better understanding of test intentions.
This commit is contained in:
@@ -53,7 +53,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,
|
||||
self,
|
||||
mock_ydl_class,
|
||||
extraction_service,
|
||||
) -> None:
|
||||
"""Test service detection for YouTube."""
|
||||
mock_ydl = Mock()
|
||||
@@ -78,7 +80,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,
|
||||
self,
|
||||
mock_ydl_class,
|
||||
extraction_service,
|
||||
) -> None:
|
||||
"""Test service detection failure."""
|
||||
mock_ydl = Mock()
|
||||
@@ -170,7 +174,9 @@ class TestExtractionService:
|
||||
assert result["status"] == "pending"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_process_extraction_with_service_detection(self, extraction_service) -> None:
|
||||
async def test_process_extraction_with_service_detection(
|
||||
self, extraction_service,
|
||||
) -> None:
|
||||
"""Test extraction processing with service detection."""
|
||||
extraction_id = 1
|
||||
|
||||
@@ -202,14 +208,18 @@ class TestExtractionService:
|
||||
|
||||
with (
|
||||
patch.object(
|
||||
extraction_service, "_detect_service_info", return_value=service_info,
|
||||
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",
|
||||
extraction_service,
|
||||
"_move_files_to_final_location",
|
||||
) as mock_move,
|
||||
patch.object(
|
||||
extraction_service, "_create_sound_record",
|
||||
extraction_service,
|
||||
"_create_sound_record",
|
||||
) as mock_create_sound,
|
||||
patch.object(extraction_service, "_normalize_sound"),
|
||||
patch.object(extraction_service, "_add_to_main_playlist"),
|
||||
@@ -289,11 +299,13 @@ class TestExtractionService:
|
||||
|
||||
with (
|
||||
patch(
|
||||
"app.services.extraction.get_audio_duration", return_value=240000,
|
||||
"app.services.extraction.get_audio_duration",
|
||||
return_value=240000,
|
||||
),
|
||||
patch("app.services.extraction.get_file_size", return_value=1024),
|
||||
patch(
|
||||
"app.services.extraction.get_file_hash", return_value="test_hash",
|
||||
"app.services.extraction.get_file_hash",
|
||||
return_value="test_hash",
|
||||
),
|
||||
):
|
||||
extraction_service.sound_repo.create = AsyncMock(
|
||||
|
||||
Reference in New Issue
Block a user