17 lines
474 B
Python
17 lines
474 B
Python
"""Helpers for API tests that exercise authenticated application routes."""
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app import auth, database
|
|
|
|
|
|
def authenticated_client(app: FastAPI) -> TestClient:
|
|
database.ensure_user(database.LOCAL_USER_ID)
|
|
token, _ = auth.issue_session(database.LOCAL_USER_ID)
|
|
return TestClient(
|
|
app,
|
|
headers={"Authorization": f"Bearer {token}"},
|
|
client=("127.0.0.1", 8000),
|
|
)
|