From ed01e2515f0e09bc08fc06c19d3a2362bd850e11 Mon Sep 17 00:00:00 2001 From: luxferre Date: Wed, 24 Jun 2026 10:10:29 +0100 Subject: [PATCH] tests: dynamic test using new fixture --- test/test_user.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/test_user.py b/test/test_user.py index a1f693c..84b7bf1 100644 --- a/test/test_user.py +++ b/test/test_user.py @@ -1,11 +1,12 @@ """ [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. +[DELETE]/user/ is not tested because the testing client cannot attach a body to a delete request. """ +from typing import Any + import pytest from httpx import AsyncClient -from fastapi.routing import APIRoute, iter_route_contexts from .conftest import generate_query_and_status @@ -153,9 +154,13 @@ async def test_get_self_orgs_success(default_client: AsyncClient): @pytest.mark.anyio -async def test_get_self_orgs_dynamic(default_client: AsyncClient): +async def test_get_self_orgs_dynamic( + default_client: AsyncClient, route_data: dict[str, dict[str, Any]] +): method = "GET" path = "/user/self/orgs" + auth_level = "User" + query = "" expected_data = { "organisations": [ { @@ -178,24 +183,19 @@ async def test_get_self_orgs_dynamic(default_client: AsyncClient): ] } - resp = await default_client.get(path) + # req_func = getattr(default_client, method); resp = await req_func(url=path, json=body) + resp = await default_client.get(f"{path}{query}") - contexts = list(iter_route_contexts(default_client._transport.app.routes)) # ty:ignore[unresolved-attribute] + route = route_data.get(f"{method.upper()}{path}") + assert route is not None - route = next( - route.route - for route in contexts - if isinstance(route.route, APIRoute) - and path in route.route.path - and isinstance(route.methods, set) - and method in route.methods - ) + assert route["auth_level"] == auth_level - assert resp.status_code == route.status_code - if route.status_code == 204: + assert resp.status_code == route["status_code"] + if route["status_code"] == 204: return - expected_response_schema = route.response_model + expected_response_schema = route["response_model"] data = resp.json() response_model = expected_response_schema(**data)