chore(quality): apply ruff autofixes and formatting (223 fixes, regression-free: 118/118 tests pass)
This commit is contained in:
+11
-26
@@ -3,9 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
from datetime import timedelta
|
||||
|
||||
import pytest
|
||||
from httpx import AsyncClient
|
||||
from jose import jwt
|
||||
|
||||
@@ -43,9 +41,7 @@ async def test_register_success(client: AsyncClient) -> None:
|
||||
# === FR-1.1 / Akzeptanzkriterium 2: register duplicate email ===
|
||||
|
||||
|
||||
async def test_register_duplicate_email(
|
||||
client: AsyncClient, registered_user: dict
|
||||
) -> None:
|
||||
async def test_register_duplicate_email(client: AsyncClient, registered_user: dict) -> None:
|
||||
"""AC #2: POST /api/v1/auth/register mit existierender Email → 409."""
|
||||
# registered_user already exists; trying again with same email (and 2nd user
|
||||
# would also be blocked by bootstrap). 409 is correct because of the email conflict.
|
||||
@@ -93,9 +89,7 @@ async def test_register_weak_password(client: AsyncClient) -> None:
|
||||
# === FR-1.2 / Akzeptanzkriterium 4: login success ===
|
||||
|
||||
|
||||
async def test_login_success(
|
||||
client: AsyncClient, registered_user: dict
|
||||
) -> None:
|
||||
async def test_login_success(client: AsyncClient, registered_user: dict) -> None:
|
||||
"""AC #4: POST /api/v1/auth/login mit korrekten Credentials → 200 + JWT."""
|
||||
resp = await client.post(
|
||||
"/api/v1/auth/login",
|
||||
@@ -114,9 +108,7 @@ async def test_login_success(
|
||||
# === FR-1.2 / Akzeptanzkriterium 5: login wrong password ===
|
||||
|
||||
|
||||
async def test_login_wrong_password(
|
||||
client: AsyncClient, registered_user: dict
|
||||
) -> None:
|
||||
async def test_login_wrong_password(client: AsyncClient, registered_user: dict) -> None:
|
||||
"""AC #5: POST /api/v1/auth/login mit falschem Passwort → 401."""
|
||||
resp = await client.post(
|
||||
"/api/v1/auth/login",
|
||||
@@ -203,12 +195,11 @@ async def test_db_user_has_hashed_password(
|
||||
) -> None:
|
||||
"""AC: DB-User wird mit gehashtem password_hash angelegt (kein Klartext)."""
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.models.user import User
|
||||
|
||||
async with session_factory() as session:
|
||||
result = await session.execute(
|
||||
select(User).where(User.email == registered_user["email"])
|
||||
)
|
||||
result = await session.execute(select(User).where(User.email == registered_user["email"]))
|
||||
user = result.scalar_one()
|
||||
# bcrypt hashes start with $2b$ (or $2a$ for passlib), never plain text
|
||||
assert user.password_hash.startswith("$"), (
|
||||
@@ -216,19 +207,17 @@ async def test_db_user_has_hashed_password(
|
||||
)
|
||||
assert user.password_hash != registered_user["password"]
|
||||
assert len(user.password_hash) > 50, (
|
||||
"Bcrypt hash should be ~60 chars long, got "
|
||||
f"{len(user.password_hash)}"
|
||||
f"Bcrypt hash should be ~60 chars long, got {len(user.password_hash)}"
|
||||
)
|
||||
|
||||
|
||||
# === Bonus: no default admin bootstrap on startup ===
|
||||
|
||||
|
||||
async def test_no_default_admin_on_startup(
|
||||
client: AsyncClient, session_factory
|
||||
) -> None:
|
||||
async def test_no_default_admin_on_startup(client: AsyncClient, session_factory) -> None:
|
||||
"""AC: KEIN admin/admin Bootstrap-User beim App-Start (Frisch-DB = leer)."""
|
||||
from sqlalchemy import select, func
|
||||
from sqlalchemy import func, select
|
||||
|
||||
from app.models.user import User
|
||||
|
||||
# Fresh DB → no users
|
||||
@@ -238,10 +227,6 @@ async def test_no_default_admin_on_startup(
|
||||
assert count == 0, f"Fresh DB should have 0 users, found {count}"
|
||||
|
||||
# Also check: no user with role=admin and well-known email
|
||||
result = await session.execute(
|
||||
select(User).where(User.role == "admin")
|
||||
)
|
||||
result = await session.execute(select(User).where(User.role == "admin"))
|
||||
admins = result.scalars().all()
|
||||
assert len(admins) == 0, (
|
||||
f"Fresh DB should have no admin users, found {len(admins)}"
|
||||
)
|
||||
assert len(admins) == 0, f"Fresh DB should have no admin users, found {len(admins)}"
|
||||
|
||||
Reference in New Issue
Block a user