chore: sprint cleanup — language unification, parser unification, fossils removal
Several weeks of work accumulated without being committed. Grouped here for clarity; see CHANGELOG.md [Unreleased] for the user-facing summary. Highlights ---------- P1 #2 — ISO 639-2/B canonical migration - New Language VO + LanguageRegistry (alfred/domain/shared/knowledge/). - iso_languages.yaml as single source of truth for language codes. - SubtitleKnowledgeBase now delegates lookup to LanguageRegistry; subtitles.yaml only declares subtitle-specific tokens (vostfr, vf, vff, …). - SubtitlePreferences default → ["fre", "eng"]; subtitle filenames written as {iso639_2b}.srt (legacy fr.srt still read via alias). - Scanner: dropped _LANG_KEYWORDS / _SDH_TOKENS / _FORCED_TOKENS / SUBTITLE_EXTENSIONS hardcoded dicts. - Fixed: 'hi' token no longer marks SDH (conflicted with Hindi alias). - Added settings.min_movie_size_bytes (was a module constant). P1 #3 — Release parser unification + data-driven tokenizer - parse_release() is now the single source of truth for release-name parsing. - alfred/knowledge/release/separators.yaml declares the token separators used by the tokenizer (., space, [, ], (, ), _). New conventions can be added without code changes. - Tokenizer now splits on any configured separator instead of name.split('.'). Releases like 'The Father (2020) [1080p] [WEBRip] [5.1] [YTS.MX]' parse via the direct path without sanitization fallback. - Site-tag extraction always runs first; well-formedness only rejects truly forbidden chars. - _parse_season_episode() extended with NxNN / NxNNxNN alt forms. - Removed dead helpers: _sanitize, _normalize. Domain cleanup - Deleted fossil services with zero production callers: alfred/domain/movies/services.py alfred/domain/tv_shows/services.py alfred/domain/subtitles/services.py (replaced by subtitles/services/ package) alfred/domain/subtitles/repositories.py - Split monolithic subtitle services into a package (identifier, matcher, placer, pattern_detector, utils) + dedicated knowledge/ package. - MediaInfo split into dedicated package (alfred/domain/shared/media/: audio, video, subtitle, info, matching). Persistence cleanup - Removed dead JSON repositories (movie/subtitle/tvshow_repository.py). Tests - Major expansion of the test suite organized to mirror the source tree. - Removed obsolete *_edge_cases test files superseded by structured tests. - Suite: 990 passed, 8 skipped. Misc - .gitignore: exclude env_backup/ and *.bak. - Adjustments across agent/llm, app.py, application/filesystem, and infrastructure/filesystem to align with the new domain layout.
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
"""Tests for ``alfred.application.movies.search_movie.SearchMovieUseCase``.
|
||||
|
||||
The use case wraps ``TMDBClient.search_media`` and converts results / errors
|
||||
into a ``SearchMovieResponse`` envelope (status="ok"|"error").
|
||||
|
||||
Coverage:
|
||||
|
||||
- ``TestSuccess`` — full MediaResult with imdb_id → ok+imdb_id; missing
|
||||
imdb_id → ok+no_imdb_id; TV media_type preserved.
|
||||
- ``TestErrorTranslation`` — ``TMDBNotFoundError`` → not_found,
|
||||
``TMDBConfigurationError`` → configuration_error,
|
||||
``TMDBAPIError`` → api_error, ``ValueError`` → validation_failed.
|
||||
- ``TestPassThrough`` — query is forwarded to the client unchanged.
|
||||
|
||||
TMDBClient is fully mocked — no real HTTP.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from alfred.application.movies.search_movie import SearchMovieUseCase
|
||||
from alfred.infrastructure.api.tmdb.dto import MediaResult
|
||||
from alfred.infrastructure.api.tmdb.exceptions import (
|
||||
TMDBAPIError,
|
||||
TMDBConfigurationError,
|
||||
TMDBNotFoundError,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
return MagicMock()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def use_case(client):
|
||||
return SearchMovieUseCase(client)
|
||||
|
||||
|
||||
def _result(**kw) -> MediaResult:
|
||||
defaults = dict(
|
||||
tmdb_id=1,
|
||||
title="Inception",
|
||||
media_type="movie",
|
||||
imdb_id="tt1375666",
|
||||
overview="o",
|
||||
release_date="2010-07-15",
|
||||
poster_path="/x.jpg",
|
||||
vote_average=8.4,
|
||||
)
|
||||
defaults.update(kw)
|
||||
return MediaResult(**defaults)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Success paths #
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
class TestSuccess:
|
||||
def test_full_result_returns_ok_with_imdb_id(self, client, use_case):
|
||||
client.search_media.return_value = _result()
|
||||
r = use_case.execute("Inception")
|
||||
assert r.status == "ok"
|
||||
assert r.imdb_id == "tt1375666"
|
||||
assert r.title == "Inception"
|
||||
assert r.media_type == "movie"
|
||||
assert r.tmdb_id == 1
|
||||
assert r.vote_average == 8.4
|
||||
assert r.error is None
|
||||
|
||||
def test_tv_result(self, client, use_case):
|
||||
client.search_media.return_value = _result(
|
||||
media_type="tv", title="Breaking Bad", imdb_id="tt0903747"
|
||||
)
|
||||
r = use_case.execute("Breaking Bad")
|
||||
assert r.status == "ok"
|
||||
assert r.media_type == "tv"
|
||||
assert r.imdb_id == "tt0903747"
|
||||
|
||||
def test_missing_imdb_id_returns_ok_with_no_imdb_id_error(self, client, use_case):
|
||||
client.search_media.return_value = _result(imdb_id=None)
|
||||
r = use_case.execute("Inception")
|
||||
assert r.status == "ok"
|
||||
assert r.error == "no_imdb_id"
|
||||
assert r.message is not None
|
||||
assert "Inception" in r.message
|
||||
assert r.imdb_id is None
|
||||
assert r.title == "Inception"
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Error translation #
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
class TestErrorTranslation:
|
||||
def test_not_found(self, client, use_case):
|
||||
client.search_media.side_effect = TMDBNotFoundError("no match")
|
||||
r = use_case.execute("ghost")
|
||||
assert r.status == "error"
|
||||
assert r.error == "not_found"
|
||||
assert "no match" in r.message
|
||||
|
||||
def test_configuration_error(self, client, use_case):
|
||||
client.search_media.side_effect = TMDBConfigurationError("missing key")
|
||||
r = use_case.execute("x")
|
||||
assert r.status == "error"
|
||||
assert r.error == "configuration_error"
|
||||
|
||||
def test_api_error(self, client, use_case):
|
||||
client.search_media.side_effect = TMDBAPIError("500 oops")
|
||||
r = use_case.execute("x")
|
||||
assert r.status == "error"
|
||||
assert r.error == "api_error"
|
||||
assert "500" in r.message
|
||||
|
||||
def test_validation_error(self, client, use_case):
|
||||
client.search_media.side_effect = ValueError("query too long")
|
||||
r = use_case.execute("x")
|
||||
assert r.status == "error"
|
||||
assert r.error == "validation_failed"
|
||||
assert "too long" in r.message
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Pass-through #
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
class TestPassThrough:
|
||||
def test_query_forwarded_verbatim(self, client, use_case):
|
||||
client.search_media.return_value = _result()
|
||||
use_case.execute("Inception")
|
||||
client.search_media.assert_called_once_with("Inception")
|
||||
Reference in New Issue
Block a user