tests: Invert validation check

Now that all of our controllers have full schema coverage, we can now
assume that all controllers are validated and raise if that's not the
case.

Change-Id: I3a58be8551e7cf13835ad565aae4fc9dc4214bbd
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane
2024-12-03 10:57:24 +00:00
parent dab02447e6
commit 6bc431bc52
@@ -43,7 +43,7 @@ class SchemaTest(test.NoDBTestCase):
)
invalid_schemas.add(func.__qualname__)
def _validate_func(func, method, validated):
def _validate_func(func, method):
if method in ("POST", "PUT", "PATCH"):
# request body validation
if not hasattr(func, 'request_body_schemas'):
@@ -61,8 +61,7 @@ class SchemaTest(test.NoDBTestCase):
# response body validation
if not hasattr(func, 'response_body_schemas'):
if validated:
missing_response_schemas.add(func.__qualname__)
missing_response_schemas.add(func.__qualname__)
else:
for schema, _, _ in func.response_body_schemas._schemas:
_validate_schema(func, schema)
@@ -73,7 +72,13 @@ class SchemaTest(test.NoDBTestCase):
controller = route.defaults['controller']
validated = getattr(controller.controller, '_validated', False)
if not hasattr(controller.controller, '_validated'):
raise Exception(
f'Found unvalidated controller: '
f'{controller.controller.__class__.__qualname__}. '
f'All controllers must be validated. Add the validated '
f'decorator plus other required schema decorators.'
)
# NOTE: This is effectively a reimplementation of
# 'routes.route.Route.make_full_route' that uses OpenAPI-compatible
@@ -111,11 +116,11 @@ class SchemaTest(test.NoDBTestCase):
) in wsgi_actions:
func = controller.wsgi_actions[wsgi_action]
# method will always be POST for actions
_validate_func(func, method, validated)
_validate_func(func, method)
else:
# body validation
func = getattr(controller.controller, action)
_validate_func(func, method, validated)
_validate_func(func, method)
if missing_request_schemas:
raise test.TestingException(