Projet

Général

Profil

0001-iparapheur-add-endpoint-to-display-raw-wsdl-30257.patch

Nicolas Roche, 27 février 2019 17:56

Télécharger (4,87 ko)

Voir les différences:

Subject: [PATCH] iparapheur: add endpoint to display raw wsdl (#30257)

 passerelle/contrib/iparapheur/models.py       | 10 ++++++++
 passerelle/contrib/iparapheur/soap.py         | 10 +++++++-
 .../iparapheur/iparapheur_detail.html         |  4 ++++
 tests/test_iparapheur.py                      | 23 +++++++++++++++++++
 4 files changed, 46 insertions(+), 1 deletion(-)
passerelle/contrib/iparapheur/models.py
31 31
from passerelle.utils.jsonresponse import APIError
32 32

  
33 33
from .soap import get_client as soap_get_client
34
from .soap import get_wsdl_string as soap_get_wsdl_string
34 35

  
35 36

  
36 37
def get_client(model):
......
39 40
    except ConnectionError as e:
40 41
        raise APIError('i-Parapheur error: %s' % e)
41 42

  
43
def get_wsdl_string(model):
44
    try:
45
        return soap_get_wsdl_string(model)
46
    except ConnectionError as e:
47
        raise APIError('i-Parapheur error: %s' % e)
42 48

  
43 49
def format_type(t):
44 50
    return {'id': unicode(t), 'text': unicode(t)}
......
111 117
    def ping(self, request):
112 118
        return {'data': self.call('echo', 'ping')}
113 119

  
120
    @endpoint(perm='can_access')
121
    def wsdl(self, request):
122
        return {'data': get_wsdl_string(self)}
123

  
114 124
    @endpoint(perm='can_access')
115 125
    def subtypes(self, request, type=None):
116 126
        if type:
passerelle/contrib/iparapheur/soap.py
22 22

  
23 23
from suds.client import Client
24 24
from suds.transport.http import HttpAuthenticated
25
from suds.transport import Reply, TransportError
25
from suds.transport import Request, Reply, TransportError
26 26
from suds.plugin import MessagePlugin, DocumentPlugin
27 27

  
28 28
from requests.exceptions import RequestException
......
91 91
    transport = Transport(instance)
92 92
    return Client(instance.wsdl_url, transport=transport,
93 93
                  plugins=[Handlewsdl(), Filter()], cache=None)
94

  
95
def get_wsdl_string(instance):
96
    '''download wsdl like suds's DocumentReader does it (but do not parse it)'''
97
    transport = Transport(instance)
98
    fp = transport.open(Request(instance.wsdl_url))
99
    content = fp.read()
100
    fp.close()
101
    return content
passerelle/contrib/iparapheur/templates/iparapheur/iparapheur_detail.html
6 6

  
7 7
{% block endpoints %}
8 8
<ul>
9
  {% url 'generic-endpoint' connector='iparapheur' slug=object.slug endpoint='wsdl' as wsdl_url %}
10
  <li>{% trans 'Download WSDL file:' %}
11
    <a href="{{ wsdl_url }}">{{ site_base_uri }}{{ wsdl_url }}</a>[?debug]
12
  </li>
9 13
  {% url 'generic-endpoint' connector='iparapheur' slug=object.slug endpoint='ping' as ping_url %}
10 14
  <li>{% trans 'Check WS availability:' %}
11 15
    <a href="{{ ping_url }}">{{ site_base_uri }}{{ ping_url }}</a>[?debug]
tests/test_iparapheur.py
422 422
        f.write('some text')
423 423
    with text_path.open() as f:
424 424
        assert 'text/plain' == get_magic_mime(f.read())
425

  
426
@mock.patch('passerelle.contrib.iparapheur.models.soap_get_wsdl_string',
427
            mock.MagicMock(return_value='... the raw wsdl file...'))
428
def test_call_wsdl(app, conn):
429
    url = reverse('generic-endpoint', kwargs={'connector': 'iparapheur',
430
                    'endpoint': 'wsdl', 'slug': conn.slug})
431
    resp = app.get(url, status=403)
432
    url += '?apikey=%s' % API_KEY
433
    resp = app.get(url)
434
    assert resp.json['err'] == 0
435
    assert resp.json['data'] == "'... the raw wsdl file...'"
436

  
437
@mock.patch('passerelle.contrib.iparapheur.models.soap_get_wsdl_string',
438
            side_effect=ConnectionError('mocked error'))
439
def test_call_wsdl_connectionerror(soap_client, app, conn):
440
    url = reverse('generic-endpoint', kwargs={'connector': 'iparapheur',
441
                    'endpoint': 'wsdl', 'slug': conn.slug})
442
    resp = app.get(url, status=403)
443
    url += '?apikey=%s' % API_KEY
444
    resp = app.get(url)
445
    assert resp.json['err'] == 1
446
    assert resp.json['data'] == None
447
    assert 'mocked error' in resp.json['err_desc']
425
-