穩定活動看板共享快取
All checks were successful
CD Pipeline / deploy (push) Successful in 1m2s

This commit is contained in:
OoO
2026-05-19 13:01:04 +08:00
parent bdae154237
commit 6fa425fb41
3 changed files with 103 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
from pathlib import Path
import pickle
from flask import Flask, session
@@ -182,6 +183,46 @@ def test_clear_daily_sales_cache_removes_shared_view_cache_files(tmp_path, monke
assert not cache_file.exists()
def test_promo_dashboard_shared_cache_roundtrip(tmp_path, monkeypatch):
from routes import edm_routes
shared_cache = tmp_path / "promo_dashboard_cache.pkl"
monkeypatch.setattr(edm_routes, "_PROMO_SHARED_CACHE_FILE", shared_cache)
edm_routes._PROMO_DASHBOARD_CACHE.clear()
cache_key = ("edm", "default", "desc", "", "2026-05-19-12", (10, "2026-05-19T12:00:00", 30))
data = {
"sorted_grouped_items": {"11:00": []},
"slot_stats": {"11:00": {"on_shelf": 0}},
"items_in_batch": [],
"last_update_str": "2026-05-19 12:00",
"activity_time": "11:00",
"active_tab": "11:00",
"current_batch_id": "batch-1",
}
edm_routes._write_shared_promo_dashboard_cache(cache_key, data)
edm_routes._PROMO_DASHBOARD_CACHE.clear()
assert edm_routes._load_shared_promo_dashboard_cache(cache_key) == data
assert shared_cache.exists()
def test_promo_dashboard_shared_cache_ignores_other_versions(tmp_path, monkeypatch):
from routes import edm_routes
shared_cache = tmp_path / "promo_dashboard_cache.pkl"
cache_key = ("edm", "default", "desc", "", "bucket", (1, "ts", 1))
shared_cache.write_bytes(
pickle.dumps(
{"version": "older-version", "entries": {cache_key: {"stale": True}}},
protocol=pickle.HIGHEST_PROTOCOL,
)
)
monkeypatch.setattr(edm_routes, "_PROMO_SHARED_CACHE_FILE", shared_cache)
assert edm_routes._load_shared_promo_dashboard_cache(cache_key) is None
def test_sales_analysis_preview_context_cache_avoids_reloading_options(tmp_path, monkeypatch):
from routes import sales_routes