File size: 810 Bytes
4a91ea9 | 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 | from fastapi.testclient import TestClient
import time
def test_register_user(client: TestClient):
# Use timestamp to ensure unique email
email = f"newuser{int(time.time())}@example.com"
response = client.post(
"/api/v1/auth/register",
json={"email": email, "password": "newpassword"},
)
assert response.status_code == 201
def test_login_user(client: TestClient):
email = f"loginuser{int(time.time())}@example.com"
client.post(
"/api/v1/auth/register",
json={"email": email, "password": "loginpassword"},
)
response = client.post(
"/api/v1/auth/login",
json={"email": email, "password": "loginpassword"},
)
assert response.status_code == 200
assert "token" in response.json()
assert "user" in response.json()
|