From 7aae4d050ef27b96fbb38b10139c8f6da2454169 Mon Sep 17 00:00:00 2001 From: Sleeps Date: Wed, 7 Oct 2026 13:55:43 +0100 Subject: [PATCH] Test persistent paged index reports --- tests/test_index_report.py | 64 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/test_index_report.py diff --git a/tests/test_index_report.py b/tests/test_index_report.py new file mode 100644 index 0000000..2f8d9b2 --- /dev/null +++ b/tests/test_index_report.py @@ -0,0 +1,64 @@ +from __future__ import annotations + +import tempfile +import unittest +from pathlib import Path +from types import SimpleNamespace +from unittest.mock import patch + +from scene_search.index_jobs import IndexJobManager +from scene_search.index_report import load_index_report, save_index_report + + +class IndexReportTests(unittest.TestCase): + def test_report_persists_across_process_state(self) -> None: + with tempfile.TemporaryDirectory() as tmp: + fake_settings = SimpleNamespace(data_dir=Path(tmp)) + report = { + "available": True, + "kind": "index", + "status": "complete", + "summary": {"failed": 1, "pruned": 1, "indexed": 1}, + "items": [ + {"status": "failed", "title": "Bad", "reason": "No Trickplay"}, + {"status": "removed", "title": "Gone", "reason": "Removed"}, + {"status": "indexed", "title": "Good", "reason": "Indexed"}, + ], + } + + with patch("scene_search.index_report.settings", fake_settings): + save_index_report(report) + loaded = load_index_report() + + self.assertTrue(loaded["available"]) + self.assertEqual(loaded["summary"]["failed"], 1) + self.assertEqual(len(loaded["items"]), 3) + + def test_manager_report_filters_and_pages_without_polling_all_items(self) -> None: + manager = IndexJobManager(SimpleNamespace()) # type: ignore[arg-type] + stored = { + "available": True, + "kind": "index", + "status": "complete", + "started_at": "start", + "finished_at": "finish", + "summary": {"failed": 3}, + "items": [ + {"status": "failed", "title": "A"}, + {"status": "indexed", "title": "B"}, + {"status": "failed", "title": "C"}, + {"status": "failed", "title": "D"}, + ], + } + + with patch("scene_search.index_jobs.load_index_report", return_value=stored): + page = manager.report(category="failed", offset=1, limit=1) + + self.assertEqual(page["total"], 3) + self.assertEqual(page["offset"], 1) + self.assertEqual(page["limit"], 1) + self.assertEqual([item["title"] for item in page["items"]], ["C"]) + + +if __name__ == "__main__": + unittest.main()