- redaktionskern (src/): schlanker Kern — App-Fabrik, Plugin-Loader (Entry-Points + plugins/-Verzeichnis), Migrations-Laufzeit (schema_migrations pro Plugin, SQLite-/Postgres-portabel), Auth mit Argon2id + Session-Cookies, Rollen admin/redakteur/rezensent, Benutzerverwaltung für Admins - plugins/: 8 ladbare Stubs (neuheiten, dedup, planung, archiv, erinnerung, benachrichtigung, audit-log, export) nach Plugin-Vertrag - Frontend: Jinja2 + Tailwind (CDN) + HTMX + Alpine.js, UI deutsch - Tests: 28 pytest-Fälle (Loader, Lifecycle, Entry-Points, Migrations- Idempotenz, Login/Logout, Rollen-Zugriff, Benutzerverwaltung) - Docker/Podman: Compose (Traefik-Labels) + Dockerfile (uv) - README.md mit Setup-Anleitung
73 lines
1.9 KiB
Python
73 lines
1.9 KiB
Python
"""Gemeinsame Fixtures: App mit temporaerer SQLite-DB und TestClient."""
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import replace
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from redaktionskern.app import create_app
|
|
from redaktionskern.config import Settings
|
|
|
|
PROJEKT_WURZEL = Path(__file__).resolve().parents[1]
|
|
ADMIN_PASSWORD = "test-admin-123"
|
|
|
|
|
|
@pytest.fixture
|
|
def settings(tmp_path) -> Settings:
|
|
return Settings(
|
|
database_url=f"sqlite:///{tmp_path / 'test.db'}",
|
|
session_secret="test-secret",
|
|
initial_admin_password=ADMIN_PASSWORD,
|
|
plugins_dir=PROJEKT_WURZEL / "plugins",
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def settings_ohne_plugins(settings) -> Settings:
|
|
"""Nur Entry-Point-Plugins, kein plugins/-Verzeichnis."""
|
|
return replace(settings, plugins_dir=None)
|
|
|
|
|
|
@pytest.fixture
|
|
def app(settings):
|
|
return create_app(settings)
|
|
|
|
|
|
@pytest.fixture
|
|
def client(app) -> TestClient:
|
|
return TestClient(app)
|
|
|
|
|
|
def melde_an(
|
|
client: TestClient,
|
|
username: str = "admin",
|
|
password: str = ADMIN_PASSWORD,
|
|
):
|
|
"""Meldet einen Benutzer an und prueft die Weiterleitung."""
|
|
antwort = client.post(
|
|
"/login", data={"username": username, "password": password},
|
|
follow_redirects=False,
|
|
)
|
|
assert antwort.status_code == 303, f"Login fehlgeschlagen fuer {username}"
|
|
return antwort
|
|
|
|
|
|
def lege_benutzer_an(app, username: str, role: str, password: str = "test-12345678"):
|
|
"""Legt direkt per DB einen Benutzer an (fuer Rollen-Tests)."""
|
|
from redaktionskern.auth.models import User
|
|
from redaktionskern.auth.security import hash_password
|
|
|
|
with app.state.session_factory() as db:
|
|
db.add(
|
|
User(
|
|
username=username,
|
|
display_name=username.capitalize(),
|
|
password_hash=hash_password(password),
|
|
role=role,
|
|
active=True,
|
|
)
|
|
)
|
|
db.commit()
|