Refactor code structure for improved readability and maintainability
Some checks failed
Backend CI / lint (push) Failing after 4m51s
Backend CI / test (push) Failing after 4m35s

This commit is contained in:
JSC
2025-08-20 11:37:28 +02:00
parent 9653062003
commit 821093f64f
15 changed files with 1897 additions and 217 deletions

View File

@@ -16,8 +16,19 @@ from sqlmodel.ext.asyncio.session import AsyncSession
from app.api import api_router
from app.core.database import get_db
from app.middleware.logging import LoggingMiddleware
# Import all models to ensure SQLAlchemy relationships are properly resolved
from app.models.credit_action import CreditAction # noqa: F401
from app.models.credit_transaction import CreditTransaction # noqa: F401
from app.models.extraction import Extraction # noqa: F401
from app.models.favorite import Favorite # noqa: F401
from app.models.plan import Plan
from app.models.playlist import Playlist # noqa: F401
from app.models.playlist_sound import PlaylistSound # noqa: F401
from app.models.sound import Sound # noqa: F401
from app.models.sound_played import SoundPlayed # noqa: F401
from app.models.user import User
from app.models.user_oauth import UserOauth # noqa: F401
from app.utils.auth import JWTUtils, PasswordUtils
@@ -48,7 +59,7 @@ async def test_engine() -> Any:
@pytest_asyncio.fixture
async def test_session(test_engine: Any) -> AsyncGenerator[AsyncSession, None]:
async def test_session(test_engine: Any) -> AsyncGenerator[AsyncSession]:
"""Create a test database session."""
connection = await test_engine.connect()
transaction = await connection.begin()
@@ -80,7 +91,7 @@ async def test_app(test_session: AsyncSession) -> FastAPI:
app.include_router(api_router)
# Override the database dependency
async def override_get_db() -> AsyncGenerator[AsyncSession, None]:
async def override_get_db() -> AsyncGenerator[AsyncSession]:
yield test_session
app.dependency_overrides[get_db] = override_get_db
@@ -89,7 +100,7 @@ async def test_app(test_session: AsyncSession) -> FastAPI:
@pytest_asyncio.fixture
async def test_client(test_app) -> AsyncGenerator[AsyncClient, None]:
async def test_client(test_app) -> AsyncGenerator[AsyncClient]:
"""Create a test HTTP client."""
async with AsyncClient(
transport=ASGITransport(app=test_app),
@@ -102,7 +113,7 @@ async def test_client(test_app) -> AsyncGenerator[AsyncClient, None]:
async def authenticated_client(
test_app: FastAPI,
auth_cookies: dict[str, str],
) -> AsyncGenerator[AsyncClient, None]:
) -> AsyncGenerator[AsyncClient]:
"""Create a test HTTP client with authentication cookies."""
async with AsyncClient(
transport=ASGITransport(app=test_app),
@@ -116,7 +127,7 @@ async def authenticated_client(
async def authenticated_admin_client(
test_app: FastAPI,
admin_cookies: dict[str, str],
) -> AsyncGenerator[AsyncClient, None]:
) -> AsyncGenerator[AsyncClient]:
"""Create a test HTTP client with admin authentication cookies."""
async with AsyncClient(
transport=ASGITransport(app=test_app),