TT-006: stabilize architecture and add quality gates

This commit is contained in:
2026-08-10 12:05:24 +03:00
parent a8102da85d
commit 384906413b
12 changed files with 3340 additions and 0 deletions
+83
View File
@@ -0,0 +1,83 @@
"""Authentication tests."""
import pytest
def test_login_success(client, admin_user):
"""Test successful login."""
response = client.post("/api/v1/auth/login", json={
"email": "admin@test.com",
"password": "admin123"
})
assert response.status_code == 200
data = response.json()
assert "access_token" in data
assert data["user"]["email"] == "admin@test.com"
def test_login_invalid_password(client, admin_user):
"""Test login with invalid password."""
response = client.post("/api/v1/auth/login", json={
"email": "admin@test.com",
"password": "wrongpassword"
})
assert response.status_code == 401
def test_login_nonexistent_user(client):
"""Test login with nonexistent user."""
response = client.post("/api/v1/auth/login", json={
"email": "nonexistent@test.com",
"password": "password"
})
assert response.status_code == 401
def test_auth_me_authenticated(client, admin_token):
"""Test /auth/me with valid token."""
response = client.get("/api/v1/auth/me", headers={
"Authorization": f"Bearer {admin_token}"
})
assert response.status_code == 200
data = response.json()
assert data["email"] == "admin@test.com"
assert "permissions" in data
assert isinstance(data["permissions"], list)
def test_auth_me_unauthenticated(client):
"""Test /auth/me without token."""
response = client.get("/api/v1/auth/me")
assert response.status_code == 403 # HTTPBearer returns 403
def test_auth_me_invalid_token(client):
"""Test /auth/me with invalid token."""
response = client.get("/api/v1/auth/me", headers={
"Authorization": "Bearer invalid_token_here"
})
assert response.status_code == 401
def test_register_success(client):
"""Test successful registration."""
response = client.post("/api/v1/auth/register", json={
"email": "new@test.com",
"password": "newpass123",
"first_name": "New",
"last_name": "User"
})
assert response.status_code == 201
data = response.json()
assert data["email"] == "new@test.com"
def test_register_duplicate_email(client, admin_user):
"""Test registration with existing email."""
response = client.post("/api/v1/auth/register", json={
"email": "admin@test.com",
"password": "password",
"first_name": "Dup",
"last_name": "User"
})
assert response.status_code == 409