first commit
This commit is contained in:
commit
34ea15a54d
246 changed files with 18660 additions and 0 deletions
56
backend/tests/helpers.py
Normal file
56
backend/tests/helpers.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import uuid
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.main import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def register_user() -> tuple[str, str]:
|
||||
email = f"buyer-{uuid.uuid4().hex}@example.com"
|
||||
password = "securepass1"
|
||||
response = client.post(
|
||||
"/api/auth/register",
|
||||
json={"email": email, "password": password, "full_name": "Buyer"},
|
||||
)
|
||||
assert response.status_code == 201
|
||||
token = response.json()["access_token"]
|
||||
return email, token
|
||||
|
||||
|
||||
def auth_headers(token: str) -> dict[str, str]:
|
||||
return {"Authorization": f"Bearer {token}"}
|
||||
|
||||
|
||||
def first_published_event() -> dict:
|
||||
response = client.get("/api/events", params={"upcoming": "false"})
|
||||
assert response.status_code == 200
|
||||
events = response.json()
|
||||
assert events, "Seed catalog required for order tests"
|
||||
return events[0]
|
||||
|
||||
|
||||
def pick_tier(tiers: list[dict], quantity: int = 1) -> dict | None:
|
||||
return next(
|
||||
(t for t in tiers if t["status"] == "active" and t["remaining_quantity"] >= quantity),
|
||||
None,
|
||||
)
|
||||
|
||||
|
||||
def create_pending_order():
|
||||
import pytest
|
||||
|
||||
_, token = register_user()
|
||||
event = first_published_event()
|
||||
tiers = client.get(f"/api/events/{event['id']}/tickets").json()
|
||||
tier = pick_tier(tiers, 1)
|
||||
if not tier:
|
||||
pytest.skip("No ticket inventory available for test")
|
||||
response = client.post(
|
||||
"/api/orders",
|
||||
headers={**auth_headers(token), "Idempotency-Key": uuid.uuid4().hex},
|
||||
json={"event_id": event["id"], "items": [{"ticket_type_id": tier["id"], "quantity": 1}]},
|
||||
)
|
||||
assert response.status_code == 201
|
||||
return token, response.json()
|
||||
Loading…
Add table
Add a link
Reference in a new issue