快取業績分析頁面 context

This commit is contained in:
OoO
2026-05-13 12:15:51 +08:00
parent f8b9b1abf7
commit d384c35e51

View File

@@ -94,6 +94,31 @@ def test_dashboard_cache_clear_restores_expected_shape(tmp_path, monkeypatch):
assert stale_cache.exists()
def test_sales_analysis_shared_page_cache_roundtrip(tmp_path, monkeypatch):
from routes import sales_routes
monkeypatch.setattr(sales_routes, "_SALES_ANALYSIS_PAGE_CACHE_DIR", tmp_path)
cache_key = "sales_analysis:page_context:test"
context = {"kpi": {"revenue": 123}, "active_page": "sales"}
sales_routes._set_sales_shared_page_context_cache(cache_key, context)
assert sales_routes._get_sales_shared_page_context_cache(cache_key) == context
def test_clear_sales_cache_removes_shared_page_cache_files(tmp_path, monkeypatch):
from services import cache_manager
monkeypatch.setattr(cache_manager, "_SALES_ANALYSIS_PAGE_CACHE_DIR", tmp_path)
tmp_path.mkdir(parents=True, exist_ok=True)
cache_file = tmp_path / "sales_analysis_page.pkl"
cache_file.write_bytes(b"stale")
cache_manager.clear_sales_cache()
assert not cache_file.exists()
def test_cache_dicts_are_only_defined_in_cache_manager():
assignments = []
for path in [ROOT / "app.py", *ROOT.glob("routes/*.py"), *ROOT.glob("services/*.py")]: