aee0f09db8
- Datafabrik: Dockerfile fix, agentorkestrering fungerar - Vision: Identify-modell, FAISS, OCR alla testade - API: Alla 7 integrationstester passerade - Upplösare: Entitetsupplösning verifierad
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
"""Tester för auth-endpoints."""
|
|
import pytest
|
|
from httpx import AsyncClient
|
|
|
|
from app.models import User
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_login_success(client: AsyncClient, test_user: User):
|
|
response = await client.post("/api/v1/auth/login", json={
|
|
"email": test_user.email,
|
|
"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"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_login_wrong_password(client: AsyncClient, test_user: User):
|
|
response = await client.post("/api/v1/auth/login", json={
|
|
"email": test_user.email,
|
|
"password": "wrongpassword",
|
|
})
|
|
assert response.status_code == 401
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_me_endpoint(client: AsyncClient, admin_token: str, test_user: User):
|
|
response = await client.get("/api/v1/auth/me", headers={"Authorization": f"Bearer {admin_token}"})
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["email"] == test_user.email
|
|
assert data["role"] == "admin"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_refresh_token(client: AsyncClient, admin_token: str):
|
|
# Hämta refresh token via login
|
|
response = await client.post("/api/v1/auth/login", json={
|
|
"email": "admin@landvex.se",
|
|
"password": "password123",
|
|
})
|
|
refresh = response.json()["refresh_token"]
|
|
|
|
response = await client.post("/api/v1/auth/refresh", json={"refresh_token": refresh})
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert "access_token" in data
|