25 lines
910 B
Python
25 lines
910 B
Python
from __future__ import annotations
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
from services.api.app import app
|
|
|
|
|
|
def test_register_and_login() -> None:
|
|
with TestClient(app) as client:
|
|
response = client.post("/api/auth/register", json={"username": "alice", "password": "secret"})
|
|
assert response.status_code == 200
|
|
token = response.json().get("token")
|
|
assert token
|
|
|
|
response = client.post("/api/auth/login", json={"username": "alice", "password": "secret"})
|
|
assert response.status_code == 200
|
|
|
|
|
|
def test_register_duplicate() -> None:
|
|
with TestClient(app) as client:
|
|
response = client.post("/api/auth/register", json={"username": "bob", "password": "secret"})
|
|
assert response.status_code == 200
|
|
response = client.post("/api/auth/register", json={"username": "bob", "password": "secret"})
|
|
assert response.status_code == 400
|