refactor enrichment to tmdb-only and fix review findings
This commit is contained in:
@@ -20,6 +20,7 @@ class TestConfig:
|
||||
assert config.series_template == "series/{title}/Season {season:02d}/"
|
||||
assert config.log_level == "INFO"
|
||||
assert config.quarantine_dir == ".quarantine"
|
||||
assert config.enrichment_providers == ["tmdb"]
|
||||
|
||||
def test_config_creation_with_custom_values(self):
|
||||
"""Test creating Config with custom values."""
|
||||
@@ -443,6 +444,15 @@ class TestValidateConfig:
|
||||
errors = validate_config(config)
|
||||
assert any("cannot be empty" in e for e in errors)
|
||||
|
||||
def test_validate_rejects_unsupported_enrichment_provider(self):
|
||||
"""Test validating config with unsupported enrichment provider."""
|
||||
config = Config(
|
||||
library_root=Path("/test"),
|
||||
enrichment_providers=["tmdb", "douban"],
|
||||
)
|
||||
errors = validate_config(config)
|
||||
assert any("unsupported providers" in e for e in errors)
|
||||
|
||||
def test_validate_category_list_with_non_string(self):
|
||||
"""Test validating config with non-string in category list."""
|
||||
config = Config(
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
"""Unit tests for enrichment pipeline."""
|
||||
|
||||
import pytest
|
||||
|
||||
from vlm.config import Config
|
||||
from vlm.enrichment import enrich_identities_data
|
||||
from vlm.enrichment import _build_display_title, _build_providers, enrich_identities_data
|
||||
from vlm.providers.base import ProviderResult
|
||||
|
||||
|
||||
@@ -169,3 +171,96 @@ def test_enrich_refresh_all_bypasses_cache(tmp_path, monkeypatch):
|
||||
_, stats = enrich_identities_data(identities, config, refresh_mode="refresh_all")
|
||||
assert provider.calls == 2
|
||||
assert stats["cache_hits"] == 0
|
||||
|
||||
|
||||
def test_build_providers_rejects_unknown_provider(tmp_path):
|
||||
"""Unknown providers should fail fast with a clear error."""
|
||||
config = Config(
|
||||
library_root=tmp_path,
|
||||
enrichment_providers=["tmdb", "tmdb_typo"],
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="Unsupported enrichment providers"):
|
||||
_build_providers(config, request_timeout=3, retries=1)
|
||||
|
||||
|
||||
def test_refresh_all_clears_stale_enrichment_fields(tmp_path, monkeypatch):
|
||||
"""refresh_all with no new match should clear stale enrichment data."""
|
||||
|
||||
class FlakyProvider:
|
||||
name = "dummy"
|
||||
|
||||
def __init__(self):
|
||||
self.calls = 0
|
||||
|
||||
def enrich(self, *, title: str, media_type: str, year=None):
|
||||
self.calls += 1
|
||||
if self.calls == 1:
|
||||
return ProviderResult(
|
||||
provider="dummy",
|
||||
canonical_id="dummy:test",
|
||||
title_zh="测试",
|
||||
title_en="Test",
|
||||
translation_source="dummy",
|
||||
reputation_score=8.8,
|
||||
reputation_votes=120,
|
||||
reputation_source="dummy",
|
||||
)
|
||||
return None
|
||||
|
||||
config = Config(
|
||||
library_root=tmp_path,
|
||||
enrichment_cache_db=tmp_path / "cache.db",
|
||||
enrichment_providers=["dummy"],
|
||||
translation_fallback_machine=False,
|
||||
)
|
||||
|
||||
provider = FlakyProvider()
|
||||
monkeypatch.setattr(
|
||||
"vlm.enrichment._build_providers",
|
||||
lambda _config, request_timeout, retries: [provider],
|
||||
)
|
||||
|
||||
identities = {
|
||||
"metadata": {},
|
||||
"movies": [
|
||||
{
|
||||
"path": "/library/movie/Test.2020.mkv",
|
||||
"filename": "Test.2020.mkv",
|
||||
"category": "movie",
|
||||
"title": "Test",
|
||||
"year": 2020,
|
||||
"confidence": 0.9,
|
||||
"needs_review": False,
|
||||
}
|
||||
],
|
||||
"series": [],
|
||||
"anime": [],
|
||||
"other": [],
|
||||
}
|
||||
|
||||
enrich_identities_data(identities, config, refresh_mode="incremental")
|
||||
movie = identities["movies"][0]
|
||||
assert movie["canonical_id"] == "dummy:test"
|
||||
assert movie["title_zh"] == "测试"
|
||||
assert movie["title_en"] == "Test"
|
||||
|
||||
enrich_identities_data(identities, config, refresh_mode="refresh_all")
|
||||
|
||||
assert movie["canonical_id"] is None
|
||||
assert movie["title_zh"] is None
|
||||
assert movie["title_en"] is None
|
||||
assert movie["translation_source"] is None
|
||||
assert movie["reputation_score"] is None
|
||||
assert movie["reputation_votes"] is None
|
||||
assert movie["reputation_source"] is None
|
||||
assert movie["enrichment_confidence"] == 0.0
|
||||
|
||||
|
||||
def test_build_display_title_deduplicates_fallback_title(tmp_path):
|
||||
"""Fallback display title should not duplicate identical names."""
|
||||
config = Config(library_root=tmp_path)
|
||||
record = {"title": "Interstellar"}
|
||||
payload = {"title_zh": None, "title_en": None}
|
||||
|
||||
assert _build_display_title(record, payload, config) == "Interstellar"
|
||||
|
||||
Reference in New Issue
Block a user