style: apply ruff formatting to source and test files
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""API test fixtures."""
|
||||
|
||||
from typing import AsyncGenerator
|
||||
from collections.abc import AsyncGenerator
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
@@ -25,7 +25,7 @@ def mock_keycloak_client() -> MagicMock:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def client(mock_keycloak_client: MagicMock) -> AsyncGenerator[AsyncClient, None]:
|
||||
async def client(mock_keycloak_client: MagicMock) -> AsyncGenerator[AsyncClient]:
|
||||
"""Create async HTTP client for API testing."""
|
||||
with patch(
|
||||
"app.presentation.api.deps.KeycloakAuthClient",
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
# E2E test fixtures
|
||||
# Provides: full application state, end-to-end workflows, cleanup
|
||||
|
||||
from typing import AsyncGenerator
|
||||
from collections.abc import AsyncGenerator
|
||||
|
||||
import pytest
|
||||
from fastapi import FastAPI
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def e2e_app() -> AsyncGenerator[FastAPI, None]:
|
||||
async def e2e_app() -> AsyncGenerator[FastAPI]:
|
||||
"""Create full application instance for E2E testing."""
|
||||
from app.main import app_factory
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Integration test fixtures."""
|
||||
|
||||
from typing import AsyncGenerator
|
||||
from collections.abc import AsyncGenerator
|
||||
|
||||
import pytest
|
||||
from sqlalchemy.ext.asyncio import (
|
||||
@@ -39,7 +39,7 @@ def session_factory(engine: AsyncEngine) -> async_sessionmaker[AsyncSession]:
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
async def setup_db(engine: AsyncEngine) -> AsyncGenerator[None, None]:
|
||||
async def setup_db(engine: AsyncEngine) -> AsyncGenerator[None]:
|
||||
"""Setup database tables for each test."""
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
@@ -51,7 +51,7 @@ async def setup_db(engine: AsyncEngine) -> AsyncGenerator[None, None]:
|
||||
@pytest.fixture
|
||||
async def db_session(
|
||||
session_factory: async_sessionmaker[AsyncSession],
|
||||
) -> AsyncGenerator[AsyncSession, None]:
|
||||
) -> AsyncGenerator[AsyncSession]:
|
||||
"""Create database session for testing."""
|
||||
async with session_factory() as session:
|
||||
yield session
|
||||
|
||||
@@ -123,9 +123,7 @@ class TestKeycloakAuthClient:
|
||||
"""Create Keycloak client."""
|
||||
return KeycloakAuthClient(settings)
|
||||
|
||||
def test_client_initialization(
|
||||
self, client: KeycloakAuthClient, settings: Settings
|
||||
) -> None:
|
||||
def test_client_initialization(self, client: KeycloakAuthClient, settings: Settings) -> None:
|
||||
"""Test client initialization."""
|
||||
assert client._settings == settings
|
||||
assert client._base_url == "http://localhost:8080/realms/test-realm"
|
||||
@@ -144,10 +142,7 @@ class TestKeycloakAuthClient:
|
||||
def test_get_userinfo_url(self, client: KeycloakAuthClient) -> None:
|
||||
"""Test userinfo URL generation."""
|
||||
url = client._get_userinfo_url()
|
||||
assert (
|
||||
url
|
||||
== "http://localhost:8080/realms/test-realm/protocol/openid-connect/userinfo"
|
||||
)
|
||||
assert url == "http://localhost:8080/realms/test-realm/protocol/openid-connect/userinfo"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_introspect_token_success(self, client: KeycloakAuthClient) -> None:
|
||||
@@ -196,18 +191,14 @@ class TestKeycloakAuthClient:
|
||||
assert result.is_valid is False
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_introspect_token_http_error(
|
||||
self, client: KeycloakAuthClient
|
||||
) -> None:
|
||||
async def test_introspect_token_http_error(self, client: KeycloakAuthClient) -> None:
|
||||
"""Test introspection with HTTP error."""
|
||||
import httpx
|
||||
|
||||
mock_async_client = AsyncMock()
|
||||
mock_async_client.__aenter__ = AsyncMock(return_value=mock_async_client)
|
||||
mock_async_client.__aexit__ = AsyncMock(return_value=None)
|
||||
mock_async_client.post = AsyncMock(
|
||||
side_effect=httpx.HTTPError("Connection error")
|
||||
)
|
||||
mock_async_client.post = AsyncMock(side_effect=httpx.HTTPError("Connection error"))
|
||||
|
||||
with patch("httpx.AsyncClient", return_value=mock_async_client):
|
||||
result = await client.introspect_token("test-token")
|
||||
@@ -216,9 +207,7 @@ class TestKeycloakAuthClient:
|
||||
assert result.is_valid is False
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_introspect_token_uses_cache(
|
||||
self, client: KeycloakAuthClient
|
||||
) -> None:
|
||||
async def test_introspect_token_uses_cache(self, client: KeycloakAuthClient) -> None:
|
||||
"""Test that token introspection uses cache."""
|
||||
mock_response = Mock()
|
||||
mock_response.json.return_value = {
|
||||
@@ -283,9 +272,7 @@ class TestKeycloakAuthClient:
|
||||
mock_async_client = AsyncMock()
|
||||
mock_async_client.__aenter__ = AsyncMock(return_value=mock_async_client)
|
||||
mock_async_client.__aexit__ = AsyncMock(return_value=None)
|
||||
mock_async_client.get = AsyncMock(
|
||||
side_effect=httpx.HTTPError("Connection error")
|
||||
)
|
||||
mock_async_client.get = AsyncMock(side_effect=httpx.HTTPError("Connection error"))
|
||||
|
||||
with patch("httpx.AsyncClient", return_value=mock_async_client):
|
||||
result = await client.get_userinfo("test-token")
|
||||
@@ -293,9 +280,7 @@ class TestKeycloakAuthClient:
|
||||
assert result is None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_introspect_token_no_realm_roles(
|
||||
self, client: KeycloakAuthClient
|
||||
) -> None:
|
||||
async def test_introspect_token_no_realm_roles(self, client: KeycloakAuthClient) -> None:
|
||||
"""Test introspection without realm_access roles."""
|
||||
mock_response = Mock()
|
||||
mock_response.json.return_value = {
|
||||
|
||||
@@ -129,10 +129,7 @@ class TestSettings:
|
||||
security=SecurityConfig(secret_key="test"),
|
||||
kc=KCConfig(client_secret="test"),
|
||||
)
|
||||
assert (
|
||||
s.database_url
|
||||
== "postgresql+asyncpg://admin:secret@db.example.com:5433/mydb"
|
||||
)
|
||||
assert s.database_url == "postgresql+asyncpg://admin:secret@db.example.com:5433/mydb"
|
||||
|
||||
def test_database_url_override(self) -> None:
|
||||
"""Test that explicit database URL overrides auto-building."""
|
||||
|
||||
Reference in New Issue
Block a user