The auth dependency raises NotAuthenticatedError (not HTTPException), and the exception handler returns a 302 redirect. Updated the unit test to expect NotAuthenticatedError, and all route auth tests to accept 302 alongside 401/303.
25 lines
804 B
Python
25 lines
804 B
Python
"""Tests for exercise browser routes."""
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
class TestExerciseBrowser:
|
|
"""Tests for GET /exercises."""
|
|
|
|
def test_exercise_browser_requires_auth(self, client: TestClient) -> None:
|
|
"""GET /exercises should require admin login."""
|
|
response = client.get("/exercises", follow_redirects=False)
|
|
assert response.status_code in (401, 302, 303)
|
|
|
|
|
|
class TestExerciseSearch:
|
|
"""Tests for HTMX exercise search."""
|
|
|
|
def test_exercise_search_requires_auth(self, client: TestClient) -> None:
|
|
"""GET /exercises/search should require admin login."""
|
|
response = client.get(
|
|
"/exercises/search?workout_day=Push",
|
|
follow_redirects=False,
|
|
)
|
|
assert response.status_code in (401, 302, 303)
|