Refactor test files for improved readability and consistency
- Removed unnecessary blank lines and adjusted formatting in test files. - Ensured consistent use of commas in function calls and assertions across various test cases. - Updated import statements for better organization and clarity. - Enhanced mock setups in tests for better isolation and reliability. - Improved assertions to follow a consistent style for better readability.
This commit is contained in:
@@ -53,7 +53,7 @@ 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,
|
||||
):
|
||||
"""Test service detection for YouTube."""
|
||||
mock_ydl = Mock()
|
||||
@@ -67,7 +67,7 @@ class TestExtractionService:
|
||||
}
|
||||
|
||||
result = await extraction_service._detect_service_info(
|
||||
"https://www.youtube.com/watch?v=test123"
|
||||
"https://www.youtube.com/watch?v=test123",
|
||||
)
|
||||
|
||||
assert result is not None
|
||||
@@ -78,7 +78,7 @@ 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,
|
||||
):
|
||||
"""Test service detection failure."""
|
||||
mock_ydl = Mock()
|
||||
@@ -106,7 +106,7 @@ class TestExtractionService:
|
||||
status="pending",
|
||||
)
|
||||
extraction_service.extraction_repo.create = AsyncMock(
|
||||
return_value=mock_extraction
|
||||
return_value=mock_extraction,
|
||||
)
|
||||
|
||||
result = await extraction_service.create_extraction(url, user_id)
|
||||
@@ -134,7 +134,7 @@ class TestExtractionService:
|
||||
status="pending",
|
||||
)
|
||||
extraction_service.extraction_repo.create = AsyncMock(
|
||||
return_value=mock_extraction
|
||||
return_value=mock_extraction,
|
||||
)
|
||||
|
||||
result = await extraction_service.create_extraction(url, user_id)
|
||||
@@ -160,7 +160,7 @@ class TestExtractionService:
|
||||
status="pending",
|
||||
)
|
||||
extraction_service.extraction_repo.create = AsyncMock(
|
||||
return_value=mock_extraction
|
||||
return_value=mock_extraction,
|
||||
)
|
||||
|
||||
result = await extraction_service.create_extraction(url, user_id)
|
||||
@@ -186,11 +186,11 @@ class TestExtractionService:
|
||||
)
|
||||
|
||||
extraction_service.extraction_repo.get_by_id = AsyncMock(
|
||||
return_value=mock_extraction
|
||||
return_value=mock_extraction,
|
||||
)
|
||||
extraction_service.extraction_repo.update = AsyncMock()
|
||||
extraction_service.extraction_repo.get_by_service_and_id = AsyncMock(
|
||||
return_value=None
|
||||
return_value=None,
|
||||
)
|
||||
|
||||
# Mock service detection
|
||||
@@ -202,14 +202,14 @@ 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") as mock_normalize,
|
||||
patch.object(extraction_service, "_add_to_main_playlist") as mock_playlist,
|
||||
@@ -223,7 +223,7 @@ class TestExtractionService:
|
||||
|
||||
# Verify service detection was called
|
||||
extraction_service._detect_service_info.assert_called_once_with(
|
||||
"https://www.youtube.com/watch?v=test123"
|
||||
"https://www.youtube.com/watch?v=test123",
|
||||
)
|
||||
|
||||
# Verify extraction was updated with service info
|
||||
@@ -289,15 +289,15 @@ 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(
|
||||
return_value=mock_sound
|
||||
return_value=mock_sound,
|
||||
)
|
||||
|
||||
result = await extraction_service._create_sound_record(
|
||||
@@ -336,7 +336,7 @@ class TestExtractionService:
|
||||
|
||||
mock_normalizer = Mock()
|
||||
mock_normalizer.normalize_sound = AsyncMock(
|
||||
return_value={"status": "normalized"}
|
||||
return_value={"status": "normalized"},
|
||||
)
|
||||
|
||||
with patch(
|
||||
@@ -368,7 +368,7 @@ class TestExtractionService:
|
||||
|
||||
mock_normalizer = Mock()
|
||||
mock_normalizer.normalize_sound = AsyncMock(
|
||||
return_value={"status": "error", "error": "Test error"}
|
||||
return_value={"status": "error", "error": "Test error"},
|
||||
)
|
||||
|
||||
with patch(
|
||||
@@ -395,7 +395,7 @@ class TestExtractionService:
|
||||
)
|
||||
|
||||
extraction_service.extraction_repo.get_by_id = AsyncMock(
|
||||
return_value=extraction
|
||||
return_value=extraction,
|
||||
)
|
||||
|
||||
result = await extraction_service.get_extraction_by_id(1)
|
||||
@@ -443,7 +443,7 @@ class TestExtractionService:
|
||||
]
|
||||
|
||||
extraction_service.extraction_repo.get_by_user = AsyncMock(
|
||||
return_value=extractions
|
||||
return_value=extractions,
|
||||
)
|
||||
|
||||
result = await extraction_service.get_user_extractions(1)
|
||||
@@ -470,7 +470,7 @@ class TestExtractionService:
|
||||
]
|
||||
|
||||
extraction_service.extraction_repo.get_pending_extractions = AsyncMock(
|
||||
return_value=pending_extractions
|
||||
return_value=pending_extractions,
|
||||
)
|
||||
|
||||
result = await extraction_service.get_pending_extractions()
|
||||
|
||||
Reference in New Issue
Block a user