0001-iparapheur-add-a-field-to-override-endpoint-location.patch
passerelle/contrib/iparapheur/migrations/0006_iparapheur_wsdl_endpoint_location.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2019-02-27 17:28 |
|
3 |
from __future__ import unicode_literals |
|
4 | ||
5 |
from django.db import migrations, models |
|
6 | ||
7 | ||
8 |
class Migration(migrations.Migration): |
|
9 | ||
10 |
dependencies = [ |
|
11 |
('iparapheur', '0005_remove_iparapheur_log_level'), |
|
12 |
] |
|
13 | ||
14 |
operations = [ |
|
15 |
migrations.AddField( |
|
16 |
model_name='iparapheur', |
|
17 |
name='wsdl_endpoint_location', |
|
18 |
field=models.CharField(blank=True, help_text='override WSDL endpoint location', max_length=256, verbose_name='WSDL endpoint location'), |
|
19 |
), |
|
20 |
] |
passerelle/contrib/iparapheur/models.py | ||
---|---|---|
70 | 70 |
wsdl_url = models.CharField(max_length=128, blank=False, |
71 | 71 |
verbose_name=_('WSDL URL'), |
72 | 72 |
help_text=_('WSDL URL')) |
73 |
wsdl_endpoint_location = models.CharField(max_length=256, blank=True, |
|
74 |
verbose_name=_('WSDL endpoint location'), |
|
75 |
help_text=_('override WSDL endpoint location')) |
|
73 | 76 |
verify_cert = models.BooleanField(default=True, |
74 | 77 |
verbose_name=_('Check HTTPS Certificate validity')) |
75 | 78 |
username = models.CharField(max_length=128, blank=True, |
passerelle/contrib/iparapheur/soap.py | ||
---|---|---|
89 | 89 | |
90 | 90 |
def get_client(instance): |
91 | 91 |
transport = Transport(instance) |
92 |
return Client(instance.wsdl_url, transport=transport, |
|
93 |
plugins=[Handlewsdl(), Filter()], cache=None) |
|
92 |
client = Client(instance.wsdl_url, transport=transport, |
|
93 |
plugins=[Handlewsdl(), Filter()], cache=None) |
|
94 |
# overrides the service port address URL defined in the WSDL. |
|
95 |
if instance.wsdl_endpoint_location: |
|
96 |
client.set_options(location=instance.wsdl_endpoint_location) |
|
97 |
return client |
|
94 | 98 | |
95 | 99 |
def get_wsdl_string(instance): |
96 | 100 |
'''download wsdl like suds's DocumentReader does it (but do not parse it)''' |
tests/test_iparapheur.py | ||
---|---|---|
442 | 442 |
assert resp.json['err'] == 1 |
443 | 443 |
assert resp.json['data'] is None |
444 | 444 |
assert 'mocked error' in resp.json['err_desc'] |
445 | ||
446 |
@mock.patch('passerelle.utils.Request.get') |
|
447 |
@mock.patch('passerelle.utils.Request.post') |
|
448 |
@mock.patch('passerelle.contrib.iparapheur.soap.HttpAuthenticated.open') |
|
449 |
def test_call_ping_overrinding_endpoint_url(http_open, mocked_post, mocked_get, app, |
|
450 |
conn, xmlmime, wsdl_file): |
|
451 |
soap_response = 'no importance' |
|
452 |
http_open.return_value = file(xmlmime) |
|
453 |
mocked_get.return_value = mock.Mock(content=file(wsdl_file).read(), |
|
454 |
status_code=200) |
|
455 |
conn.wsdl_endpoint_location = 'http://www.nowhere.com' |
|
456 |
conn.save() |
|
457 |
mocked_post.return_value = mock.Mock(status_code=200, content=soap_response) |
|
458 |
url = reverse('generic-endpoint', kwargs={'connector': 'iparapheur', |
|
459 |
'endpoint': 'ping', 'slug': conn.slug}) |
|
460 |
url += '?apikey=%s' % API_KEY |
|
461 |
app.get(url) |
|
462 |
assert mocked_post.call_args[0][0] == 'http://www.nowhere.com' |
|
445 |
- |