feat: FastAPI-App mit API-Key- und Session-Auth
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
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
|
||||
from app.db import Base, get_session
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -15,3 +16,19 @@ def db():
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user