Files
MABEA/backend/tests/test_auth.py
T
sysopsandClaude Sonnet 5 cedc39e075
CI / backend-tests (push) Failing after 2s
Sprint 0: FastAPI-Skeleton, vollständiges DB-Schema (Alembic), Auth (JWT/bcrypt), Rollen-Dependency, CI
- Vollständiges Ziel-Schema aus Prompt 20 als initiale Migration (inkl. Karte-13-Vorbereitung: UUID-PKs, systemknoten)
- Seed-Migration für Hauptserver-Datensatz (Sprintplan E6)
- JWT-Login + /auth/me, require_roles-Dependency (Prompt 05 Berechtigungsmatrix)
- Tests: health, login/me, Rollen-Ablehnung/-Zulassung (S0-Abnahmekriterien)
- Gitea-Actions-CI: install -> migrate -> pytest mit Coverage-Gate 50%

Nur Code/Config erzeugt, nicht lokal installiert oder ausgeführt (Deployment-Regel).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L85hmKbvX7Cqkq47KnQhFt
2026-09-03 22:32:54 +02:00

46 lines
1.3 KiB
Python

import pytest
@pytest.mark.asyncio
async def test_login_success(client, mitarbeiter_user):
response = await client.post(
"/api/v1/auth/login",
data={"username": "mitarbeiter1", "password": "test-passwort-123"},
)
assert response.status_code == 200
body = response.json()
assert body["token_type"] == "bearer"
assert body["access_token"]
@pytest.mark.asyncio
async def test_login_wrong_password(client, mitarbeiter_user):
response = await client.post(
"/api/v1/auth/login",
data={"username": "mitarbeiter1", "password": "falsch"},
)
assert response.status_code == 401
@pytest.mark.asyncio
async def test_me_requires_token(client):
response = await client.get("/api/v1/auth/me")
assert response.status_code == 401
@pytest.mark.asyncio
async def test_me_returns_current_user(client, mitarbeiter_user):
login_response = await client.post(
"/api/v1/auth/login",
data={"username": "mitarbeiter1", "password": "test-passwort-123"},
)
token = login_response.json()["access_token"]
response = await client.get(
"/api/v1/auth/me", headers={"Authorization": f"Bearer {token}"}
)
assert response.status_code == 200
body = response.json()
assert body["login"] == "mitarbeiter1"
assert body["rollen"] == ["mitarbeiter"]