Projet

Général

Profil

0004-to-fixup-add-tests.patch

Benjamin Dauvergne, 15 novembre 2019 15:05

Télécharger (2,42 ko)

Voir les différences:

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
tests/test_templatetags.py
1
# passerelle - uniform access to data and services
2
# Copyright (C) 2019  Entr'ouvert
3
#
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU Affero General Public License as published
6
# by the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; exclude even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU Affero General Public License for more details.
13
#
14
# You should have received a.deepcopy of the GNU Affero General Public License
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16

  
17
import inspect
18

  
19
from django.apps import apps
20

  
21
from passerelle.base.templatetags.passerelle import render_body_schemas
22

  
23

  
24
def test_render_body_schemas(db):
25
    # FIXME: db should be required but the way ProxyLogger is initialized force an access to the DB
26
    def collect_schemas():
27
        for app in apps.get_app_configs():
28
            connector_model = None
29
            if not hasattr(app, 'get_connector_model'):
30
                continue
31
            connector_model = app.get_connector_model()
32
            if connector_model is None:
33
                continue
34
            for name, method in inspect.getmembers(connector_model, inspect.ismethod):
35
                if not hasattr(method, 'endpoint_info'):
36
                    continue
37
                if method.endpoint_info.post and method.endpoint_info.post.get('request_body', {}).get('schema'):
38
                    yield  method.endpoint_info.post['request_body']['schema'], method
39

  
40
    schemas = list(collect_schemas())
41
    assert schemas , 'no endpoint with schema found'
42
    for schema, endpoint in schemas:
43
        assert render_body_schemas(schema), 'failed for %s' % endpoint
0
-