fitAI / backend /tests /test_auth.py
FitAI Dev
feat: add jwt auth, schemas, and router structure
027cadc
Raw History Blame Contribute Delete
1.77 kB
from tests.conftest import client as _client # noqa: register overrides
def test_register(client):
res = client.post("/auth/register", json={"email": "a@test.com", "password": "pass123"})
assert res.status_code == 200
assert "access_token" in res.json()
def test_register_duplicate(client):
client.post("/auth/register", json={"email": "dup@test.com", "password": "pass"})
res = client.post("/auth/register", json={"email": "dup@test.com", "password": "pass"})
assert res.status_code == 400
def test_login(client):
client.post("/auth/register", json={"email": "login@test.com", "password": "secret"})
res = client.post("/auth/login", json={"email": "login@test.com", "password": "secret"})
assert res.status_code == 200
assert "access_token" in res.json()
def test_login_wrong_password(client):
client.post("/auth/register", json={"email": "wp@test.com", "password": "correct"})
res = client.post("/auth/login", json={"email": "wp@test.com", "password": "wrong"})
assert res.status_code == 401
def test_me(client):
reg = client.post("/auth/register", json={"email": "me@test.com", "password": "pass"})
token = reg.json()["access_token"]
res = client.get("/auth/me", headers={"Authorization": f"Bearer {token}"})
assert res.status_code == 200
assert res.json()["email"] == "me@test.com"
def test_update_persona(client):
reg = client.post("/auth/register", json={"email": "persona@test.com", "password": "pass"})
token = reg.json()["access_token"]
headers = {"Authorization": f"Bearer {token}"}
res = client.patch("/auth/me/persona", json={"coach_persona": "strict"}, headers=headers)
assert res.status_code == 200
assert res.json()["coach_persona"] == "strict"