34 lines
1.3 KiB
Python
34 lines
1.3 KiB
Python
"""Debug: verify period matching in kpis endpoint"""
|
|
import datetime
|
|
print(f"Current date: {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
|
print(f"period_str for month query: {datetime.datetime.now().strftime('%Y-%m')}")
|
|
|
|
# Run the failing tests with extra debugging
|
|
import os, sys
|
|
sys.path.insert(0, '/root/cma-management/backend')
|
|
|
|
# Patch summary to debug
|
|
from app.api import dashboard as dashboard_mod
|
|
original_summary = dashboard_mod.get_dashboard_summary
|
|
|
|
def debug_summary(role="ceo", period="month", db=None):
|
|
from app.models import KPIDefinition
|
|
from sqlalchemy import func
|
|
if db:
|
|
cnt = db.query(func.count(KPIDefinition.id)).filter(KPIDefinition.status == "active").scalar()
|
|
print(f"[INTERNAL DEBUG] kpi_total query returns: {cnt}")
|
|
all_k = db.query(KPIDefinition).all()
|
|
print(f"[INTERNAL DEBUG] All KPIs: {[(k.id, k.kpi_code, k.status) for k in all_k]}")
|
|
return original_summary(role=role, period=period, db=db)
|
|
|
|
dashboard_mod.get_dashboard_summary = debug_summary
|
|
|
|
# Now run the test sequence
|
|
import pytest
|
|
exit_code = pytest.main(["-v", "--tb=short",
|
|
"tests/test_dashboard.py::TestDashboard::test_summary_empty",
|
|
"tests/test_dashboard.py::TestDashboard::test_summary_with_data"])
|
|
|
|
dashboard_mod.get_dashboard_summary = original_summary
|
|
sys.exit(exit_code)
|