Add edit dialogs, library organizer, and TMDb pool migration

This commit is contained in:
2026-09-08 07:37:40 +02:00
parent 39712d7283
commit 79c9e34a5d
10 changed files with 1371 additions and 110 deletions
+95
View File
@@ -0,0 +1,95 @@
"""Tests for pool → TMDb migration (src.core.migrate + FileManager)."""
import pytest
from src.core.migrate import classify, normalize
from src.core.tmdb import TmdbResult
def test_normalize_folds_diacritics_and_punct():
assert normalize("Šíleně smutná princezna!") == "silene smutna princezna"
assert normalize("Amélie z Montmartru") == "amelie z montmartru"
def test_classify_auto_on_exact_unique():
cands = [TmdbResult(603, "Matrix", "1999", "movie")]
status, chosen = classify("Matrix", "1999", cands)
assert status == "auto" and chosen.tmdb_id == 603
def test_classify_auto_disambiguates_by_year():
cands = [
TmdbResult(1, "Solaris", "1972", "movie"),
TmdbResult(2, "Solaris", "2002", "movie"),
]
# local year 1972 → unique exact-year match → auto picks the 1972 one
assert classify("Solaris", "1972", cands) == ("auto", cands[0])
def test_classify_ambiguous_when_year_matches_none():
cands = [
TmdbResult(1, "Solaris", "1972", "movie"),
TmdbResult(2, "Solaris", "2002", "movie"),
]
status, chosen = classify("Solaris", "1990", cands)
# year close to neither → no unique exact-year → ambiguous (top hit preselected)
assert status == "ambiguous" and chosen.tmdb_id == 1
def test_classify_ambiguous_without_year():
cands = [TmdbResult(603, "Matrix", "1999", "movie")]
status, _ = classify("Matrix", None, cands)
assert status == "ambiguous" # no local year → user confirms
def test_classify_no_match():
assert classify("Nic", "2000", []) == ("no_match", None)
class TestFileManagerMigrate:
@pytest.fixture
def file_manager(self, tmp_path, monkeypatch):
import src.core.config as config_module
monkeypatch.setattr(config_module, "GLOBAL_CONFIG_FILE", tmp_path / ".gtag")
from src.core.tag_manager import TagManager
from src.core.file_manager import FileManager
fm = FileManager(TagManager())
fm.set_pool_dir(tmp_path / "pool")
return fm
def test_match_and_assign(self, file_manager, tmp_path, monkeypatch):
(tmp_path / "a.mkv").write_bytes(b"x")
movie = file_manager.import_movie(tmp_path / "a.mkv", "Matrix", year=1999)
assert "[tmdbid" not in movie.file_path.name # not migrated yet
import src.core.tmdb as tmdb
monkeypatch.setattr(
tmdb, "search_movie",
lambda q, year=None, limit=5: [TmdbResult(603, "Matrix", "1999", "movie")])
proposals = file_manager.match_pool_to_tmdb()
assert len(proposals) == 1
p = proposals[0]
assert p.status == "auto" and p.chosen.tmdb_id == 603
file_manager.assign_tmdb_id(p.file, p.chosen.tmdb_id, p.chosen.year)
assert movie.file_path.name == "Matrix (1999) [tmdbid-603].mkv"
def test_match_skips_already_migrated(self, file_manager, tmp_path, monkeypatch):
(tmp_path / "a.mkv").write_bytes(b"x")
file_manager.import_movie(tmp_path / "a.mkv", "Matrix", year=1999, tmdb_id=603)
import src.core.tmdb as tmdb
called = []
monkeypatch.setattr(
tmdb, "search_movie",
lambda q, year=None, limit=5: called.append(q) or [])
proposals = file_manager.match_pool_to_tmdb()
assert proposals == [] and called == [] # already has id → not searched
def test_assign_fills_missing_year_from_tmdb(self, file_manager, tmp_path):
(tmp_path / "a.mkv").write_bytes(b"x")
movie = file_manager.import_movie(tmp_path / "a.mkv", "Matrix") # no year
assert movie.file_path.name == "Matrix.mkv"
file_manager.assign_tmdb_id(movie, 603, "1999") # TMDb supplies the year
assert movie.file_path.name == "Matrix (1999) [tmdbid-603].mkv"