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.
22 lines
752 B
Python
22 lines
752 B
Python
"""Tests for dashboard routes."""
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
class TestDashboard:
|
|
"""Tests for GET /dashboard."""
|
|
|
|
def test_dashboard_requires_auth(self, client: TestClient) -> None:
|
|
"""GET /dashboard should require admin login."""
|
|
response = client.get("/dashboard", follow_redirects=False)
|
|
assert response.status_code in (401, 302, 303)
|
|
|
|
|
|
class TestExerciseProgress:
|
|
"""Tests for GET /dashboard/exercise/<id>."""
|
|
|
|
def test_exercise_progress_requires_auth(self, client: TestClient) -> None:
|
|
"""GET /dashboard/exercise/1 should require admin login."""
|
|
response = client.get("/dashboard/exercise/1", follow_redirects=False)
|
|
assert response.status_code in (401, 302, 303)
|