54 |
54 |
if url == 'https://secure-iparapheur.demonstrations.adullact.org:443/ws-iparapheur?wsdl':
|
55 |
55 |
target_file = wsdl_file()
|
56 |
56 |
|
57 |
|
# simulate second GET call (nested <xsd:import> into wsdl fil)
|
|
57 |
# simulate second GET call (nested <xsd:import> into wsdl file)
|
58 |
58 |
elif url == 'http://www.w3.org/2005/05/xmlmime':
|
|
59 |
assert kwargs['auth'] is None # no basic_authenticton on wsdl' imports
|
59 |
60 |
target_file = xmlmime()
|
60 |
61 |
|
61 |
62 |
else:
|
... | ... | |
98 |
99 |
typ = 'Courrier'
|
99 |
100 |
subtyp = 'maire'
|
100 |
101 |
visibility = 'SERVICE'
|
|
102 |
email = 'alice.boniadetos@arf.pt'
|
101 |
103 |
response = Response()
|
102 |
104 |
response.status_code = 200
|
103 |
105 |
|
... | ... | |
155 |
157 |
assert 'zeep.exceptions.TransportError' in resp.json['err_class']
|
156 |
158 |
assert 'Server returned HTTP status 200 (<nada>)' in resp.json['err_desc']
|
157 |
159 |
|
|
160 |
# Unknown value for "visibility"
|
|
161 |
data = {'type': typ, 'subtype': subtyp, 'visibility': 'UNKNOWN_VISIBILITY',
|
|
162 |
'title': title, 'data': base64_data, 'content-type':'application/pdf'}
|
|
163 |
url = reverse('generic-endpoint', kwargs={'connector': 'iparapheur',
|
|
164 |
'endpoint': 'create-file', 'slug': conn.slug})
|
|
165 |
url += '?apikey=%s' % API_KEY
|
|
166 |
resp = app.post_json(url, params=data, status=500)
|
|
167 |
assert resp.json['err'] == 1
|
|
168 |
assert 'FileError' in resp.json['err_class']
|
|
169 |
|
|
170 |
# OK, providing email
|
|
171 |
data = {'type': typ, 'subtype': subtyp, 'visibility': visibility,
|
|
172 |
'title': title, 'data': base64_data, 'content-type':'application/pdf',
|
|
173 |
'email': email}
|
|
174 |
url = reverse('generic-endpoint', kwargs={'connector': 'iparapheur',
|
|
175 |
'endpoint': 'create-file', 'slug': conn.slug})
|
|
176 |
url += '?apikey=%s' % API_KEY
|
|
177 |
soap_response = """<nada>"""
|
|
178 |
response._content = soap_response
|
|
179 |
mocked_post.return_value = response
|
|
180 |
resp = app.post_json(url, params=data, status=500)
|
|
181 |
assert (BASE_URL,) == mocked_post.call_args[0]
|
|
182 |
assert resp.json['err'] == 1
|
|
183 |
assert 'zeep.exceptions.TransportError' in resp.json['err_class']
|
|
184 |
assert 'Server returned HTTP status 200 (<nada>)' in resp.json['err_desc']
|
|
185 |
|
158 |
186 |
@mock.patch('passerelle.utils.Request.get', side_effect=iph_mocked_get)
|
159 |
187 |
@mock.patch('passerelle.utils.Request.post')
|
160 |
188 |
def test_files(mocked_post, mocked_get, app, conn):
|
... | ... | |
175 |
203 |
assert item['id']
|
176 |
204 |
assert item['timestamp']
|
177 |
205 |
|
|
206 |
# same call providing parameter
|
|
207 |
soap_response = """<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><RechercherDossiersResponse xmlns="http://www.adullact.org/spring-ws/iparapheur/1.0" xmlns:xmime="http://www.w3.org/2005/05/xmlmime"><LogDossier><timestamp>2015-10-29T15:42:08.732+01:00</timestamp><nom>test</nom><status>Lu</status><annotation></annotation><accessible>KO</accessible></LogDossier></RechercherDossiersResponse></S:Body></S:Envelope>"""
|
|
208 |
response._content = soap_response
|
|
209 |
mocked_post.return_value = response
|
|
210 |
url += '&status=Lu'
|
|
211 |
resp = app.get(url)
|
|
212 |
assert len(resp.json['data']) == 1
|
|
213 |
for item in resp.json['data']:
|
|
214 |
assert item['status']
|
|
215 |
assert item['id']
|
|
216 |
assert item['timestamp']
|
|
217 |
|
178 |
218 |
@mock.patch('passerelle.utils.Request.get', side_effect=iph_mocked_get)
|
179 |
219 |
@mock.patch('passerelle.utils.Request.post')
|
180 |
220 |
def test_get_file_status(mocked_post, mocked_get, app, conn):
|
... | ... | |
428 |
468 |
assert resp.json['err'] == 1
|
429 |
469 |
assert resp.json['data'] is None
|
430 |
470 |
assert 'mocked error' in resp.json['err_desc']
|
|
471 |
|
|
472 |
@mock.patch('passerelle.utils.Request.get')
|
|
473 |
@mock.patch('zeep.Transport._load_remote_data')
|
|
474 |
@mock.patch('passerelle.utils.Request.post')
|
|
475 |
def test_no_auth_on_wsdl_imports(mocked_post, mocked_load, mocked_get, app, conn):
|
|
476 |
"""
|
|
477 |
While getting wsdl:
|
|
478 |
- zeep.Transport._load_remote_data is call on basic_authentication (get wsdl file)
|
|
479 |
- passerelle.utils.Request.get is call on no basic_authenticaion (get xmlmime import's file)
|
|
480 |
|
|
481 |
Notice: this also test the 'echo' SOAP service
|
|
482 |
"""
|
|
483 |
response_xmlmime, response_post = Response(), Response()
|
|
484 |
response_xmlmime.status_code, response_post.status_code = 200, 200
|
|
485 |
response_xmlmime._content=file(xmlmime()).read()
|
|
486 |
response_post._content = """<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><echoResponse xmlns="http://www.adullact.org/spring-ws/iparapheur/1.0" xmlns:xmime="http://www.w3.org/2005/05/xmlmime">[publik_test] m'a dit: "ping"!</echoResponse></S:Body></S:Envelope>
|
|
487 |
"""
|
|
488 |
mocked_load.return_value = file(wsdl_file()).read()
|
|
489 |
mocked_get.return_value = response_xmlmime
|
|
490 |
mocked_post.return_value = response_post
|
|
491 |
url = reverse('generic-endpoint', kwargs={'connector': 'iparapheur',
|
|
492 |
'endpoint': 'ping', 'slug': conn.slug})
|
|
493 |
|
|
494 |
resp = app.get(url, status=403)
|
|
495 |
url += '?apikey=%s' % API_KEY
|
|
496 |
resp = app.get(url)
|
|
497 |
assert resp.json['err'] == 0
|
|
498 |
assert resp.json['data'] == "[publik_test] m'a dit: \"ping\"!"
|
|
499 |
|
|
500 |
@mock.patch('passerelle.utils.Request.get', side_effect=iph_mocked_get)
|
|
501 |
@mock.patch('passerelle.utils.Request.post')
|
|
502 |
def test_types(mocked_post, mocked_get, app, conn):
|
|
503 |
"""test GetListeTypesRequest SOAP service"""
|
|
504 |
response = Response()
|
|
505 |
response.status_code = 200
|
|
506 |
|
|
507 |
# empty list of types as response
|
|
508 |
soap_response = """<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><GetListeTypesResponse xmlns="http://www.adullact.org/spring-ws/iparapheur/1.0" xmlns:xmime="http://www.w3.org/2005/05/xmlmime"/></S:Body></S:Envelope>"""
|
|
509 |
|
|
510 |
response._content = soap_response
|
|
511 |
mocked_post.return_value = response
|
|
512 |
url = reverse('generic-endpoint', kwargs={'slug': conn.slug, 'connector': 'iparapheur',
|
|
513 |
'endpoint': 'types'})
|
|
514 |
url += '?apikey=%s' % API_KEY
|
|
515 |
resp = app.get(url)
|
|
516 |
assert resp.json['err'] == 0
|
|
517 |
assert resp.json['data'] == []
|
|
518 |
|
|
519 |
@mock.patch('passerelle.utils.Request.get', side_effect=iph_mocked_get)
|
|
520 |
@mock.patch('passerelle.utils.Request.post')
|
|
521 |
def test_subtypes(mocked_post, mocked_get, app, conn):
|
|
522 |
"""test GetListeSousTypes SOAP service"""
|
|
523 |
response = Response()
|
|
524 |
response.status_code = 200
|
|
525 |
|
|
526 |
# error: no parameter provided
|
|
527 |
url = reverse('generic-endpoint', kwargs={'slug': conn.slug, 'connector': 'iparapheur',
|
|
528 |
'endpoint': 'subtypes'})
|
|
529 |
resp = app.get(url, status=403)
|
|
530 |
url += '?apikey=%s' % API_KEY
|
|
531 |
resp = app.get(url)
|
|
532 |
assert resp.json['err'] == 1
|
|
533 |
assert resp.json['err_desc'] == "Type Error: TypeTechnique() takes exactly 1 argument (0 given). Simple types expect only a single value argument"
|
|
534 |
|
|
535 |
# providing a type as parameter
|
|
536 |
soap_response = """<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><GetListeTypesResponse xmlns="http://www.adullact.org/spring-ws/iparapheur/1.0" xmlns:xmime="http://www.w3.org/2005/05/xmlmime"/></S:Body></S:Envelope>"""
|
|
537 |
|
|
538 |
response._content = soap_response # empty list of subtypes as response
|
|
539 |
mocked_post.return_value = response
|
|
540 |
url += '&type=my_unknown_type'
|
|
541 |
resp = app.get(url)
|
|
542 |
assert resp.json['err'] == 0
|
|
543 |
assert resp.json['data'] == []
|
431 |
|
-
|