Skip to content

Commit

Permalink
🦄 refactor: Add database initialization in session fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
AndPuQing committed Feb 16, 2024
1 parent 03fb4d7 commit c96469b
Showing 1 changed file with 3 additions and 27 deletions.
30 changes: 3 additions & 27 deletions backend/app/app/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from sqlmodel import Session, SQLModel, create_engine

from app.core.config import settings
from app.db.init_db import init_db
from app.web.api.deps import get_db
from app.web.application import get_app

Expand All @@ -13,7 +14,9 @@ def session_fixture():
f"postgresql+psycopg://{settings.POSTGRES_USER}:{settings.POSTGRES_PASSWORD}@bemore-db/{settings.POSTGRES_DB}",
)
SQLModel.metadata.create_all(engine)

with Session(engine) as session:
init_db(session)
yield session


Expand All @@ -38,30 +41,3 @@ def get_session_override():
client = AsyncClient(app=app, base_url="http://localhost:8000")
yield client
app.dependency_overrides.clear()


# @pytest.fixture()
# def fastapi_app() -> FastAPI:
# """
# Fixture for creating FastAPI app.

# :return: fastapi app with mocked dependencies.
# """
# application = get_app()
# return application # noqa: WPS331


# @pytest.fixture(name="client")
# async def client_fixture(
# fastapi_app: FastAPI,
# ) -> AsyncGenerator[AsyncClient, None]:
# """
# Fixture that creates client for requesting server.

# :param fastapi_app: the application.
# :yield: client for the app.
# """
# async with AsyncClient(
# app=fastapi_app, base_url="http://localhost:8000"
# ) as ac:
# yield ac

0 comments on commit c96469b

Please sign in to comment.