first commit
This commit is contained in:
commit
34ea15a54d
246 changed files with 18660 additions and 0 deletions
50
backend/tests/test_admin_api.py
Normal file
50
backend/tests/test_admin_api.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import uuid
|
||||
|
||||
from tests.helpers import auth_headers, client, register_user
|
||||
|
||||
|
||||
def _admin_token() -> str:
|
||||
from app.core.config import get_settings
|
||||
|
||||
settings = get_settings()
|
||||
response = client.post(
|
||||
"/api/admin/auth/login",
|
||||
json={"email": settings.admin_email, "password": settings.admin_password},
|
||||
)
|
||||
if response.status_code != 200:
|
||||
raise RuntimeError(f"Admin login failed: {response.text} — run scripts/seed_admin.py")
|
||||
return response.json()["access_token"]
|
||||
|
||||
|
||||
def test_attendee_cannot_access_admin_dashboard() -> None:
|
||||
_, token = register_user()
|
||||
response = client.get("/api/admin/dashboard/metrics", headers=auth_headers(token))
|
||||
assert response.status_code == 401
|
||||
|
||||
|
||||
def test_admin_dashboard_metrics() -> None:
|
||||
token = _admin_token()
|
||||
response = client.get("/api/admin/dashboard/metrics", headers={"Authorization": f"Bearer {token}"})
|
||||
assert response.status_code == 200
|
||||
body = response.json()
|
||||
assert "total_revenue_paise" in body
|
||||
assert "tickets_sold" in body
|
||||
assert "upcoming_events" in body
|
||||
|
||||
|
||||
def test_admin_lists_catalog() -> None:
|
||||
token = _admin_token()
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
assert client.get("/api/admin/events", headers=headers).status_code == 200
|
||||
assert client.get("/api/admin/venues", headers=headers).status_code == 200
|
||||
assert client.get("/api/admin/orders", headers=headers).status_code == 200
|
||||
assert client.get("/api/admin/payments", headers=headers).status_code == 200
|
||||
assert client.get("/api/admin/stats/events", headers=headers).status_code == 200
|
||||
|
||||
|
||||
def test_admin_invalid_login() -> None:
|
||||
response = client.post(
|
||||
"/api/admin/auth/login",
|
||||
json={"email": f"nope-{uuid.uuid4().hex}@example.com", "password": "wrongpass"},
|
||||
)
|
||||
assert response.status_code == 401
|
||||
Loading…
Add table
Add a link
Reference in a new issue