feat(core): standardize SeriesApp to use key as primary identifier

Task 2.1 - Update SeriesApp to Use Key for All Operations

Changes:
- Added 'key' field to DownloadStatusEventArgs and ScanStatusEventArgs
- Updated download() method docstrings to clarify key vs folder usage
- Implemented _get_serie_by_key() helper method for series lookups
- Updated all event emissions to include both key (identifier) and folder (metadata)
- Enhanced logging to show both key and folder for better debugging
- Fixed test mocks to include new key and item_id fields

Benefits:
- Consistent series identification throughout core application layer
- Clear separation between identifier (key) and metadata (folder)
- Better debugging with comprehensive log messages
- Type-safe lookups with Optional[Serie] return types
- Single source of truth for series lookups

Test Results:
- All 16 SeriesApp tests pass
- All 562 unit tests pass with no regressions
- No breaking changes to existing functionality

Follows:
- PEP 8 style guidelines (max 79 chars per line)
- PEP 257 docstring standards
- Project coding standards (type hints, error handling, logging)
This commit is contained in:
2025-11-23 19:51:26 +01:00
parent 51cd319a24
commit 8443de4e0f
3 changed files with 181 additions and 30 deletions

View File

@@ -39,20 +39,23 @@ def mock_series_app():
class MockDownloadArgs:
def __init__(
self, status, serie_folder, season, episode,
progress=None, message=None, error=None
key=None, progress=None, message=None, error=None,
item_id=None
):
self.status = status
self.serie_folder = serie_folder
self.key = key
self.season = season
self.episode = episode
self.progress = progress
self.message = message
self.error = error
self.item_id = item_id
# Trigger started event
if app.download_status:
app.download_status(MockDownloadArgs(
"started", serie_folder, season, episode
"started", serie_folder, season, episode, key=key
))
# Simulate progress updates
@@ -62,6 +65,7 @@ def mock_series_app():
await asyncio.sleep(0.01) # Small delay
app.download_status(MockDownloadArgs(
"progress", serie_folder, season, episode,
key=key,
progress=progress,
message=f"Downloading... {progress}%"
))
@@ -69,10 +73,12 @@ def mock_series_app():
# Trigger completed event
if app.download_status:
app.download_status(MockDownloadArgs(
"completed", serie_folder, season, episode
"completed", serie_folder, season, episode, key=key
))
return True
return True
app.download = Mock(side_effect=mock_download)
return app