add uni tests for user auth

This commit is contained in:
Jakub Miazek
2023-07-24 15:07:44 +02:00
parent 32346cd7e7
commit 89595175e6
5 changed files with 88 additions and 10 deletions

35
tests/api/test_auth.py Normal file
View File

@@ -0,0 +1,35 @@
import pytest
from httpx import AsyncClient
from starlette import status
import jwt
pytestmark = pytest.mark.anyio
# TODO: parametrize test with diff urls
async def test_add_user(client: AsyncClient):
payload = {
"email": "rancher@grassroots.com",
"first_name": "Joe",
"last_name": "Garcia",
"password": "s1lly"
}
response = await client.post("/user/", json=payload)
assert response.status_code == status.HTTP_201_CREATED
claimset = jwt.decode(response.json()["access_token"], options={"verify_signature": False})
assert claimset["email"] == payload["email"]
assert claimset["expiry"] > 0
assert claimset["platform"] == "python-httpx/0.24.1"
# TODO: parametrize test with diff urls including 404 and 401
async def test_get_token(client: AsyncClient):
payload = {"email": "rancher@grassroots.com", "password": "s1lly"}
response = await client.post("/user/token", json=payload)
assert response.status_code == status.HTTP_201_CREATED
claimset = jwt.decode(response.json()["access_token"], options={"verify_signature": False})
assert claimset["email"] == payload["email"]
assert claimset["expiry"] > 0
assert claimset["platform"] == "python-httpx/0.24.1"
# TODO: baerer token test > get token > test endpoint auth with token > expire token on redis > test endpoint auth with token

11
tests/api/test_health.py Normal file
View File

@@ -0,0 +1,11 @@
import pytest
from fastapi import status
from httpx import AsyncClient
pytestmark = pytest.mark.anyio
async def test_redis_health(client: AsyncClient):
response = await client.get(f"/public/health/redis")
assert response.status_code == status.HTTP_200_OK
# assert payload["name"] == response.json()["name"]
# assert UUID(response.json()["id"])