54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
async def test_login_success(client, test_user):
|
|
resp = await client.post(
|
|
"/api/v1/auth/login",
|
|
json={"email": test_user.email, "password": test_user._plain_password},
|
|
)
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert "access_token" in data
|
|
assert "refresh_token" in data
|
|
assert data["token_type"] == "bearer"
|
|
|
|
|
|
async def test_login_wrong_password(client, test_user):
|
|
resp = await client.post(
|
|
"/api/v1/auth/login",
|
|
json={"email": test_user.email, "password": "wrongpassword"},
|
|
)
|
|
assert resp.status_code == 401
|
|
|
|
|
|
async def test_login_unknown_email(client):
|
|
resp = await client.post(
|
|
"/api/v1/auth/login",
|
|
json={"email": "nobody@example.com", "password": "irrelevant"},
|
|
)
|
|
assert resp.status_code == 401
|
|
|
|
|
|
async def test_me(client, auth_headers):
|
|
resp = await client.get("/api/v1/auth/me", headers=auth_headers)
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert "email" in data
|
|
|
|
|
|
async def test_me_unauthenticated(client):
|
|
resp = await client.get("/api/v1/auth/me")
|
|
assert resp.status_code == 401
|
|
|
|
|
|
async def test_token_refresh(client, test_user):
|
|
login = await client.post(
|
|
"/api/v1/auth/login",
|
|
json={"email": test_user.email, "password": test_user._plain_password},
|
|
)
|
|
refresh_token = login.json()["refresh_token"]
|
|
|
|
resp = await client.post(
|
|
"/api/v1/auth/refresh",
|
|
json={"refresh_token": refresh_token},
|
|
)
|
|
assert resp.status_code == 200
|
|
assert "access_token" in resp.json()
|