Admin pages: one shared specification, builders, fragments, caps and live refresh
Adds admin_sections registry, shared admin partials, WorkspaceList, admin CLAUDE.md spec, capped node/flag listings, and api/unit tests enforcing the spec. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
import re
|
||||
|
||||
import requests
|
||||
from tests.conftest import BASE_URL
|
||||
from devplacepy.database import get_table, refresh_snapshot
|
||||
|
||||
HTML = {"Accept": "text/html"}
|
||||
JSON = {"Accept": "application/json"}
|
||||
|
||||
|
||||
def _admin(seeded_db):
|
||||
refresh_snapshot()
|
||||
key = get_table("users").find_one(username="alice_test")["api_key"]
|
||||
session = requests.Session()
|
||||
session.headers.update({"X-API-KEY": key})
|
||||
return session
|
||||
|
||||
|
||||
def test_statistics_page_is_server_rendered(seeded_db):
|
||||
admin = _admin(seeded_db)
|
||||
r = admin.get(f"{BASE_URL}/admin/statistics", headers=HTML)
|
||||
assert r.status_code == 200
|
||||
assert "Loading" not in r.text
|
||||
assert 'class="metric-card"' in r.text
|
||||
assert 'id="statistics-initial"' in r.text
|
||||
assert "<time" in r.text
|
||||
|
||||
|
||||
def test_statistics_tab_and_window_navigate(seeded_db):
|
||||
admin = _admin(seeded_db)
|
||||
r = admin.get(f"{BASE_URL}/admin/statistics?tab=members&hours=24&compare=0", headers=HTML)
|
||||
assert r.status_code == 200, re.sub(r"\s+", " ", re.sub(r"<(script|style).*?</\1>", "", r.text, flags=re.S))[-500:]
|
||||
assert 'name="tab" value="members"' in r.text
|
||||
assert '<option value="24" selected>' in r.text
|
||||
assert '<option value="0" selected>No comparison</option>' in r.text
|
||||
|
||||
|
||||
def test_statistics_data_matches_page_json(seeded_db):
|
||||
admin = _admin(seeded_db)
|
||||
page = admin.get(f"{BASE_URL}/admin/statistics?tab=content", headers=JSON).json()
|
||||
data = admin.get(f"{BASE_URL}/admin/statistics/data?tab=content", headers=JSON).json()
|
||||
assert page["initial"]["tab"] == data["tab"] == "content"
|
||||
assert [c["key"] for c in page["initial"]["cards"]] == [c["key"] for c in data["cards"]]
|
||||
assert all(c["display"] for c in data["cards"])
|
||||
|
||||
|
||||
def test_statistics_params_are_clamped(seeded_db):
|
||||
admin = _admin(seeded_db)
|
||||
data = admin.get(
|
||||
f"{BASE_URL}/admin/statistics/data?tab=overview&hours=99999999&top_n=100000",
|
||||
headers=JSON,
|
||||
).json()
|
||||
assert data["window_hours"] == 2160
|
||||
unknown = admin.get(f"{BASE_URL}/admin/statistics/data?tab=nope", headers=JSON).json()
|
||||
assert unknown["tab"] == "overview"
|
||||
Reference in New Issue
Block a user