Skip to content

Commit

Permalink
fix(test): fake test with sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
valeeraZ committed Feb 14, 2024
1 parent 63435f4 commit 64466ed
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Settings(BaseSettings):
db_echo: bool = False

# openai api key
openai_api_key: str = ""
OPENAI_API_KEY: str = ""

@property
def db_url(self) -> URL:
Expand Down
27 changes: 25 additions & 2 deletions api/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
from typing import Generator

import pytest
from fastapi import FastAPI
from sqlalchemy import create_engine, StaticPool
from sqlalchemy.orm import sessionmaker
from starlette.testclient import TestClient

from api.web.application import get_app
from api.web.api import api_router


def get_test_app() -> FastAPI:
app = FastAPI()

SQLALCHEMY_DATABASE_URL = "sqlite://"

engine = create_engine(
SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False},
poolclass=StaticPool,
)
TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

app.state.db_engine = engine
app.state.db_session_factory = TestingSessionLocal
# noqa: F821
app.include_router(router=api_router, prefix="/api")

return app


@pytest.fixture(scope="session")
def client() -> Generator[TestClient, None, None]:
with TestClient(get_app()) as c:
with TestClient(get_test_app()) as c:
yield c

0 comments on commit 64466ed

Please sign in to comment.