Spaces:
Running
Running
Download backend/tests/test_auth.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 1.92 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/tests/test_auth.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/tests/test_auth.py
-
curl -L -o test_auth.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/tests/test_auth.py
1.92 kB
| """Tests for authentication endpoints.""" | |
| import pytest | |
| from faker import Faker | |
| fake = Faker() | |
| 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" | |
| 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 | |
| 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() | |
| 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"] | |
| 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() | |