35 lines
973 B
Python
35 lines
973 B
Python
import pytest
|
|
from fastapi.testclient import TestClient
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import Session
|
|
from sqlalchemy.pool import StaticPool
|
|
|
|
from app.db import Base, get_session
|
|
|
|
|
|
@pytest.fixture
|
|
def db():
|
|
engine = create_engine(
|
|
"sqlite://", poolclass=StaticPool,
|
|
connect_args={"check_same_thread": False},
|
|
)
|
|
Base.metadata.create_all(engine)
|
|
with Session(engine) as session:
|
|
yield session
|
|
|
|
|
|
@pytest.fixture
|
|
def client(db, monkeypatch):
|
|
monkeypatch.setenv("FB_API_KEY", "test-key")
|
|
from app.config import get_settings
|
|
get_settings.cache_clear()
|
|
from app.auth import hash_password
|
|
monkeypatch.setenv("FB_GUI_PASSWORD_HASH", hash_password("geheim"))
|
|
get_settings.cache_clear()
|
|
from app.main import app
|
|
app.dependency_overrides[get_session] = lambda: iter([db])
|
|
with TestClient(app) as c:
|
|
yield c
|
|
app.dependency_overrides.clear()
|
|
get_settings.cache_clear()
|