Skip to content

Commit a24c47a

Browse files
committed
refactor: improve test_get_token by creating user before token request
1 parent 1188734 commit a24c47a

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

tests/api/test_auth.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,28 @@ async def test_add_user(client: AsyncClient):
3737

3838
# TODO: parametrize test with diff urls including 404 and 401
3939
async def test_get_token(client: AsyncClient):
40-
payload = {"email": "joe@grillazz.com", "password": "s1lly"}
40+
# First, create the user required for this test
41+
user_payload = {
42+
"email": "joe@grillazz.com",
43+
"first_name": "Joe",
44+
"last_name": "Garcia",
45+
"password": "s1lly",
46+
}
47+
create_user_response = await client.post("/user/", json=user_payload)
48+
assert create_user_response.status_code == status.HTTP_201_CREATED
49+
50+
# Now, request the token for the newly created user
51+
token_payload = {"email": "joe@grillazz.com", "password": "s1lly"}
4152
response = await client.post(
4253
"/user/token",
43-
data=payload,
54+
data=token_payload,
4455
headers={"Content-Type": "application/x-www-form-urlencoded"},
4556
)
4657
assert response.status_code == status.HTTP_201_CREATED
4758
claimset = jwt.decode(
4859
response.json()["access_token"], options={"verify_signature": False}
4960
)
50-
assert claimset["email"] == payload["email"]
61+
assert claimset["email"] == token_payload["email"]
5162
assert claimset["expiry"] == IsPositiveFloat()
5263
assert claimset["platform"] == "python-httpx/0.28.1"
5364

0 commit comments

Comments
 (0)