prod: UI Optimisée mise en production
- Documentation archivée et réorganisée - Backend: Ajout tests, migrations, library service, rate limiting - Frontend: Suppression Flutter, focus sur interface web HTML/JS - Tailwind CSS ajouté pour le style - Améliorations UX et corrections bugs Generated with [Claude Code](https://claude.com/claude-code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
"""Test authentication endpoints."""
|
||||
import pytest
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
class TestAuthEndpoints:
|
||||
"""Tests for /api/v1/auth/* endpoints."""
|
||||
|
||||
async def test_register_user(self, client: AsyncClient):
|
||||
"""Test user registration."""
|
||||
response = await client.post(
|
||||
"/api/v1/auth/register",
|
||||
json={
|
||||
"email": "newuser@example.com",
|
||||
"username": "newuser",
|
||||
"password": "password123",
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "access_token" in data
|
||||
assert "refresh_token" in data
|
||||
assert data["token_type"] == "bearer"
|
||||
|
||||
async def test_register_duplicate_email(self, client: AsyncClient):
|
||||
"""Test registration with duplicate email."""
|
||||
# First registration
|
||||
await client.post(
|
||||
"/api/v1/auth/register",
|
||||
json={
|
||||
"email": "duplicate@example.com",
|
||||
"username": "user1",
|
||||
"password": "password123",
|
||||
},
|
||||
)
|
||||
|
||||
# Second registration with same email
|
||||
response = await client.post(
|
||||
"/api/v1/auth/register",
|
||||
json={
|
||||
"email": "duplicate@example.com",
|
||||
"username": "user2",
|
||||
"password": "password123",
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 400
|
||||
|
||||
async def test_login_success(self, client: AsyncClient):
|
||||
"""Test successful login."""
|
||||
# Register first
|
||||
await client.post(
|
||||
"/api/v1/auth/register",
|
||||
json={
|
||||
"email": "login@example.com",
|
||||
"username": "loginuser",
|
||||
"password": "password123",
|
||||
},
|
||||
)
|
||||
|
||||
# Login
|
||||
response = await client.post(
|
||||
"/api/v1/auth/login",
|
||||
json={
|
||||
"email": "login@example.com",
|
||||
"password": "password123",
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "access_token" in data
|
||||
assert "refresh_token" in data
|
||||
|
||||
async def test_login_wrong_password(self, client: AsyncClient):
|
||||
"""Test login with wrong password."""
|
||||
# Register first
|
||||
await client.post(
|
||||
"/api/v1/auth/register",
|
||||
json={
|
||||
"email": "wrongpass@example.com",
|
||||
"username": "wronguser",
|
||||
"password": "password123",
|
||||
},
|
||||
)
|
||||
|
||||
# Login with wrong password
|
||||
response = await client.post(
|
||||
"/api/v1/auth/login",
|
||||
json={
|
||||
"email": "wrongpass@example.com",
|
||||
"password": "wrongpassword",
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 401
|
||||
|
||||
async def test_get_current_user(self, client: AsyncClient, auth_headers: dict):
|
||||
"""Test getting current user info."""
|
||||
response = await client.get("/api/v1/auth/me", headers=auth_headers)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["email"] == "test@example.com"
|
||||
assert data["username"] == "testuser"
|
||||
|
||||
async def test_get_current_user_unauthorized(self, client: AsyncClient):
|
||||
"""Test getting current user without auth."""
|
||||
response = await client.get("/api/v1/auth/me")
|
||||
|
||||
assert response.status_code == 401
|
||||
Reference in New Issue
Block a user