Add global stats generation
This commit is contained in:
parent
9619888a3a
commit
a1102952e9
3 changed files with 80 additions and 0 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue