Spaces:
Running

File size: 1,916 Bytes
cd61bf7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Tests for authentication endpoints."""
import pytest
from faker import Faker

fake = Faker()


@pytest.mark.unit
def test_health_check(client):
    """Test health check endpoint."""
    response = client.get("/health")
    assert response.status_code == 200
    data = response.json()
    assert data["status"] == "healthy"


@pytest.mark.unit
def test_register_missing_fields(client):
    """Test registration with missing required fields."""
    response = client.post("/api/v1/auth/register", json={})
    assert response.status_code == 422  # Validation error


@pytest.mark.unit
def test_register_weak_password(client, override_get_session):
    """Test registration with weak password."""
    response = client.post("/api/v1/auth/register", json={
        "email": fake.email(),
        "password": "weak",  # Too short
        "company_name": "Test Company"
    })
    assert response.status_code == 400
    assert "at least 8 characters" in response.json()["detail"].lower()


@pytest.mark.integration
async def test_register_success(client, override_get_session):
    """Test successful registration."""
    email = fake.email()
    response = client.post("/api/v1/auth/register", json={
        "email": email,
        "password": "SecurePass123!",
        "company_name": "Test Company",
        "full_name": "Test User"
    })
    
    assert response.status_code == 200
    data = response.json()
    assert "access_token" in data
    assert data["user"]["email"] == email
    assert "tenant_id" in data["user"]


@pytest.mark.unit
def test_login_invalid_credentials(client, override_get_session):
    """Test login with invalid credentials."""
    response = client.post("/api/v1/auth/login", json={
        "email": "nonexistent@example.com",
        "password": "WrongPassword123"
    })
    assert response.status_code == 401
    assert "invalid credentials" in response.json()["detail"].lower()