1
0
Fork 0
forked from sr2/cloud-api

tests: dynamic test standardised

The dynamic test structure should now be able applicable to all endpoints and the bulk of its logic has been split into a new function.
This commit is contained in:
Chris Milne 2026-06-24 10:26:28 +01:00
parent ed01e2515f
commit 41df580a1a
2 changed files with 43 additions and 25 deletions

View file

@ -8,8 +8,7 @@ from typing import Any
import pytest
from httpx import AsyncClient
from .conftest import generate_query_and_status
from .conftest import generate_query_and_status, standard_test
pytestmark = [
pytest.mark.user_module,
@ -154,13 +153,14 @@ async def test_get_self_orgs_success(default_client: AsyncClient):
@pytest.mark.anyio
async def test_get_self_orgs_dynamic(
async def test_get_self_orgs_standard(
default_client: AsyncClient, route_data: dict[str, dict[str, Any]]
):
method = "GET"
path = "/user/self/orgs"
auth_level = "User"
query = ""
body = {}
expected_data = {
"organisations": [
{
@ -183,24 +183,6 @@ async def test_get_self_orgs_dynamic(
]
}
# req_func = getattr(default_client, method); resp = await req_func(url=path, json=body)
resp = await default_client.get(f"{path}{query}")
route = route_data.get(f"{method.upper()}{path}")
assert route is not None
assert route["auth_level"] == auth_level
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
await standard_test(
default_client, method, path, auth_level, query, body, expected_data, route_data
)