Refactor code structure for improved readability and maintainability

This commit is contained in:
JSC
2025-07-27 14:24:11 +02:00
parent 0f605d7ed1
commit 2e87ff9927
8 changed files with 388 additions and 65 deletions

View File

@@ -62,9 +62,26 @@ async def test_session(test_engine: Any) -> AsyncGenerator[AsyncSession, None]:
@pytest_asyncio.fixture
async def test_app(test_session: AsyncSession) -> FastAPI:
async def test_app(test_session: AsyncSession):
"""Create a test FastAPI application."""
app = create_app()
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api import api_router
from app.middleware.logging import LoggingMiddleware
# Create FastAPI app directly for testing (without Socket.IO)
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:8001"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.add_middleware(LoggingMiddleware)
app.include_router(api_router)
# Override the database dependency
async def override_get_db() -> AsyncGenerator[AsyncSession, None]:
@@ -76,7 +93,7 @@ async def test_app(test_session: AsyncSession) -> FastAPI:
@pytest_asyncio.fixture
async def test_client(test_app: FastAPI) -> AsyncGenerator[AsyncClient, None]:
async def test_client(test_app) -> AsyncGenerator[AsyncClient, None]:
"""Create a test HTTP client."""
async with AsyncClient(
transport=ASGITransport(app=test_app),