A previous `git pull --rebase origin main` dropped 177 local commits,
losing 3400+ files across admin-v2, backend, studio-v2, website,
klausur-service, and many other services. The partial restore attempt
(660295e2) only recovered some files.
This commit restores all missing files from pre-rebase ref 98933f5e
while preserving post-rebase additions (night-scheduler, night-mode UI,
NightModeWidget dashboard integration).
Restored features include:
- AI Module Sidebar (FAB), OCR Labeling, OCR Compare
- GPU Dashboard, RAG Pipeline, Magic Help
- Klausur-Korrektur (8 files), Abitur-Archiv (5+ files)
- Companion, Zeugnisse-Crawler, Screen Flow
- Full backend, studio-v2, website, klausur-service
- All compliance SDKs, agent-core, voice-service
- CI/CD configs, documentation, scripts
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
107 lines
2.8 KiB
Python
107 lines
2.8 KiB
Python
"""
|
|
Pytest Fixtures für Alerts Agent Tests.
|
|
|
|
Stellt eine SQLite In-Memory Datenbank für Tests bereit.
|
|
Verwendet StaticPool damit alle Connections dieselbe DB sehen.
|
|
"""
|
|
import pytest
|
|
from sqlalchemy import create_engine, event
|
|
from sqlalchemy.orm import sessionmaker
|
|
from sqlalchemy.pool import StaticPool
|
|
from fastapi import FastAPI
|
|
from fastapi.testclient import TestClient
|
|
|
|
# Import der Basis und Modelle - WICHTIG: Modelle müssen vor create_all importiert werden
|
|
from classroom_engine.database import Base
|
|
# Import aller Modelle damit sie bei Base registriert werden
|
|
from alerts_agent.db import models as alerts_models # noqa: F401
|
|
from alerts_agent.api.routes import router
|
|
|
|
|
|
# SQLite In-Memory für Tests mit StaticPool (dieselbe Connection für alle)
|
|
SQLALCHEMY_TEST_DATABASE_URL = "sqlite:///:memory:"
|
|
|
|
test_engine = create_engine(
|
|
SQLALCHEMY_TEST_DATABASE_URL,
|
|
connect_args={"check_same_thread": False},
|
|
poolclass=StaticPool, # Wichtig: Gleiche DB für alle Connections
|
|
)
|
|
|
|
|
|
@event.listens_for(test_engine, "connect")
|
|
def set_sqlite_pragma(dbapi_connection, connection_record):
|
|
"""SQLite Foreign Key Constraints aktivieren."""
|
|
cursor = dbapi_connection.cursor()
|
|
cursor.execute("PRAGMA foreign_keys=ON")
|
|
cursor.close()
|
|
|
|
|
|
TestSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=test_engine)
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def test_db():
|
|
"""
|
|
Erstellt eine frische Test-Datenbank für jeden Test.
|
|
"""
|
|
# Tabellen erstellen
|
|
Base.metadata.create_all(bind=test_engine)
|
|
|
|
db = TestSessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|
|
# Tabellen nach dem Test löschen
|
|
Base.metadata.drop_all(bind=test_engine)
|
|
|
|
|
|
def override_get_db():
|
|
"""Test-Database-Dependency - verwendet dieselbe Engine."""
|
|
db = TestSessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def client(test_db):
|
|
"""
|
|
TestClient mit überschriebener Datenbank-Dependency.
|
|
"""
|
|
from alerts_agent.db.database import get_db
|
|
|
|
app = FastAPI()
|
|
app.include_router(router, prefix="/api")
|
|
|
|
# Dependency Override
|
|
app.dependency_overrides[get_db] = override_get_db
|
|
|
|
with TestClient(app) as test_client:
|
|
yield test_client
|
|
|
|
# Cleanup
|
|
app.dependency_overrides.clear()
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_alert_data():
|
|
"""Beispieldaten für Alert-Tests."""
|
|
return {
|
|
"title": "Neue Inklusions-Richtlinie",
|
|
"url": "https://example.com/inklusion",
|
|
"snippet": "Das Kultusministerium hat neue Richtlinien...",
|
|
"topic_label": "Inklusion Bayern",
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def sample_feedback_data():
|
|
"""Beispieldaten für Feedback-Tests."""
|
|
return {
|
|
"is_relevant": True,
|
|
"reason": "Sehr relevant für Schulen",
|
|
"tags": ["wichtig", "inklusion"],
|
|
}
|