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:
@@ -10,7 +10,6 @@ from sqlmodel.ext.asyncio.session import AsyncSession
|
||||
|
||||
from app.core.config import settings
|
||||
from app.core.logging import get_logger
|
||||
from app.models.extraction import Extraction
|
||||
from app.models.sound import Sound
|
||||
from app.repositories.extraction import ExtractionRepository
|
||||
from app.repositories.sound import SoundRepository
|
||||
@@ -155,7 +154,7 @@ class ExtractionService:
|
||||
|
||||
# Check if extraction already exists for this service
|
||||
existing = await self.extraction_repo.get_by_service_and_id(
|
||||
service_info["service"], service_info["service_id"]
|
||||
service_info["service"], service_info["service_id"],
|
||||
)
|
||||
if existing and existing.id != extraction_id:
|
||||
error_msg = (
|
||||
@@ -180,7 +179,7 @@ class ExtractionService:
|
||||
|
||||
# Extract audio and thumbnail
|
||||
audio_file, thumbnail_file = await self._extract_media(
|
||||
extraction_id, extraction_url
|
||||
extraction_id, extraction_url,
|
||||
)
|
||||
|
||||
# Move files to final locations
|
||||
@@ -238,7 +237,7 @@ class ExtractionService:
|
||||
except Exception as e:
|
||||
error_msg = str(e)
|
||||
logger.exception(
|
||||
"Failed to process extraction %d: %s", extraction_id, error_msg
|
||||
"Failed to process extraction %d: %s", extraction_id, error_msg,
|
||||
)
|
||||
|
||||
# Update extraction with error
|
||||
@@ -262,14 +261,14 @@ class ExtractionService:
|
||||
}
|
||||
|
||||
async def _extract_media(
|
||||
self, extraction_id: int, extraction_url: str
|
||||
self, extraction_id: int, extraction_url: str,
|
||||
) -> tuple[Path, Path | None]:
|
||||
"""Extract audio and thumbnail using yt-dlp."""
|
||||
temp_dir = Path(settings.EXTRACTION_TEMP_DIR)
|
||||
|
||||
# Create unique filename based on extraction ID
|
||||
output_template = str(
|
||||
temp_dir / f"extraction_{extraction_id}_%(title)s.%(ext)s"
|
||||
temp_dir / f"extraction_{extraction_id}_%(title)s.%(ext)s",
|
||||
)
|
||||
|
||||
# Configure yt-dlp options
|
||||
@@ -304,8 +303,8 @@ class ExtractionService:
|
||||
# Find the extracted files
|
||||
audio_files = list(
|
||||
temp_dir.glob(
|
||||
f"extraction_{extraction_id}_*.{settings.EXTRACTION_AUDIO_FORMAT}"
|
||||
)
|
||||
f"extraction_{extraction_id}_*.{settings.EXTRACTION_AUDIO_FORMAT}",
|
||||
),
|
||||
)
|
||||
thumbnail_files = (
|
||||
list(temp_dir.glob(f"extraction_{extraction_id}_*.webp"))
|
||||
@@ -342,7 +341,7 @@ class ExtractionService:
|
||||
"""Move extracted files to their final locations."""
|
||||
# Generate clean filename based on title and service
|
||||
safe_title = self._sanitize_filename(
|
||||
title or f"{service or 'unknown'}_{service_id or 'unknown'}"
|
||||
title or f"{service or 'unknown'}_{service_id or 'unknown'}",
|
||||
)
|
||||
|
||||
# Move audio file
|
||||
|
||||
Reference in New Issue
Block a user