Projet

Général

Profil

0001-astregs-add-contact-details-endpoint-35129.patch

Serghei Mihai, 05 août 2019 11:41

Télécharger (4,73 ko)

Voir les différences:

Subject: [PATCH] astregs: add contact details endpoint (#35129)

 passerelle/apps/astregs/models.py      | 17 +++++++++++++++++
 tests/data/astregs/ContactResponse.xml |  1 +
 tests/test_astregs.py                  | 18 ++++++++++++++++++
 3 files changed, 36 insertions(+)
 create mode 100644 tests/data/astregs/ContactResponse.xml
passerelle/apps/astregs/models.py
478 478
        )
479 479
        return {'data': serialize_object(r)}
480 480

  
481

  
482
    @endpoint(name='get-contact', perm='can_access',
483
              description=_('Get association contact details'),
484
              parameters={
485
                  'contact_id':{
486
                      'description': _('Contact identifier'),
487
                      'example_value': '1111',
488
                  }
489
              }
490
    )
491
    def get_contact(self, request, contact_id):
492
        r = self.call('Contact', 'Chargement',
493
                      ContactCle={'idContact': contact_id}
494
        )
495
        return {'data': serialize_object(r)}
496

  
497

  
481 498
    @endpoint(name='create-contact',
482 499
              perm='can_access',
483 500
              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=500,
278
                                         headers={'Content-Type': 'text/xml'})
279
    resp = app.get('/astregs/test/get-contact',
280
                   params={'contact_id': '4242'})
281
    assert not resp.json['data']
282
    assert resp.json['err'] == 1
283
    assert resp.json['err_class'] == 'passerelle.utils.jsonresponse.APIError'
284

  
285
    mocked_post.return_value = mock.Mock(content=get_xml_file('ContactResponse.xml'), status_code=200,
286
                                         headers={'Content-Type': 'text/xml'})
287
    resp = app.get('/astregs/test/get-contact',
288
                   params={'contact_id': '1111'})
289

  
290

  
273 291
@mock.patch('passerelle.utils.Request.get', side_effect=contact_wsdl_side_effect)
274 292
@mock.patch('passerelle.utils.Request.post', side_effect=contact_side_effect)
275 293
def test_create_association_contact(mocked_post, mocked_get, connector, app):
276
-