tests: dynamic test structure

Issue: #23
This commit is contained in:
Chris Milne 2026-06-10 12:28:25 +01:00
parent bdba903db1
commit 5a433dfe41
2 changed files with 69 additions and 23 deletions

View file

@ -5,6 +5,7 @@
import pytest
from httpx import AsyncClient
from fastapi.routing import APIRoute
from .conftest import generate_query_and_status
@ -143,3 +144,51 @@ async def test_get_self_orgs_success(default_client: AsyncClient):
assert isinstance(org["security_contact"], dict)
assert org["security_contact"]["email"] == "security@test.org"
assert org["security_contact"]["id"] == 3
@pytest.mark.anyio
async def test_get_self_orgs_dynamic(default_client: AsyncClient):
method = "GET"
path = "/user/self/orgs"
expected_data = {
"organisations": [
{
"organisation_id": 1,
"name": "Test Org",
"status": "approved",
"root_user_email": "admin@test.com",
"owner_contact": {"email": "owner@test.org", "id": 2},
"security_contact": {"email": "security@test.org", "id": 3},
"billing_contact": {"email": "billing@test.org", "id": 1},
"intake_questionnaire": {
"question_one": None,
"question_three": None,
"question_two": "answer two",
},
}
]
}
resp = await default_client.get(path)
route = next(
route
for route in default_client._transport.app.routes
if isinstance(route, APIRoute)
and path in route.path
and method in route.methods
)
assert resp.status_code == route.status_code
if route.status_code == 204:
return
expected_response_schema = route.response_model
data = resp.json()
response_model = expected_response_schema(**data)
assert isinstance(response_model, expected_response_schema)
expected_response_model = expected_response_schema(**expected_data)
assert response_model == expected_response_model