forked from sr2/cloud-api
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
"""
|
|
[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
|