Files
devplacepy/tests/api/admin/backups/pages.py
T
retoorandClaude Sonnet 5.5 1a9201cb91 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>
2026-11-15 01:50:50 +01:00

55 lines
1.8 KiB
Python

# retoor <retoor@molodetz.nl>
import requests
from tests.conftest import BASE_URL
from devplacepy.database import get_table, refresh_snapshot
from devplacepy.services.backup import store
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_backups_page_is_server_rendered(seeded_db):
admin = _admin(seeded_db)
schedule_uid = store.create_schedule(
name="Pages schedule",
target="database",
kind="interval",
every_seconds=3600,
cron="",
keep_last=3,
created_by="pages-test",
next_run_at="",
)
backup_uid = store.create_backup(
target="database", created_by="pages-test", job_uid="pagesjob"
)
refresh_snapshot()
r = admin.get(f"{BASE_URL}/admin/backups", headers=HTML)
assert r.status_code == 200
assert "Loading" not in r.text
assert 'data-live="storage"' in r.text
assert 'data-live="backups"' in r.text
assert 'data-live="schedules"' in r.text
assert f'data-uid="{backup_uid}"' in r.text
assert f'data-uid="{schedule_uid}"' in r.text
assert "Pages schedule" in r.text
assert "<time" in r.text
def test_backups_data_matches_page_json(seeded_db):
admin = _admin(seeded_db)
page = admin.get(f"{BASE_URL}/admin/backups", headers=JSON).json()
data = admin.get(f"{BASE_URL}/admin/backups/data", headers=JSON).json()
assert {b["uid"] for b in page["backups"]} == {b["uid"] for b in data["backups"]}
assert page["backups_total"] >= len(page["backups"])
assert data["backups_total"] >= len(data["backups"])