feat: datenmodell für benutzer, sessions und login-versuche
- Tabellen users, sessions, login_attempts (Migration 0002) - UTCDateTime speichert UTC in SQLite und liefert aware datetimes - Tests legen das Schema über die echten Migrationen an - Test prüft, dass Migrationen und Modelle übereinstimmen Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d9b7baf788
commit
d4cf8bdddd
12 files changed
+283
-11
No files matched your search
@@ -1,11 +1,17 @@
|
||||
from collections.abc import Iterator
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from alembic import command
|
||||
from alembic.config import Config
|
||||
from fastapi.testclient import TestClient
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.config import get_settings
|
||||
from app.db import _session_factory, get_engine
|
||||
|
||||
BACKEND_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
def _clear_caches() -> None:
|
||||
get_settings.cache_clear()
|
||||
@@ -22,15 +28,32 @@ def static_dir(tmp_path):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(tmp_path, static_dir, monkeypatch) -> Iterator[TestClient]:
|
||||
def app_env(tmp_path, static_dir, monkeypatch) -> Iterator[None]:
|
||||
"""Isolated settings and a migrated database for one test."""
|
||||
monkeypatch.setenv("DATA_DIR", str(tmp_path / "data"))
|
||||
monkeypatch.setenv("STATIC_DIR", str(static_dir))
|
||||
monkeypatch.setenv("ALLOWED_ORIGINS", "https://testserver")
|
||||
monkeypatch.delenv("INITIAL_ADMIN_USERNAME", raising=False)
|
||||
monkeypatch.delenv("INITIAL_ADMIN_PASSWORD", raising=False)
|
||||
_clear_caches()
|
||||
command.upgrade(Config(str(BACKEND_DIR / "alembic.ini")), "head")
|
||||
|
||||
from app.main import create_app
|
||||
|
||||
with TestClient(create_app()) as test_client:
|
||||
yield test_client
|
||||
yield
|
||||
|
||||
get_engine().dispose()
|
||||
_clear_caches()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def db(app_env) -> Iterator[Session]:
|
||||
with _session_factory()() as session:
|
||||
yield session
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(app_env) -> Iterator[TestClient]:
|
||||
from app.main import create_app
|
||||
|
||||
# https so that Secure cookies are sent back by the test client
|
||||
with TestClient(create_app(), base_url="https://testserver") as test_client:
|
||||
yield test_client
|
||||
@@ -0,0 +1,12 @@
|
||||
from alembic.autogenerate import compare_metadata
|
||||
from alembic.migration import MigrationContext
|
||||
|
||||
from app.db import get_engine
|
||||
from app.models import Base
|
||||
|
||||
|
||||
def test_migrations_match_models(app_env):
|
||||
with get_engine().connect() as conn:
|
||||
diff = compare_metadata(MigrationContext.configure(conn), Base.metadata)
|
||||
|
||||
assert diff == []
|
||||
Reference in new issue
Block a user