Fix PPT auto generation and analytics fallbacks
Some checks failed
CD Pipeline / deploy (push) Failing after 26s
Some checks failed
CD Pipeline / deploy (push) Failing after 26s
This commit is contained in:
74
tests/test_ppt_auto_generation_service.py
Normal file
74
tests/test_ppt_auto_generation_service.py
Normal file
@@ -0,0 +1,74 @@
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def test_build_defined_ppt_jobs_uses_latest_date():
|
||||
from services.ppt_auto_generation_service import build_defined_ppt_jobs
|
||||
|
||||
jobs = build_defined_ppt_jobs(latest_date="2026-05-11")
|
||||
by_type = {job.report_type: job for job in jobs}
|
||||
|
||||
assert list(by_type) == ["daily", "weekly", "monthly", "strategy", "competitor", "promo"]
|
||||
assert by_type["daily"].sub_arg == "2026/05/11"
|
||||
assert by_type["monthly"].sub_arg == "2026/05"
|
||||
assert by_type["strategy"].sub_arg == "monthly 2026/05"
|
||||
assert by_type["competitor"].sub_arg == "monthly"
|
||||
assert by_type["promo"].sub_arg == "2026/05/05-2026/05/11"
|
||||
|
||||
|
||||
def test_auto_generation_respects_disabled_flag(monkeypatch):
|
||||
monkeypatch.setenv("PPT_AUTO_GENERATION_ENABLED", "false")
|
||||
|
||||
from services.ppt_auto_generation_service import generate_defined_ppt_reports
|
||||
|
||||
result = generate_defined_ppt_reports(report_types=["daily"])
|
||||
|
||||
assert result["ok"] is False
|
||||
assert result["status"] == "disabled"
|
||||
|
||||
|
||||
def test_dry_run_does_not_generate(monkeypatch):
|
||||
monkeypatch.setenv("PPT_AUTO_GENERATION_ENABLED", "true")
|
||||
|
||||
from services import ppt_auto_generation_service as svc
|
||||
|
||||
monkeypatch.setattr(svc, "_latest_sales_date", lambda: "2026-05-11")
|
||||
|
||||
result = svc.generate_defined_ppt_reports(
|
||||
report_types=["daily", "monthly"],
|
||||
dry_run=True,
|
||||
)
|
||||
|
||||
assert result["ok"] is True
|
||||
assert result["status"] == "planned"
|
||||
assert [job["report_type"] for job in result["jobs"]] == ["daily", "monthly"]
|
||||
|
||||
|
||||
def test_coverage_marks_ready_from_database(monkeypatch):
|
||||
from services import ppt_auto_generation_service as svc
|
||||
|
||||
class _Rows:
|
||||
def fetchall(self):
|
||||
return [("daily", 2), ("monthly", 1)]
|
||||
|
||||
class _Session:
|
||||
def execute(self, *_args, **_kwargs):
|
||||
return _Rows()
|
||||
|
||||
def close(self):
|
||||
return None
|
||||
|
||||
monkeypatch.setattr(svc, "get_session", lambda: _Session())
|
||||
monkeypatch.setenv("PPT_AUTO_GENERATION_ENABLED", "true")
|
||||
|
||||
result = svc.get_defined_report_coverage(
|
||||
month_start=datetime(2026, 5, 1),
|
||||
month_end=datetime(2026, 6, 1),
|
||||
reports_dir="/tmp/does-not-exist-for-test",
|
||||
report_types=["daily", "monthly", "weekly"],
|
||||
)
|
||||
|
||||
by_key = {item["key"]: item for item in result["items"]}
|
||||
assert by_key["daily"]["ready"] is True
|
||||
assert by_key["monthly"]["ready"] is True
|
||||
assert by_key["weekly"]["ready"] is False
|
||||
assert result["missing_count"] == 1
|
||||
Reference in New Issue
Block a user