ping: with debug argument, shows SOAP client infos

This commit is contained in:
Thomas NOËL 2015-04-17 11:47:23 +02:00
parent ad2bc28b4e
commit 040d681765
2 changed files with 25 additions and 2 deletions

View File

@ -63,3 +63,23 @@ class MaarchSudsTransport(HttpAuthenticated):
def get_client(maarch):
transport = MaarchSudsTransport(maarch=maarch)
return Client(maarch.wsdl_url, transport=transport, cache=None, doctor=doctor)
def client_to_dict(client):
"""return description of the client, as dict"""
res = {}
for i, sd in enumerate(client.sd):
d = {}
d['tns'] = sd.wsdl.tns[1]
d['prefixes'] = dict(p for p in sd.prefixes)
d['ports'] = {}
for p in sd.ports:
d['ports'][p[0].name] = {}
for m in p[1]:
d['ports'][p[0].name][m[0]] = dict(
(mp[0], sd.xlate(mp[1])) for mp in m[1])
d['types'] = {}
for t in sd.types:
ft = client.factory.create(sd.xlate(t[0]))
d['types'][sd.xlate(t[0])] = unicode(ft)
res[sd.service.name] = d
return res

View File

@ -24,7 +24,7 @@ from django.core.cache import cache
from passerelle import utils
from .soap import get_client
from .soap import get_client, client_to_dict
from .models import MaarchManagement
from .forms import MaarchManagementForm, MaarchManagementUpdateForm
@ -71,4 +71,7 @@ class MaarchDetailView(DetailView):
class MaarchPingView(MaarchDetailView):
def get_data(self, request, *args, **kwargs):
client = self.get_client()
return {'ping': 'pong'}
res = {'ping': 'pong'}
if 'debug' in request.GET:
res['client'] = client_to_dict(client)
return res