iparapheur: add endpoint to display raw wsdl (#30257)
This commit is contained in:
parent
2ef3a13b31
commit
3885a94e0c
|
@ -31,6 +31,7 @@ from passerelle.utils.api import endpoint
|
|||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
from .soap import get_client as soap_get_client
|
||||
from .soap import get_wsdl_string as soap_get_wsdl_string
|
||||
|
||||
|
||||
def get_client(model):
|
||||
|
@ -111,6 +112,14 @@ class IParapheur(BaseResource):
|
|||
def ping(self, request):
|
||||
return {'data': self.call('echo', 'ping')}
|
||||
|
||||
@endpoint()
|
||||
def wsdl(self, request):
|
||||
try:
|
||||
wsdl = soap_get_wsdl_string(self)
|
||||
except ConnectionError as exc:
|
||||
raise APIError('i-Parapheur WSDL error: %s' % exc)
|
||||
return HttpResponse(wsdl, content_type='text/xml')
|
||||
|
||||
@endpoint(perm='can_access')
|
||||
def subtypes(self, request, type=None):
|
||||
if type:
|
||||
|
|
|
@ -22,7 +22,7 @@ import StringIO
|
|||
|
||||
from suds.client import Client
|
||||
from suds.transport.http import HttpAuthenticated
|
||||
from suds.transport import Reply, TransportError
|
||||
from suds.transport import Request, Reply, TransportError
|
||||
from suds.plugin import MessagePlugin, DocumentPlugin
|
||||
|
||||
from requests.exceptions import RequestException
|
||||
|
@ -91,3 +91,8 @@ def get_client(instance):
|
|||
transport = Transport(instance)
|
||||
return Client(instance.wsdl_url, transport=transport,
|
||||
plugins=[Handlewsdl(), Filter()], cache=None)
|
||||
|
||||
def get_wsdl_string(instance):
|
||||
'''download wsdl like suds's DocumentReader does it (but do not parse it)'''
|
||||
transport = Transport(instance)
|
||||
return transport.open(Request(instance.wsdl_url))
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
|
||||
{% block endpoints %}
|
||||
<ul>
|
||||
{% url 'generic-endpoint' connector='iparapheur' slug=object.slug endpoint='wsdl' as wsdl_url %}
|
||||
<li>{% trans 'Download WSDL file:' %}
|
||||
<a href="{{ wsdl_url }}">{{ site_base_uri }}{{ wsdl_url }}</a>[?debug]
|
||||
</li>
|
||||
{% url 'generic-endpoint' connector='iparapheur' slug=object.slug endpoint='ping' as ping_url %}
|
||||
<li>{% trans 'Check WS availability:' %}
|
||||
<a href="{{ ping_url }}">{{ site_base_uri }}{{ ping_url }}</a>[?debug]
|
||||
|
|
|
@ -422,3 +422,23 @@ def test_get_magic_mime(tmpdir):
|
|||
f.write('some text')
|
||||
with text_path.open() as f:
|
||||
assert 'text/plain' == get_magic_mime(f.read())
|
||||
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_call_wsdl(mocked_get, app, conn, wsdl_file):
|
||||
mocked_get.return_value = mock.Mock(content=file(wsdl_file).read(),
|
||||
status_code=200)
|
||||
url = reverse('generic-endpoint',
|
||||
kwargs={'slug': conn.slug,
|
||||
'connector': 'iparapheur', 'endpoint': 'wsdl'})
|
||||
resp = app.get(url)
|
||||
assert resp.headers['content-type'] == 'text/xml'
|
||||
assert resp.content == file(wsdl_file).read()
|
||||
|
||||
@mock.patch('passerelle.utils.Request.get', side_effect=ConnectionError('mocked error'))
|
||||
def test_call_wsdl_connectionerror(mocked_get, app, conn):
|
||||
url = reverse('generic-endpoint', kwargs={'connector': 'iparapheur',
|
||||
'endpoint': 'wsdl', 'slug': conn.slug})
|
||||
resp = app.get(url)
|
||||
assert resp.json['err'] == 1
|
||||
assert resp.json['data'] is None
|
||||
assert 'mocked error' in resp.json['err_desc']
|
||||
|
|
Loading…
Reference in New Issue