Spaces:
Running on T4
Running on T4
Download backend/tests/helpers.py from modventures/baseball-engine: direct link, hf CLI and curl.
- Browser
- Download file 716 Bytes
-
https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/backend/tests/helpers.py
- Command line
-
hf download hf://spaces/modventures/baseball-engine/backend/tests/helpers.py
-
curl -L -o helpers.py https://huggingface.co/spaces/modventures/baseball-engine/resolve/main/backend/tests/helpers.py
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"])} | |