forked from retoor/devplacepy
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>
53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
# retoor <retoor@molodetz.nl>
|
|
|
|
import requests
|
|
from tests.conftest import BASE_URL
|
|
from devplacepy.database import get_table
|
|
|
|
|
|
def test_containers_admin_data_denied_for_non_admin(app_server, seeded_db):
|
|
s = requests.Session()
|
|
s.post(
|
|
f"{BASE_URL}/auth/login",
|
|
data={
|
|
"email": seeded_db["bob"]["email"],
|
|
"password": seeded_db["bob"]["password"],
|
|
},
|
|
)
|
|
r = s.get(f"{BASE_URL}/admin/containers/data", allow_redirects=False)
|
|
assert r.status_code in (302, 303, 403)
|
|
|
|
|
|
def test_containers_admin_data_is_paginated(app_server, seeded_db):
|
|
from devplacepy.database import refresh_snapshot
|
|
from devplacepy.services.containers import store
|
|
|
|
refresh_snapshot()
|
|
admin = get_table("users").find_one(username=seeded_db["alice"]["username"])
|
|
uids = []
|
|
try:
|
|
for index in range(27):
|
|
row = store.create_instance(
|
|
{
|
|
"project_uid": "proj-admin-page",
|
|
"name": f"cm-page-{index}",
|
|
"status": "stopped",
|
|
"desired_state": "stopped",
|
|
}
|
|
)
|
|
uids.append(row["uid"])
|
|
headers = {"Accept": "application/json", "X-API-KEY": admin["api_key"]}
|
|
first = requests.get(f"{BASE_URL}/admin/containers/data", headers=headers).json()
|
|
assert first["pagination"]["per_page"] == 25
|
|
assert len(first["instances"]) <= 25
|
|
second = requests.get(
|
|
f"{BASE_URL}/admin/containers/data", headers=headers, params={"page": 2}
|
|
).json()
|
|
assert not {i["uid"] for i in first["instances"]} & {
|
|
i["uid"] for i in second["instances"]
|
|
}
|
|
finally:
|
|
table = get_table("instances")
|
|
for uid in uids:
|
|
table.delete(uid=uid)
|