style: format test_api_auth_enabled.py with Black and isort
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
@@ -5,7 +5,6 @@ These tests verify that authentication properly protects endpoints when enabled.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
@@ -40,6 +39,7 @@ class TestSessionConfiguration:
|
||||
def test_session_secret_configured_in_conftest(self):
|
||||
"""Test that SESSION_SECRET is configured in conftest.py."""
|
||||
import os
|
||||
|
||||
session_secret = os.environ.get("SESSION_SECRET")
|
||||
assert session_secret is not None
|
||||
assert len(session_secret) >= 32, "SESSION_SECRET must be at least 32 characters"
|
||||
@@ -60,6 +60,7 @@ class TestAuthEnabledConfiguration:
|
||||
def test_auth_enabled_defaults_to_false_in_tests(self):
|
||||
"""Test that AUTH_ENABLED defaults to False in test environment."""
|
||||
import os
|
||||
|
||||
auth_enabled = os.environ.get("AUTH_ENABLED", "False")
|
||||
assert auth_enabled == "False", "Tests should run with AUTH_ENABLED=False by default"
|
||||
|
||||
@@ -102,9 +103,10 @@ class TestProtectedAPIEndpoints:
|
||||
# This tests the endpoint logic itself
|
||||
|
||||
# We can't easily set session in TestClient, so we'll test the handler directly
|
||||
from app.api.user import whoami_handler
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from app.api.user import whoami_handler
|
||||
|
||||
mock_request = MagicMock()
|
||||
mock_request.session = {
|
||||
"user": {
|
||||
@@ -115,6 +117,7 @@ class TestProtectedAPIEndpoints:
|
||||
}
|
||||
|
||||
import asyncio
|
||||
|
||||
result = asyncio.run(whoami_handler(mock_request))
|
||||
|
||||
assert result["id"] == "test123"
|
||||
@@ -123,10 +126,12 @@ class TestProtectedAPIEndpoints:
|
||||
|
||||
def test_whoami_raises_401_when_no_user(self):
|
||||
"""Test /whoami handler raises 401 when no user in session."""
|
||||
from app.api.user import whoami_handler
|
||||
from fastapi import HTTPException
|
||||
from unittest.mock import MagicMock
|
||||
import asyncio
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from fastapi import HTTPException
|
||||
|
||||
from app.api.user import whoami_handler
|
||||
|
||||
mock_request = MagicMock()
|
||||
mock_request.session = {}
|
||||
|
||||
Reference in New Issue
Block a user