baseball-engine / backend /tests /helpers.py
github-actions[bot]
Automated Deploy: 0d5b759d8eca219a25b3ab717925e73a66bbf4a4
2756f0f
Raw History Blame Contribute Delete
716 Bytes
"""Shared test helpers built only on public endpoints."""
import uuid
import httpx
PASSWORD = "correct-horse-9"
def bearer(token: str) -> dict[str, str]:
return {"Authorization": f"Bearer {token}"}
async def register(client: httpx.AsyncClient, *, role: str = "player", email: str | None = None) -> dict:
"""Creates an account; returns {"user", "tokens", "headers"}."""
email = email or f"{role}-{uuid.uuid4().hex[:10]}@example.com"
response = await client.post("/v1/auth/register", json={"email": email, "password": PASSWORD, "role": role})
assert response.status_code == 201, response.text
body = response.json()
return {**body, "headers": bearer(body["tokens"]["access_token"])}