Some checks failed
ci / lint_and_test (push) Failing after 8s
New assertions added for new data being delivered (eg IDs on endpoints not previously serving IDs)
113 lines
3 KiB
Python
113 lines
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 generate_query_and_status
|
|
|
|
|
|
pytestmark = [
|
|
pytest.mark.user_module,
|
|
]
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_get_self_db_success(default_client: AsyncClient):
|
|
resp = await default_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 isinstance(data["organisations"], list)
|
|
assert "groups" in data
|
|
assert isinstance(data["groups"], dict)
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_get_user_success(default_client: AsyncClient):
|
|
resp = await default_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 isinstance(data["organisations"], list)
|
|
assert "groups" in data
|
|
assert isinstance(data["groups"], dict)
|
|
|
|
|
|
@pytest.mark.anyio
|
|
@pytest.mark.parametrize(
|
|
"query, expected_status", generate_query_and_status(["user_id"])
|
|
)
|
|
async def test_get_user_status_checks(
|
|
default_client: AsyncClient, query: str, expected_status: int
|
|
):
|
|
resp = await default_client.get(f"/user/?{query}")
|
|
|
|
assert resp.status_code == expected_status
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_delete_user_success(default_client: AsyncClient):
|
|
resp = await default_client.delete("/user/?user_id=1")
|
|
|
|
assert resp.status_code == 204
|
|
|
|
|
|
@pytest.mark.anyio
|
|
async def test_post_user_invitation_success(default_client: AsyncClient):
|
|
body = {"user_email": "admin@test.com", "organisation_id": 1}
|
|
resp = await default_client.post("/user/invitation", json=body)
|
|
|
|
assert resp.status_code == 200
|
|
assert resp.json() == "Invitation sent"
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"body, expected_status",
|
|
[
|
|
({"organisation_id": 42, "user_email": "admin@test.com"}, 404),
|
|
({"organisation_id": "Test Org", "user_email": "admin@test.com"}, 422),
|
|
({"organisation_id": "", "user_email": "admin@test.com"}, 422),
|
|
({}, 422),
|
|
({"user_email": 42}, 422),
|
|
({"organisation_id": 1, "user_email": "Test User"}, 422),
|
|
],
|
|
)
|
|
@pytest.mark.anyio
|
|
async def test_post_user_invitation_status_checks(
|
|
default_client: AsyncClient, body, expected_status
|
|
):
|
|
resp = await default_client.post("/user/invitation", json=body)
|
|
|
|
assert resp.status_code == expected_status
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"body, expected_status",
|
|
[
|
|
({"jwt": "invalid"}, 401),
|
|
({"jwt": ""}, 401),
|
|
({"jwt": None}, 422),
|
|
({"jwt": 42}, 422),
|
|
],
|
|
)
|
|
@pytest.mark.anyio
|
|
async def test_post_user_invitation_accept_status_checks(
|
|
default_client: AsyncClient, body, expected_status
|
|
):
|
|
resp = await default_client.post("/user/invitation/accept", json=body)
|
|
|
|
assert resp.status_code == expected_status
|
|
|
|
if resp.status_code == 401:
|
|
assert resp.json()["detail"] == "Invalid JWS"
|