blitz_api/tests/routers/utils.py

27 lines
963 B
Python
Raw Permalink Normal View History

from fastapi import status
from starlette.testclient import TestClient
invalid_auth_header = {"Authorization": "Bearer dsgfdg"}
def call_route(test_client: TestClient, route: str, params={}, method="g"):
# Test with no "Authentication" header at all
2026-02-02 12:25:30 +01:00
# Should return a 401 by BlitzAPI's JWTBearer
response = None
if method == "g":
response = test_client.get(route, params=params)
elif method == "p":
response = test_client.post(route, params=params)
2026-02-02 12:25:30 +01:00
assert response.status_code == status.HTTP_401_UNAUTHORIZED
# Test with an invalid "Authentication" header
2026-02-02 12:25:30 +01:00
# Should return a 401 by BlitzAPI's JWTBearer
response = None
if method == "g":
response = test_client.get(route, params=params, headers=invalid_auth_header)
elif method == "p":
response = test_client.post(route, params=params, headers=invalid_auth_header)
assert response.status_code == status.HTTP_401_UNAUTHORIZED