Add global report generation

This commit is contained in:
Jordan Wages 2025-07-19 00:09:26 -05:00
commit a3f06fd9e2
3 changed files with 83 additions and 0 deletions

View file

@ -80,6 +80,14 @@ def sample_reports(tmp_path):
FROM logs
GROUP BY bucket
ORDER BY bucket
- name: domain_totals
global: true
query: |
SELECT host AS bucket,
COUNT(*) AS value
FROM logs
GROUP BY host
ORDER BY value DESC
"""
)
return cfg
@ -161,3 +169,23 @@ def test_generate_root_index(tmp_path, sample_reports, monkeypatch):
# check for domain options
assert '<option value="foo.com">' in content
assert '<option value="bar.com">' in content
def test_global_reports_once(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()
gr._generate_interval("hourly")
global_snippet = tmp_path / "output" / "global" / "domain_totals.html"
assert global_snippet.exists()
assert not (tmp_path / "output" / "hourly" / "domain_totals.html").exists()