-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_admin_ui.py
More file actions
73 lines (55 loc) · 2.1 KB
/
Copy pathtest_admin_ui.py
File metadata and controls
73 lines (55 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from pathlib import Path
import pytest
from fastapi.testclient import TestClient
from src.serving.api.auth import AuthManager
from src.serving.api.main import app
pytestmark = pytest.mark.integration
def _write_api_keys(path: Path) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(
(
"keys:\n"
' - key: "admin-ui-acme-key"\n'
' name: "Admin UI Agent"\n'
' tenant: "acme"\n'
" rate_limit_rpm: 100\n"
" allowed_entity_types: null\n"
' created_at: "2026-04-10"\n'
),
encoding="utf-8",
newline="\n",
)
@pytest.fixture
def client(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
monkeypatch.setenv("DUCKDB_PATH", str(tmp_path / "pipeline.duckdb"))
monkeypatch.setenv("AGENTFLOW_USAGE_DB_PATH", str(tmp_path / "usage.duckdb"))
api_keys_path = tmp_path / "config" / "api_keys.yaml"
_write_api_keys(api_keys_path)
with TestClient(app) as c:
manager = AuthManager(
api_keys_path=api_keys_path,
db_path=tmp_path / "usage.duckdb",
admin_key="admin-secret",
)
manager.load()
manager.ensure_usage_table()
c.app.state.auth_manager = manager
c.get("/v1/metrics/revenue", headers={"X-API-Key": "admin-ui-acme-key"})
yield c
manager.shutdown()
def test_admin_ui_requires_admin_key(client: TestClient):
response = client.get("/admin/")
assert response.status_code == 401
def test_admin_ui_renders_dashboard(client: TestClient):
response = client.get("/admin/", headers={"X-Admin-Key": "admin-secret"})
assert response.status_code == 200
assert "text/html" in response.headers["content-type"]
assert "AgentFlow Admin" in response.text
assert "System Summary" in response.text
def test_admin_ui_partial_renders_summary(client: TestClient):
response = client.get(
"/admin/partials/summary",
headers={"X-Admin-Key": "admin-secret"},
)
assert response.status_code == 200
assert "System Summary" in response.text