0004-iparapheur-add-a-field-to-override-endpoint-location.patch
passerelle/contrib/iparapheur/migrations/0007_iparapheur_wsdl_endpoint_location.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# Generated by Django 1.11.18 on 2019-03-12 17:32 |
|
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', '0006_use_http_resource'), |
|
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 | ||
---|---|---|
33 | 33 | |
34 | 34 |
def get_client(model): |
35 | 35 |
try: |
36 |
return model.soap_client() |
|
36 |
soap_client = model.soap_client() |
|
37 | ||
38 |
# overrides the service port address URL defined in the WSDL. |
|
39 |
if model.wsdl_endpoint_location: |
|
40 |
soap_client.overridden_service = soap_client.create_service( |
|
41 |
# picks the first binding in the WSDL as the default |
|
42 |
soap_client.wsdl.bindings.keys()[0], |
|
43 |
model.wsdl_endpoint_location) |
|
44 |
else: |
|
45 |
soap_client.overridden_service = soap_client.service |
|
46 |
return soap_client |
|
37 | 47 |
except ConnectionError as exc: |
38 | 48 |
raise APIError('i-Parapheur error: %s' % exc) |
39 | 49 | |
... | ... | |
67 | 77 |
wsdl_url = models.CharField(max_length=128, blank=False, |
68 | 78 |
verbose_name=_('WSDL URL'), |
69 | 79 |
help_text=_('WSDL URL')) |
80 |
wsdl_endpoint_location = models.CharField(max_length=256, blank=True, |
|
81 |
verbose_name=_('WSDL endpoint location'), |
|
82 |
help_text=_('override WSDL endpoint location')) |
|
70 | 83 |
category = _('Business Process Connectors') |
71 | 84 | |
72 | 85 |
class Meta: |
... | ... | |
79 | 92 |
def call(self, service_name, *args, **kwargs): |
80 | 93 |
client = get_client(self) |
81 | 94 |
try: |
82 |
result = getattr(client.service, service_name)(*args, **kwargs) |
|
95 |
result = getattr(client.overridden_service, service_name)(*args, **kwargs)
|
|
83 | 96 |
except WebFault as exc: |
84 | 97 |
# Remote Service Error: <SOAP-ENV:Fault> in response |
85 | 98 |
raise APIError('ServiceError: %s' % exc) |
... | ... | |
144 | 157 |
} |
145 | 158 |
if email: |
146 | 159 |
parameters['EmailEmetteur'] = email |
147 |
resp = soap_client.service.CreerDossier(**parameters) |
|
160 |
resp = soap_client.overridden_service.CreerDossier(**parameters)
|
|
148 | 161 |
if not resp or not resp.MessageRetour: |
149 | 162 |
raise FileError('unknown error, no response') |
150 | 163 |
if resp.MessageRetour.codeRetour == 'KO': |
tests/test_iparapheur.py | ||
---|---|---|
70 | 70 |
def test_call_ping(soap_client, app, conn): |
71 | 71 |
service = mock.Mock() |
72 | 72 |
service.echo.return_value = 'pong' |
73 |
mocked_client = mock.Mock(service=service) |
|
73 |
mocked_client = mock.Mock(overridden_service=service)
|
|
74 | 74 |
soap_client.return_value = mocked_client |
75 | 75 |
url = reverse('generic-endpoint', kwargs={'connector': 'iparapheur', |
76 | 76 |
'endpoint': 'ping', 'slug': conn.slug}) |
... | ... | |
541 | 541 |
resp = app.get(url) |
542 | 542 |
assert resp.json['err'] == 0 |
543 | 543 |
assert resp.json['data'] == [] |
544 | ||
545 |
@mock.patch('passerelle.utils.Request.get', side_effect=iph_mocked_get) |
|
546 |
@mock.patch('passerelle.utils.Request.post') |
|
547 |
def test_call_ping_overrinding_endpoint_url(mocked_post, mocked_get, app, conn): |
|
548 |
response = Response() |
|
549 |
response.status_code = 200 |
|
550 |
soap_response = 'no importance' |
|
551 |
response._content = soap_response |
|
552 |
mocked_post.return_value = response |
|
553 | ||
554 |
conn.wsdl_endpoint_location = 'http://www.nowhere.com' |
|
555 |
conn.save() |
|
556 |
url = reverse('generic-endpoint', kwargs={'connector': 'iparapheur', |
|
557 |
'endpoint': 'ping', 'slug': conn.slug}) |
|
558 |
url += '?apikey=%s' % API_KEY |
|
559 |
app.get(url) |
|
560 |
assert mocked_post.call_args[0][0] == 'http://www.nowhere.com' |
|
544 |
- |