fix: parameterize import snapshot date filters
All checks were successful
CD Pipeline / deploy (push) Successful in 1m3s

This commit is contained in:
OoO
2026-05-18 14:23:49 +08:00
parent cb02cd350f
commit 49f6b3ebd9
3 changed files with 98 additions and 10 deletions

View File

@@ -1,5 +1,7 @@
from pathlib import Path
from datetime import date
from services import import_service
from services.import_service import _build_in_clause
@@ -17,6 +19,20 @@ def test_import_service_does_not_interpolate_date_values_into_in_clauses():
assert "join([f\"'{d}'\" for d in" not in source
def test_daily_snapshot_delete_casts_text_date_column_on_postgres(monkeypatch):
monkeypatch.setattr(import_service, "_db_dialect_name", lambda: "postgresql")
assert import_service._date_filter_expr("snapshot_date") == "snapshot_date::date"
assert import_service._normalise_date_values_for_sql(["2026-05-01"]) == [date(2026, 5, 1)]
def test_daily_snapshot_delete_uses_iso_dates_on_sqlite(monkeypatch):
monkeypatch.setattr(import_service, "_db_dialect_name", lambda: "sqlite")
assert import_service._date_filter_expr("snapshot_date") == "date(snapshot_date)"
assert import_service._normalise_date_values_for_sql([date(2026, 5, 1)]) == ["2026-05-01"]
def test_monthly_summary_import_does_not_replace_entire_table():
source = Path("routes/import_routes.py").read_text(encoding="utf-8")
start = source.index("DELETE FROM monthly_summary_analysis WHERE year = :y AND month = :m")