Add test for root index generation

This commit is contained in:
Jordan Wages 2025-07-18 02:49:26 -05:00
commit 9d5dc7e9ad

View file

@ -125,3 +125,36 @@ def test_generate_interval_domain_filter(tmp_path, sample_reports, monkeypatch):
(tmp_path / "output" / "domains" / "example.com" / "hourly" / "hits.json").read_text()
)
assert hits[0]["value"] == 2
def test_generate_root_index(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_interval("hourly")
gr._generate_interval("daily")
# create dummy domain directories
(tmp_path / "output" / "domains" / "foo.com").mkdir(parents=True)
(tmp_path / "output" / "domains" / "bar.com").mkdir(parents=True)
gr._generate_root_index()
index_file = tmp_path / "output" / "index.html"
assert index_file.exists()
content = index_file.read_text()
# check for interval links
assert 'data-interval="hourly"' in content
assert 'data-interval="daily"' in content
# check for domain links
assert 'data-domain="foo.com"' in content
assert 'data-domain="bar.com"' in content