2026-01-25 18:01:48 +01:00

72 lines
1.8 KiB
Python

"""Test authentication"""
import pytest
from fastapi import status
def test_user_registration(client):
"""Test user registration"""
response = client.post(
"/api/v1/auth/register",
json={
"email": "test@example.com",
"username": "testuser",
"password": "SecurePass123",
"full_name": "Test User"
}
)
assert response.status_code == status.HTTP_200_OK
assert response.json()["email"] == "test@example.com"
assert response.json()["username"] == "testuser"
def test_duplicate_user_registration(client):
"""Test duplicate registration fails"""
# Register first time
client.post(
"/api/v1/auth/register",
json={
"email": "test@example.com",
"username": "testuser",
"password": "SecurePass123",
}
)
# Try to register again
response = client.post(
"/api/v1/auth/register",
json={
"email": "test@example.com",
"username": "testuser",
"password": "DifferentPass123",
}
)
assert response.status_code == status.HTTP_400_BAD_REQUEST
def test_user_login(client):
"""Test user login"""
# Register
client.post(
"/api/v1/auth/register",
json={
"email": "test@example.com",
"username": "testuser",
"password": "SecurePass123",
}
)
# Login
response = client.post(
"/api/v1/auth/login",
json={
"email": "test@example.com",
"password": "SecurePass123",
}
)
assert response.status_code == status.HTTP_200_OK
assert "access_token" in response.json()
assert response.json()["token_type"] == "bearer"