Add global stats generation

This commit is contained in:
Jordan Wages 2025-07-19 00:16:11 -05:00
commit a1102952e9
3 changed files with 80 additions and 0 deletions

View file

@ -189,3 +189,31 @@ def test_global_reports_once(tmp_path, sample_reports, monkeypatch):
assert global_snippet.exists()
assert not (tmp_path / "output" / "hourly" / "domain_totals.html").exists()
def test_global_stats_file(tmp_path, sample_reports, monkeypatch):
db_path = tmp_path / "database" / "ngxstat.db"
setup_db(db_path)
monkeypatch.setattr(gr, "DB_PATH", db_path)
monkeypatch.setattr(gr, "OUTPUT_DIR", tmp_path / "output")
monkeypatch.setattr(gr, "REPORT_CONFIG", sample_reports)
monkeypatch.setattr(
gr, "TEMPLATE_DIR", Path(__file__).resolve().parents[1] / "templates"
)
gr._generate_global()
stats_path = tmp_path / "output" / "global" / "stats.json"
assert stats_path.exists()
stats = json.loads(stats_path.read_text())
assert set(stats.keys()) == {
"total_logs",
"start_date",
"end_date",
"unique_domains",
}
assert stats["total_logs"] == 2
assert stats["start_date"] == "2024-01-01 10:00:00"
assert stats["end_date"] == "2024-01-01 10:05:00"
assert stats["unique_domains"] == 1