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.
27 lines
867 B
Python
27 lines
867 B
Python
"""Tests for profile management routes."""
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
class TestProfileSwitcher:
|
|
"""Tests for POST /profiles/switch."""
|
|
|
|
def test_switch_profile_requires_auth(self, client: TestClient) -> None:
|
|
"""POST /profiles/switch should require admin login."""
|
|
response = client.post(
|
|
"/profiles/switch",
|
|
data={"profile_id": "1"},
|
|
follow_redirects=False,
|
|
)
|
|
# Should redirect to login or return 401
|
|
assert response.status_code in (401, 302, 303)
|
|
|
|
|
|
class TestProfileList:
|
|
"""Tests for GET /profiles."""
|
|
|
|
def test_profiles_page_requires_auth(self, client: TestClient) -> None:
|
|
"""GET /profiles should require admin login."""
|
|
response = client.get("/profiles", follow_redirects=False)
|
|
assert response.status_code in (401, 302, 303)
|