Add statistics and data-consistency menus, recently-added folder
This commit is contained in:
@@ -592,6 +592,72 @@ class TestPoolManagement:
|
||||
assert movie.csfd_link == "https://csfd.cz/film/1"
|
||||
assert file_manager.index.get(movie.file_path) is not None
|
||||
|
||||
def test_statistics_aggregates_pool(self, file_manager, tmp_path):
|
||||
file_manager.set_pool_dir(tmp_path / "pool")
|
||||
(tmp_path / "a.mkv").write_bytes(b"x" * 100)
|
||||
(tmp_path / "b.mkv").write_bytes(b"y" * 50)
|
||||
a = file_manager.import_movie(tmp_path / "a.mkv", "A", "https://csfd/1")
|
||||
a.add_tag("Žánr/Akční")
|
||||
a.add_tag("Žánr/Sci-Fi")
|
||||
a.csfd_cache = {"rating": 90}
|
||||
a.save_metadata()
|
||||
b = file_manager.import_movie(tmp_path / "b.mkv", "B")
|
||||
b.add_tag("Žánr/Akční")
|
||||
|
||||
s = file_manager.statistics()
|
||||
assert s["count"] == 2
|
||||
assert s["total_size"] == 150
|
||||
assert s["with_csfd"] == 1 and s["without_csfd"] == 1
|
||||
assert s["untagged"] == 0
|
||||
assert s["avg_rating"] == 90
|
||||
# Akční on both movies → count 2, sorted first
|
||||
assert dict(s["categories"]["Žánr"])["Akční"] == 2
|
||||
assert s["categories"]["Žánr"][0] == ("Akční", 2)
|
||||
|
||||
def test_check_data_consistency_clean(self, file_manager, tmp_path):
|
||||
file_manager.set_pool_dir(tmp_path / "pool")
|
||||
(tmp_path / "a.mkv").write_bytes(b"a")
|
||||
file_manager.import_movie(tmp_path / "a.mkv", "Matrix")
|
||||
|
||||
result = file_manager.check_data_consistency()
|
||||
assert result["ok"]
|
||||
assert result["missing"] == []
|
||||
assert result["untracked"] == []
|
||||
assert result["index_count"] == 1 and result["disk_count"] == 1
|
||||
|
||||
def test_check_data_consistency_detects_missing_file(self, file_manager, tmp_path):
|
||||
file_manager.set_pool_dir(tmp_path / "pool")
|
||||
(tmp_path / "a.mkv").write_bytes(b"a")
|
||||
movie = file_manager.import_movie(tmp_path / "a.mkv", "Matrix")
|
||||
movie.file_path.unlink() # someone deleted the file directly
|
||||
|
||||
result = file_manager.check_data_consistency()
|
||||
assert result["missing"] == ["Filmy/Matrix.mkv"]
|
||||
assert result["untracked"] == []
|
||||
|
||||
def test_check_data_consistency_detects_untracked_file(self, file_manager, tmp_path):
|
||||
file_manager.set_pool_dir(tmp_path / "pool")
|
||||
(tmp_path / "a.mkv").write_bytes(b"a")
|
||||
file_manager.import_movie(tmp_path / "a.mkv", "Matrix")
|
||||
# a file dropped into the pool without importing
|
||||
(file_manager.movies_dir / "Sneaked.mkv").write_bytes(b"x")
|
||||
|
||||
result = file_manager.check_data_consistency()
|
||||
assert result["missing"] == []
|
||||
assert result["untracked"] == ["Filmy/Sneaked.mkv"]
|
||||
|
||||
def test_import_movie_records_added_timestamp(self, file_manager, tmp_path):
|
||||
file_manager.set_pool_dir(tmp_path / "pool")
|
||||
source = tmp_path / "raw.mkv"
|
||||
source.write_bytes(b"x")
|
||||
movie = file_manager.import_movie(source, "Matrix")
|
||||
|
||||
assert movie.added is not None
|
||||
# parseable ISO timestamp, persisted in the index
|
||||
from datetime import datetime
|
||||
datetime.fromisoformat(movie.added)
|
||||
assert file_manager.index.get(movie.file_path)["added"] == movie.added
|
||||
|
||||
def test_import_movie_move_removes_source(self, file_manager, tmp_path):
|
||||
file_manager.set_pool_dir(tmp_path / "pool")
|
||||
source = tmp_path / "raw.mkv"
|
||||
|
||||
Reference in New Issue
Block a user