Phase 1: Kern mit Plugin-System, Auth/Rollen, Migrations, Plugin-Stubs
- 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
This commit is contained in:
66
tests/test_auth.py
Normal file
66
tests/test_auth.py
Normal file
@@ -0,0 +1,66 @@
|
||||
"""Tests: Login/Logout und initialer Admin."""
|
||||
from __future__ import annotations
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from redaktionskern.auth.models import User
|
||||
|
||||
|
||||
def test_initialer_admin_wird_angelegt(app):
|
||||
with app.state.session_factory() as db:
|
||||
admin = db.scalar(select(User).where(User.username == "admin"))
|
||||
assert admin is not None
|
||||
assert admin.role == "admin"
|
||||
assert admin.active is True
|
||||
|
||||
|
||||
def test_login_seite_erreichbar(client):
|
||||
antwort = client.get("/login")
|
||||
assert antwort.status_code == 200
|
||||
assert "Anmelden" in antwort.text
|
||||
|
||||
|
||||
def test_geschuetzte_seite_leitet_anonym_zum_login(client):
|
||||
antwort = client.get("/", follow_redirects=False)
|
||||
assert antwort.status_code == 303
|
||||
assert antwort.headers["location"] == "/login"
|
||||
|
||||
|
||||
def test_login_falsches_passwort(client):
|
||||
antwort = client.post(
|
||||
"/login",
|
||||
data={"username": "admin", "password": "falsch"},
|
||||
follow_redirects=False,
|
||||
)
|
||||
assert antwort.status_code == 200
|
||||
assert "falsch" in antwort.text
|
||||
|
||||
|
||||
def test_login_unbekannter_benutzer(client):
|
||||
antwort = client.post(
|
||||
"/login",
|
||||
data={"username": "niemand", "password": "egal-egal-1"},
|
||||
follow_redirects=False,
|
||||
)
|
||||
assert antwort.status_code == 200
|
||||
assert "falsch" in antwort.text
|
||||
|
||||
|
||||
def test_login_erfolg_und_dashboard(client):
|
||||
from tests.conftest import melde_an
|
||||
|
||||
melde_an(client)
|
||||
antwort = client.get("/")
|
||||
assert antwort.status_code == 200
|
||||
assert "Willkommen" in antwort.text
|
||||
|
||||
|
||||
def test_logout(client):
|
||||
from tests.conftest import melde_an
|
||||
|
||||
melde_an(client)
|
||||
antwort = client.post("/logout", follow_redirects=False)
|
||||
assert antwort.status_code == 303
|
||||
assert antwort.headers["location"] == "/login"
|
||||
danach = client.get("/", follow_redirects=False)
|
||||
assert danach.status_code == 303 # wieder anonym
|
||||
Reference in New Issue
Block a user