diff --git a/test/conftest.py b/test/conftest.py index ffe4065..a97e092 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -256,6 +256,58 @@ def generate_body_and_status(params: dict[str, str]) -> list[tuple[dict, int]]: return body_and_status +@pytest.fixture +async def route_data(): + routes: dict[str, dict] = {} + + contexts = list(iter_route_contexts(app.routes)) + + for route in contexts: + if not route.methods: + continue + if not isinstance(route.route, APIRoute): + continue + + dep_func_names = set() + + unchecked = [route.route.dependant] + while unchecked: + dependant = unchecked.pop(0) + ck = dependant.cache_key[0] + if hasattr(ck, "__name__"): + dep_func_names.add(ck.__name__) + unchecked += [ + dep for dep in dependant.dependencies if isinstance(dep, Dependant) + ] + + auth_level = None + if "get_current_user" in dep_func_names: + auth_level = "User" + if ( + "org_body_root_claims" in dep_func_names + or "org_query_root_claims" in dep_func_names + ): + auth_level = "Root User" + if "user_model_super_admin" in dep_func_names: + auth_level = "Super Admin" + if "valid_service_key" in dep_func_names: + auth_level = "API Key" + + for method in route.methods: + if method in {"HEAD", "OPTIONS"}: + continue + + route_key = f"{method.upper()}{route.route.path}" + + routes[route_key] = { + "status_code": route.route.status_code, + "response_model": route.route.response_model, + "auth_level": auth_level, + } + + return routes + + def get_testable_routes(): routes = []