Task 4.5: Update Pydantic models to use key as primary identifier
- Updated AnimeSeriesResponse and SearchResult models in anime.py: - Changed 'id' field to 'key' as the primary series identifier - Added 'folder' as optional metadata field - Added field validator to normalize key to lowercase and strip whitespace - Added comprehensive docstrings explaining identifier usage - Updated DownloadItem and DownloadRequest models in download.py: - Added field validator for serie_id normalization (lowercase, stripped) - Improved documentation for serie_id (primary identifier) vs serie_folder (metadata) - Updated test_anime_models.py with comprehensive tests: - Tests for key normalization and whitespace stripping - Tests for folder as optional metadata - Reorganized tests into proper class structure - Updated test_download_models.py with validator tests: - Tests for serie_id normalization in DownloadItem - Tests for serie_id normalization in DownloadRequest All 885 tests pass.
This commit is contained in:
@@ -126,6 +126,14 @@ class DownloadItem(BaseModel):
|
||||
None, description="Source URL for download"
|
||||
)
|
||||
|
||||
@field_validator('serie_id', mode='before')
|
||||
@classmethod
|
||||
def normalize_serie_id(cls, v: str) -> str:
|
||||
"""Normalize serie_id (key) to lowercase and stripped."""
|
||||
if isinstance(v, str):
|
||||
return v.lower().strip()
|
||||
return v
|
||||
|
||||
|
||||
class QueueStatus(BaseModel):
|
||||
"""Overall status of the download queue system."""
|
||||
@@ -218,6 +226,14 @@ class DownloadRequest(BaseModel):
|
||||
return v.upper()
|
||||
return v
|
||||
|
||||
@field_validator('serie_id', mode='before')
|
||||
@classmethod
|
||||
def normalize_serie_id(cls, v: str) -> str:
|
||||
"""Normalize serie_id (key) to lowercase and stripped."""
|
||||
if isinstance(v, str):
|
||||
return v.lower().strip()
|
||||
return v
|
||||
|
||||
|
||||
class DownloadResponse(BaseModel):
|
||||
"""Response after adding items to the download queue."""
|
||||
|
||||
Reference in New Issue
Block a user