From d384c35e51fffc41c62448b0f1a2c31f7300cdf8 Mon Sep 17 00:00:00 2001 From: OoO Date: Wed, 13 May 2026 12:15:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=AB=E5=8F=96=E6=A5=AD=E7=B8=BE=E5=88=86?= =?UTF-8?q?=E6=9E=90=E9=A0=81=E9=9D=A2=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_cache_manager.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test_cache_manager.py b/tests/test_cache_manager.py index 202cb11..e0f4cb4 100644 --- a/tests/test_cache_manager.py +++ b/tests/test_cache_manager.py @@ -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")]: