From 03168b3cdf4d00ef88cec3abf183edcfc91bb8c2 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 15 Nov 2019 15:04:25 +0100 Subject: [PATCH 4/4] to fixup: add tests --- tests/test_templatetags.py | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/test_templatetags.py diff --git a/tests/test_templatetags.py b/tests/test_templatetags.py new file mode 100644 index 00000000..8d605bc3 --- /dev/null +++ b/tests/test_templatetags.py @@ -0,0 +1,43 @@ +# passerelle - uniform access to data and services +# Copyright (C) 2019 Entr'ouvert +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; exclude even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a.deepcopy of the GNU Affero General Public License +# along with this program. If not, see . + +import inspect + +from django.apps import apps + +from passerelle.base.templatetags.passerelle import render_body_schemas + + +def test_render_body_schemas(db): + # FIXME: db should be required but the way ProxyLogger is initialized force an access to the DB + def collect_schemas(): + for app in apps.get_app_configs(): + connector_model = None + if not hasattr(app, 'get_connector_model'): + continue + connector_model = app.get_connector_model() + if connector_model is None: + continue + for name, method in inspect.getmembers(connector_model, inspect.ismethod): + if not hasattr(method, 'endpoint_info'): + continue + if method.endpoint_info.post and method.endpoint_info.post.get('request_body', {}).get('schema'): + yield method.endpoint_info.post['request_body']['schema'], method + + schemas = list(collect_schemas()) + assert schemas , 'no endpoint with schema found' + for schema, endpoint in schemas: + assert render_body_schemas(schema), 'failed for %s' % endpoint -- 2.23.0