This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from pathlib import Path
|
||||
from datetime import date
|
||||
import pickle
|
||||
from flask import Flask, session
|
||||
|
||||
@@ -183,6 +184,54 @@ def test_clear_daily_sales_cache_removes_shared_view_cache_files(tmp_path, monke
|
||||
assert not cache_file.exists()
|
||||
|
||||
|
||||
def test_daily_sales_metadata_uses_single_postgres_query():
|
||||
from routes import daily_sales_routes
|
||||
|
||||
class FakeDialect:
|
||||
name = "postgresql"
|
||||
|
||||
class FakeResult:
|
||||
def fetchone(self):
|
||||
return ("2026-05-17", 85118, [date(2026, 5, 17), date(2026, 5, 16)])
|
||||
|
||||
class FakeConnection:
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc, tb):
|
||||
return False
|
||||
|
||||
def execute(self, query):
|
||||
self.query = str(query)
|
||||
return FakeResult()
|
||||
|
||||
class FakeEngine:
|
||||
dialect = FakeDialect()
|
||||
|
||||
def connect(self):
|
||||
return FakeConnection()
|
||||
|
||||
dates, fingerprint = daily_sales_routes._get_daily_sales_metadata(FakeEngine())
|
||||
|
||||
assert [d.strftime("%Y-%m-%d") for d in dates] == ["2026-05-17", "2026-05-16"]
|
||||
assert fingerprint == ("2026-05-17", 85118)
|
||||
|
||||
|
||||
def test_daily_sales_metadata_falls_back_for_sqlite(monkeypatch):
|
||||
from routes import daily_sales_routes
|
||||
|
||||
class FakeDialect:
|
||||
name = "sqlite"
|
||||
|
||||
class FakeEngine:
|
||||
dialect = FakeDialect()
|
||||
|
||||
monkeypatch.setattr(daily_sales_routes, "_get_available_daily_dates", lambda engine, table_name: ["date-a"])
|
||||
monkeypatch.setattr(daily_sales_routes, "_get_data_fingerprint", lambda engine, table_name: ("date-a", 1))
|
||||
|
||||
assert daily_sales_routes._get_daily_sales_metadata(FakeEngine()) == (["date-a"], ("date-a", 1))
|
||||
|
||||
|
||||
def test_promo_dashboard_shared_cache_roundtrip(tmp_path, monkeypatch):
|
||||
from routes import edm_routes
|
||||
|
||||
|
||||
Reference in New Issue
Block a user