0001-astregs-add-contact-details-endpoint-35129.patch
passerelle/apps/astregs/models.py | ||
---|---|---|
453 | 453 |
) |
454 | 454 |
return {'data': serialize_object(r)} |
455 | 455 | |
456 | ||
457 |
@endpoint(name='get-contact', perm='can_access', |
|
458 |
description=_('Get association contact details'), |
|
459 |
parameters={ |
|
460 |
'contact_id':{ |
|
461 |
'description': _('Contact identifier'), |
|
462 |
'example_value': '1111', |
|
463 |
} |
|
464 |
} |
|
465 |
) |
|
466 |
def get_contact(self, request, contact_id): |
|
467 |
r = self.call('Contact', 'Chargement', |
|
468 |
ContactCle={'idContact': contact_id} |
|
469 |
) |
|
470 |
return {'data': serialize_object(r)} |
|
471 | ||
472 | ||
456 | 473 |
@endpoint(name='create-contact', |
457 | 474 |
perm='can_access', |
458 | 475 |
post={'description': _('Create contact'), |
tests/data/astregs/ContactResponse.xml | ||
---|---|---|
1 |
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns1:chargementResponse xmlns:ns1="http://gfi.astre.webservices/rf/gf/contact"><ns1:response><ns1:ContactReturn><ns1:idContact>1111</ns1:idContact><ns1:CodeContact>POL14466</ns1:CodeContact><ns1:CodeTitreCivilite>035</ns1:CodeTitreCivilite><ns1:Nom>NARDELLI</ns1:Nom><ns1:Prenom>Robert</ns1:Prenom><ns1:NomDeJeuneFille></ns1:NomDeJeuneFille><ns1:DateDeNaissance></ns1:DateDeNaissance><ns1:FormuleCivilite>Maire de Drap</ns1:FormuleCivilite><ns1:IntituleTitre2></ns1:IntituleTitre2><ns1:IntituleTitre3></ns1:IntituleTitre3><ns1:IntituleTitre4>Président du</ns1:IntituleTitre4><ns1:SituationDeFamille></ns1:SituationDeFamille><ns1:CodeFonction></ns1:CodeFonction><ns1:LibelleFonction></ns1:LibelleFonction><ns1:TelephoneBureau></ns1:TelephoneBureau><ns1:TelephoneMobile></ns1:TelephoneMobile><ns1:NumeroDeFax></ns1:NumeroDeFax><ns1:AdresseMail></ns1:AdresseMail><ns1:PageWeb></ns1:PageWeb><ns1:AdresseDestinataire>Robert NARDELLI</ns1:AdresseDestinataire><ns1:AdresseComplementaire></ns1:AdresseComplementaire><ns1:ComplementGeographique>Mairie</ns1:ComplementGeographique><ns1:RueVoie>Avenue du Général de Gaulle</ns1:RueVoie><ns1:ComplementVoie>B.P. n° 37</ns1:ComplementVoie><ns1:CodePostal>06340</ns1:CodePostal><ns1:Ville>DRAP</ns1:Ville><ns1:CodePays>FR</ns1:CodePays><ns1:LibellePays>France</ns1:LibellePays><ns1:LibelleAdresse>ADRESSE PROFESSIONNELLE</ns1:LibelleAdresse><ns1:Commentaire></ns1:Commentaire></ns1:ContactReturn></ns1:response></ns1:chargementResponse></soapenv:Body></soapenv:Envelope> |
tests/test_astregs.py | ||
---|---|---|
270 | 270 |
assert not resp.json['data'] |
271 | 271 | |
272 | 272 | |
273 |
@mock.patch('passerelle.utils.Request.get') |
|
274 |
@mock.patch('passerelle.utils.Request.post') |
|
275 |
def test_get_contact_details(mocked_post, mocked_get, connector, app): |
|
276 |
mocked_get.return_value = mock.Mock(content=get_xml_file('Contact.wsdl')) |
|
277 |
mocked_post.return_value = mock.Mock(content=get_xml_file('ContactResponse.xml'), status_code=200, |
|
278 |
headers={'Content-Type': 'text/xml'}) |
|
279 |
resp = app.get('/astregs/test/get-contact', |
|
280 |
params={'contact_id': '1111'}) |
|
281 |
assert resp.json['data'] |
|
282 |
data = resp.json['data'] |
|
283 |
assert data['idContact'] == '1111' |
|
284 |
assert data['CodeContact'] == 'POL14466' |
|
285 |
assert data['Nom'] == 'NARDELLI' |
|
286 |
assert data['Prenom'] == 'Robert' |
|
287 |
assert data['ComplementGeographique'] == 'Mairie' |
|
288 |
assert data['CodePostal'] == '06340' |
|
289 |
assert data['Ville'] == 'DRAP' |
|
290 |
assert data['LibellePays'] == 'France' |
|
291 | ||
292 |
mocked_post.return_value = mock.Mock(content=get_xml_file('ContactResponse.xml'), status_code=500, |
|
293 |
headers={'Content-Type': 'text/xml'}) |
|
294 |
resp = app.get('/astregs/test/get-contact', |
|
295 |
params={'contact_id': '4242'}) |
|
296 |
assert not resp.json['data'] |
|
297 |
assert resp.json['err'] == 1 |
|
298 |
assert resp.json['err_class'] == 'passerelle.utils.jsonresponse.APIError' |
|
299 | ||
300 | ||
273 | 301 |
@mock.patch('passerelle.utils.Request.get', side_effect=contact_wsdl_side_effect) |
274 | 302 |
@mock.patch('passerelle.utils.Request.post', side_effect=contact_side_effect) |
275 | 303 |
def test_create_association_contact(mocked_post, mocked_get, connector, app): |
276 |
- |