tests: user router
This commit is contained in:
parent
19145271ae
commit
79f8104f2f
1 changed files with 50 additions and 0 deletions
50
test/test_user.py
Normal file
50
test/test_user.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
"""
|
||||
[GET]/user/self/claims is not tested because it requires OIDC authentication.
|
||||
[DELETE/user/ is not tested because the testing client cannot attach a body to a delete request.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from httpx import AsyncClient
|
||||
|
||||
from .conftest import client
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_get_self_db(client: AsyncClient):
|
||||
resp = await client.get("/user/self/db")
|
||||
data = resp.json()
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert data["first_name"] == "Admin"
|
||||
assert data["last_name"] == "Test"
|
||||
assert data["email"] == "admin@test.com"
|
||||
assert "organisations" in data
|
||||
assert "groups" in data
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_get_user_success(client: AsyncClient):
|
||||
resp = await client.get("/user/?user_id=1")
|
||||
data = resp.json()
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert data["first_name"] == "Admin"
|
||||
assert data["last_name"] == "Test"
|
||||
assert data["email"] == "admin@test.com"
|
||||
assert "organisations" in data
|
||||
assert "groups" in data
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@pytest.mark.parametrize(
|
||||
"query, expected_status",
|
||||
[
|
||||
("user_id=1", 200),
|
||||
("user_id=2", 404),
|
||||
("user_id=banana", 422),
|
||||
("", 422),
|
||||
],
|
||||
)
|
||||
async def test_get_user_fail(client: AsyncClient, query: str, expected_status: int):
|
||||
resp = await client.get(f"/user/?{query}")
|
||||
|
||||
assert resp.status_code == expected_status
|
||||
Loading…
Add table
Add a link
Reference in a new issue