초기 커밋
This commit is contained in:
0
tests/integration/__init__.py
Normal file
0
tests/integration/__init__.py
Normal file
68
tests/integration/test_auth.py
Normal file
68
tests/integration/test_auth.py
Normal file
@@ -0,0 +1,68 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from httpx import AsyncClient
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.security import hash_password
|
||||
from app.models.mariadb.user import User, UserProfile
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_register(client: AsyncClient) -> None:
|
||||
response = await client.post(
|
||||
"/api/v1/auth/register",
|
||||
json={"email": "test@example.com", "password": "password123", "full_name": "Test User"},
|
||||
)
|
||||
assert response.status_code == 201
|
||||
data = response.json()
|
||||
assert "access_token" in data
|
||||
assert "refresh_token" in data
|
||||
assert data["token_type"] == "bearer"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_register_duplicate_email(client: AsyncClient) -> None:
|
||||
await client.post(
|
||||
"/api/v1/auth/register",
|
||||
json={"email": "dup@example.com", "password": "pass123"},
|
||||
)
|
||||
response = await client.post(
|
||||
"/api/v1/auth/register",
|
||||
json={"email": "dup@example.com", "password": "pass456"},
|
||||
)
|
||||
assert response.status_code == 409
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_login(client: AsyncClient, db_session: AsyncSession) -> None:
|
||||
user = User(email="login@example.com", hashed_password=hash_password("pass123"))
|
||||
db_session.add(user)
|
||||
await db_session.flush()
|
||||
profile = UserProfile(user_id=user.id, full_name="Login User")
|
||||
db_session.add(profile)
|
||||
await db_session.commit()
|
||||
|
||||
response = await client.post(
|
||||
"/api/v1/auth/login",
|
||||
json={"email": "login@example.com", "password": "pass123"},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "access_token" in data
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_login_wrong_password(client: AsyncClient, db_session: AsyncSession) -> None:
|
||||
user = User(email="wrong@example.com", hashed_password=hash_password("correct"))
|
||||
db_session.add(user)
|
||||
await db_session.flush()
|
||||
profile = UserProfile(user_id=user.id)
|
||||
db_session.add(profile)
|
||||
await db_session.commit()
|
||||
|
||||
response = await client.post(
|
||||
"/api/v1/auth/login",
|
||||
json={"email": "wrong@example.com", "password": "incorrect"},
|
||||
)
|
||||
assert response.status_code == 401
|
||||
13
tests/integration/test_health.py
Normal file
13
tests/integration/test_health.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_health_check(client: AsyncClient) -> None:
|
||||
response = await client.get("/api/v1/system/health")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["status"] == "ok"
|
||||
assert data["service"] == "core-api"
|
||||
Reference in New Issue
Block a user