Fix SQLite view creation and test domain filter
This commit is contained in:
parent
b87c76e8c9
commit
fb08fcaa07
2 changed files with 68 additions and 12 deletions
|
@ -32,11 +32,31 @@ def setup_db(path: Path):
|
|||
)
|
||||
cur.execute(
|
||||
"INSERT INTO logs (ip, host, time, request, status, bytes_sent, referer, user_agent, cache_status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
("127.0.0.1", "example.com", "2024-01-01 10:00:00", "GET / HTTP/1.1", 200, 100, "-", "curl", "MISS"),
|
||||
(
|
||||
"127.0.0.1",
|
||||
"example.com",
|
||||
"2024-01-01 10:00:00",
|
||||
"GET / HTTP/1.1",
|
||||
200,
|
||||
100,
|
||||
"-",
|
||||
"curl",
|
||||
"MISS",
|
||||
),
|
||||
)
|
||||
cur.execute(
|
||||
"INSERT INTO logs (ip, host, time, request, status, bytes_sent, referer, user_agent, cache_status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
("127.0.0.1", "example.com", "2024-01-01 10:05:00", "GET /err HTTP/1.1", 500, 100, "-", "curl", "MISS"),
|
||||
(
|
||||
"127.0.0.1",
|
||||
"example.com",
|
||||
"2024-01-01 10:05:00",
|
||||
"GET /err HTTP/1.1",
|
||||
500,
|
||||
100,
|
||||
"-",
|
||||
"curl",
|
||||
"MISS",
|
||||
),
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
@ -72,14 +92,36 @@ def test_generate_interval(tmp_path, sample_reports, monkeypatch):
|
|||
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")
|
||||
monkeypatch.setattr(
|
||||
gr, "TEMPLATE_DIR", Path(__file__).resolve().parents[1] / "templates"
|
||||
)
|
||||
|
||||
gr._generate_interval("hourly")
|
||||
|
||||
hits = json.loads((tmp_path / "output" / "hourly" / "hits.json").read_text())
|
||||
assert hits[0]["value"] == 2
|
||||
error_rate = json.loads((tmp_path / "output" / "hourly" / "error_rate.json").read_text())
|
||||
error_rate = json.loads(
|
||||
(tmp_path / "output" / "hourly" / "error_rate.json").read_text()
|
||||
)
|
||||
assert error_rate[0]["value"] == pytest.approx(50.0)
|
||||
reports = json.loads((tmp_path / "output" / "hourly" / "reports.json").read_text())
|
||||
assert {r["name"] for r in reports} == {"hits", "error_rate"}
|
||||
|
||||
|
||||
def test_generate_interval_domain_filter(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", "example.com")
|
||||
|
||||
hits = json.loads(
|
||||
(tmp_path / "output" / "example.com" / "hourly" / "hits.json").read_text()
|
||||
)
|
||||
assert hits[0]["value"] == 2
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue