0001-astregs-return-only-valid-mobile-number-in-linking-m.patch
passerelle/apps/astregs/models.py | ||
---|---|---|
385 | 385 |
if NameID and Link.objects.filter(resource=self, name_id=NameID, |
386 | 386 |
association_id=association_id).exists(): |
387 | 387 |
response['already_paired'] = True |
388 |
data = []
|
|
388 |
response['data'] = []
|
|
389 | 389 |
# assocation contact is defined in EncodeKeyContact attribute |
390 | 390 |
if not r.EncodeKeyContact: |
391 | 391 |
return {'data': data} |
... | ... | |
393 | 393 |
r = self.call('Contact', 'Chargement', |
394 | 394 |
ContactCle={'idContact': r.EncodeKeyContact} |
395 | 395 |
) |
396 |
response['raw_data'] = serialize_object(r) |
|
396 | 397 |
if r.AdresseMail: |
397 |
data.append({'id': 'email', |
|
398 |
'text': 'par courriel vers %s***@***%s' % (r.AdresseMail[:2], r.AdresseMail[-3:]), |
|
399 |
'value': r.AdresseMail, |
|
400 |
'type': 'email'}) |
|
398 |
response['data'].append({'id': 'email', |
|
399 |
'text': 'par courriel vers %s***@***%s' % ( |
|
400 |
r.AdresseMail[:2], |
|
401 |
r.AdresseMail[-3:]), |
|
402 |
'value': r.AdresseMail, |
|
403 |
'type': 'email'}) |
|
401 | 404 |
if r.TelephoneMobile: |
402 |
data.append({'id': 'mobile', |
|
403 |
'text': 'par SMS vers %s****%s' % (r.TelephoneMobile[:2], r.TelephoneMobile[-3:]), |
|
404 |
'value': r.TelephoneMobile, |
|
405 |
'type': 'mobile'}) |
|
406 |
response['data'] = data |
|
405 |
mobile = ''.join((n for n in r.TelephoneMobile if n.isdigit())) |
|
406 | ||
407 |
# remove international prefix marker |
|
408 |
if mobile.startswith('00'): |
|
409 |
mobile = mobile[2:] |
|
410 | ||
411 |
if mobile.startswith('33'): |
|
412 |
mobile = '0' + mobile[2:] |
|
413 | ||
414 |
if not mobile or len(mobile) != 10: |
|
415 |
return response |
|
416 | ||
417 |
if mobile[:2] in ('06', '07'): |
|
418 |
response['data'].append({'id': 'mobile', |
|
419 |
'text': 'par SMS vers %s*****%s' % ( |
|
420 |
mobile[:2], |
|
421 |
mobile[-3:]), |
|
422 |
'value': mobile, |
|
423 |
'type': 'mobile'}) |
|
407 | 424 |
return response |
408 | 425 | |
409 | 426 |
@endpoint(description=_('Create link between user and association'), |
tests/data/astregs/Contact.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>13012</ns1:idContact><ns1:CodeContact>AS173957</ns1:CodeContact><ns1:CodeTitreCivilite>035</ns1:CodeTitreCivilite><ns1:Nom>MARTIN</ns1:Nom><ns1:Prenom>Jean-Marc</ns1:Prenom><ns1:NomDeJeuneFille></ns1:NomDeJeuneFille><ns1:DateDeNaissance></ns1:DateDeNaissance><ns1:FormuleCivilite></ns1:FormuleCivilite><ns1:IntituleTitre2></ns1:IntituleTitre2><ns1:IntituleTitre3></ns1:IntituleTitre3><ns1:IntituleTitre4>Président de l&#39;</ns1:IntituleTitre4><ns1:SituationDeFamille></ns1:SituationDeFamille><ns1:CodeFonction></ns1:CodeFonction><ns1:LibelleFonction></ns1:LibelleFonction><ns1:TelephoneBureau></ns1:TelephoneBureau><ns1:TelephoneMobile>0660909980</ns1:TelephoneMobile><ns1:NumeroDeFax></ns1:NumeroDeFax><ns1:AdresseMail>jeanmarcallan@neuf.fr</ns1:AdresseMail><ns1:PageWeb></ns1:PageWeb><ns1:AdresseDestinataire>Jean-Marc MARTIN</ns1:AdresseDestinataire><ns1:AdresseComplementaire></ns1:AdresseComplementaire><ns1:ComplementGeographique></ns1:ComplementGeographique><ns1:RueVoie>271 chemin de Curnier</ns1:RueVoie><ns1:ComplementVoie></ns1:ComplementVoie><ns1:CodePostal>06750</ns1:CodePostal><ns1:Ville>SERANON</ns1:Ville><ns1:CodePays>FR</ns1:CodePays><ns1:LibellePays>France</ns1:LibellePays><ns1:LibelleAdresse>SIEGE SOCIAL</ns1:LibelleAdresse><ns1:Commentaire></ns1:Commentaire></ns1:ContactReturn></ns1:response></ns1:chargementResponse></soapenv:Body></soapenv:Envelope> |
|
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>13012</ns1:idContact><ns1:CodeContact>AS173957</ns1:CodeContact><ns1:CodeTitreCivilite>035</ns1:CodeTitreCivilite><ns1:Nom>FOO</ns1:Nom><ns1:Prenom>Foo-Marc</ns1:Prenom><ns1:NomDeJeuneFille></ns1:NomDeJeuneFille><ns1:DateDeNaissance></ns1:DateDeNaissance><ns1:FormuleCivilite></ns1:FormuleCivilite><ns1:IntituleTitre2></ns1:IntituleTitre2><ns1:IntituleTitre3></ns1:IntituleTitre3><ns1:IntituleTitre4>Président de l&#39;</ns1:IntituleTitre4><ns1:SituationDeFamille></ns1:SituationDeFamille><ns1:CodeFonction></ns1:CodeFonction><ns1:LibelleFonction></ns1:LibelleFonction><ns1:TelephoneBureau></ns1:TelephoneBureau><ns1:TelephoneMobile>06 67 78 89 90</ns1:TelephoneMobile><ns1:NumeroDeFax></ns1:NumeroDeFax><ns1:AdresseMail>foo@example.com</ns1:AdresseMail><ns1:PageWeb></ns1:PageWeb><ns1:AdresseDestinataire>Foo FOO</ns1:AdresseDestinataire><ns1:AdresseComplementaire></ns1:AdresseComplementaire><ns1:ComplementGeographique></ns1:ComplementGeographique><ns1:RueVoie>271 chemin de Curnier</ns1:RueVoie><ns1:ComplementVoie></ns1:ComplementVoie><ns1:CodePostal>06750</ns1:CodePostal><ns1:Ville>SERANON</ns1:Ville><ns1:CodePays>FR</ns1:CodePays><ns1:LibellePays>France</ns1:LibellePays><ns1:LibelleAdresse>SIEGE SOCIAL</ns1:LibelleAdresse><ns1:Commentaire></ns1:Commentaire></ns1:ContactReturn></ns1:response></ns1:chargementResponse></soapenv:Body></soapenv:Envelope> |
tests/data/astregs/ContactWithInternationalMobile.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>13012</ns1:idContact><ns1:CodeContact>AS173957</ns1:CodeContact><ns1:CodeTitreCivilite>035</ns1:CodeTitreCivilite><ns1:Nom>Bar</ns1:Nom><ns1:Prenom></ns1:Prenom><ns1:NomDeJeuneFille></ns1:NomDeJeuneFille><ns1:DateDeNaissance></ns1:DateDeNaissance><ns1:FormuleCivilite></ns1:FormuleCivilite><ns1:IntituleTitre2></ns1:IntituleTitre2><ns1:IntituleTitre3></ns1:IntituleTitre3><ns1:IntituleTitre4>Président de l&#39;</ns1:IntituleTitre4><ns1:SituationDeFamille></ns1:SituationDeFamille><ns1:CodeFonction></ns1:CodeFonction><ns1:LibelleFonction></ns1:LibelleFonction><ns1:TelephoneBureau></ns1:TelephoneBureau><ns1:TelephoneMobile>00 33 7 02 03 04 05</ns1:TelephoneMobile><ns1:NumeroDeFax></ns1:NumeroDeFax><ns1:AdresseMail>foo@example.com</ns1:AdresseMail><ns1:PageWeb></ns1:PageWeb><ns1:AdresseDestinataire>Foo-Marc</ns1:AdresseDestinataire><ns1:AdresseComplementaire></ns1:AdresseComplementaire><ns1:ComplementGeographique></ns1:ComplementGeographique><ns1:RueVoie>271 chemin de Curnier</ns1:RueVoie><ns1:ComplementVoie></ns1:ComplementVoie><ns1:CodePostal>06750</ns1:CodePostal><ns1:Ville>SERANON</ns1:Ville><ns1:CodePays>FR</ns1:CodePays><ns1:LibellePays>France</ns1:LibellePays><ns1:LibelleAdresse>SIEGE SOCIAL</ns1:LibelleAdresse><ns1:Commentaire></ns1:Commentaire></ns1:ContactReturn></ns1:response></ns1:chargementResponse></soapenv:Body></soapenv:Envelope> |
tests/data/astregs/ContactWithWrongMobile.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>13012</ns1:idContact><ns1:CodeContact>AS173957</ns1:CodeContact><ns1:CodeTitreCivilite>035</ns1:CodeTitreCivilite><ns1:Nom>Bar</ns1:Nom><ns1:Prenom></ns1:Prenom><ns1:NomDeJeuneFille></ns1:NomDeJeuneFille><ns1:DateDeNaissance></ns1:DateDeNaissance><ns1:FormuleCivilite></ns1:FormuleCivilite><ns1:IntituleTitre2></ns1:IntituleTitre2><ns1:IntituleTitre3></ns1:IntituleTitre3><ns1:IntituleTitre4>Président de l&#39;</ns1:IntituleTitre4><ns1:SituationDeFamille></ns1:SituationDeFamille><ns1:CodeFonction></ns1:CodeFonction><ns1:LibelleFonction></ns1:LibelleFonction><ns1:TelephoneBureau></ns1:TelephoneBureau><ns1:TelephoneMobile>+33 01 02 03 04 05</ns1:TelephoneMobile><ns1:NumeroDeFax></ns1:NumeroDeFax><ns1:AdresseMail>foo@example.com</ns1:AdresseMail><ns1:PageWeb></ns1:PageWeb><ns1:AdresseDestinataire>Foo-Marc</ns1:AdresseDestinataire><ns1:AdresseComplementaire></ns1:AdresseComplementaire><ns1:ComplementGeographique></ns1:ComplementGeographique><ns1:RueVoie>271 chemin de Curnier</ns1:RueVoie><ns1:ComplementVoie></ns1:ComplementVoie><ns1:CodePostal>06750</ns1:CodePostal><ns1:Ville>SERANON</ns1:Ville><ns1:CodePays>FR</ns1:CodePays><ns1:LibellePays>France</ns1:LibellePays><ns1:LibelleAdresse>SIEGE SOCIAL</ns1:LibelleAdresse><ns1:Commentaire></ns1:Commentaire></ns1:ContactReturn></ns1:response></ns1:chargementResponse></soapenv:Body></soapenv:Envelope> |
tests/test_astregs.py | ||
---|---|---|
130 | 130 |
resp = app.get('/astregs/test/get-association-link-means', params={'association_id': '42'}) |
131 | 131 |
assert len(resp.json['data']) == 2 |
132 | 132 |
assert resp.json['already_paired'] == False |
133 |
for result in resp.json['data']: |
|
134 |
assert 'id' in result |
|
135 |
assert 'text' in result |
|
136 |
assert 'type' in result |
|
137 |
assert 'value' in result |
|
133 |
assert resp.json['data'][0] == { |
|
134 |
'id': 'email', |
|
135 |
'text': 'par courriel vers fo***@***com', |
|
136 |
'value': 'foo@example.com', |
|
137 |
'type': 'email' |
|
138 |
} |
|
139 |
assert resp.json['data'][1] == { |
|
140 |
'id': 'mobile', |
|
141 |
'text': 'par SMS vers 06*****990', |
|
142 |
'value': '0667788990', |
|
143 |
'type': 'mobile' |
|
144 |
} |
|
145 |
assert 'raw_data' in resp.json |
|
138 | 146 | |
139 | 147 |
Link.objects.create(name_id='user_name_id', association_id='42', resource=connector) |
140 | 148 |
resp = app.get('/astregs/test/get-association-link-means', |
141 | 149 |
params={'association_id': '42', 'NameID': 'user_name_id'}) |
142 | 150 |
assert resp.json['already_paired'] == True |
143 | 151 | |
152 |
mocked_post.side_effect = [ |
|
153 |
mock.Mock(content=get_xml_file('Tiers.xml'), status_code=200, |
|
154 |
headers={'Content-Type': 'text/xml'}), |
|
155 |
mock.Mock(content=get_xml_file('ContactWithWrongMobile.xml'), |
|
156 |
status_code=200, headers={'Content-Type': 'text/xml'}) |
|
157 |
] |
|
158 |
resp = app.get('/astregs/test/get-association-link-means', params={'association_id': '42'}) |
|
159 |
assert len(resp.json['data']) == 1 |
|
160 |
assert resp.json['data'][0] == { |
|
161 |
'id': 'email', |
|
162 |
'text': 'par courriel vers fo***@***com', |
|
163 |
'value': 'foo@example.com', |
|
164 |
'type': 'email' |
|
165 |
} |
|
144 | 166 | |
167 |
mocked_post.side_effect = [ |
|
168 |
mock.Mock(content=get_xml_file('Tiers.xml'), status_code=200, |
|
169 |
headers={'Content-Type': 'text/xml'}), |
|
170 |
mock.Mock(content=get_xml_file('ContactWithInternationalMobile.xml'), |
|
171 |
status_code=200, headers={'Content-Type': 'text/xml'}) |
|
172 |
] |
|
173 |
resp = app.get('/astregs/test/get-association-link-means', params={'association_id': '42'}) |
|
174 |
assert len(resp.json['data']) == 2 |
|
175 |
assert resp.json['data'][1] == { |
|
176 |
'id': 'mobile', |
|
177 |
'text': 'par SMS vers 07*****405', |
|
178 |
'value': '0702030405', |
|
179 |
'type': 'mobile' |
|
180 |
} |
|
145 | 181 | |
146 | 182 |
@mock.patch('passerelle.utils.Request.get', side_effect=search_wsdl_side_effect) |
147 | 183 |
@mock.patch('passerelle.utils.Request.post', side_effect=contact_search_side_effect) |
148 |
- |