Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user