Projet

Général

Profil

0001-atos_genesys-filter-call_cherche_beneficiaire-result.patch

Benjamin Dauvergne, 28 mai 2019 16:53

Télécharger (5,72 ko)

Voir les différences:

Subject: [PATCH] atos_genesys: filter call_cherche_beneficiaire results
 (#33492)

Create a datasource from contact informations.
 passerelle/apps/atos_genesys/models.py | 62 +++++++++++++++++++++-----
 tests/test_atos_genesys.py             | 23 ++++++++--
 2 files changed, 71 insertions(+), 14 deletions(-)
passerelle/apps/atos_genesys/models.py
363 363
              })
364 364
    def search(self, request, first_name, last_name, date_of_birth):
365 365
        try:
366
            date_of_birth = datetime.datetime.strptime(date_of_birth, '%Y-%m-%d')
366
            date_of_birth = datetime.datetime.strptime(date_of_birth, '%Y-%m-%d').date()
367 367
        except (ValueError, TypeError):
368 368
            raise APIError('invalid date_of_birth: %r' % date_of_birth)
369 369
        beneficiaires = self.call_cherche_beneficiaire(
370 370
            prenom=first_name,
371 371
            nom=last_name,
372 372
            dob=date_of_birth)
373
        response = {'data': []}
373 374
        for beneficiaire in beneficiaires:
374
            ref_per = beneficiaire.get('REF_PER')
375
            if not ref_per:
375
            id_per = beneficiaire.get('ID_PER')
376
            if not id_per:
377
                self.logger.warning('no ID_PER')
376 378
                continue
377
            dossier = self.call_select_usager_by_ref(ref_per)
378
            identification = dossier['IDENTIFICATION'][0]
379
            beneficiaire['ID_PER'] = identification['ID_PER']
380
            beneficiaire['TEL_FIXE'] = identification.get('TEL_FIXE', '')
381
            beneficiaire['TEL_MOBILE'] = identification.get('TEL_MOBILE', '')
382
            beneficiaire['MAIL'] = identification.get('MAIL', '')
383
        return {'data': beneficiaires}
379
            try:
380
                dob = beneficiaire['DATE_NAISSANCE']
381
            except KeyError:
382
                self.logger.warning('id_per %s: no DATE_NAISSANCE', id_per)
383
                continue
384
            try:
385
                dob = datetime.datetime.strptime(dob, '%d/%m/%Y').date()
386
            except (ValueError, TypeError):
387
                self.logger.warning('id_per %s: invalid DATE_NAISSANCE', id_per)
388
                continue
389
            if dob != date_of_birth:
390
                self.logger.debug('ignoring id_per %s different dob %s != %s', id_per, dob, date_of_birth)
391
                continue
392
            dossier = self.call_select_usager(id_per)
393
            try:
394
                identification = dossier['IDENTIFICATION'][0]
395
            except KeyError:
396
                self.logger.warning('id_per %s: dossier is empty', id_per)
397
                continue
398
            assert identification['ID_PER'] == id_per
399
            tel1 = ''.join(c for c in identification.get('TEL_MOBILE', '') if c.isdigit())
400
            tel2 = ''.join(c for c in identification.get('TEL_FIXE', '') if c.isdigit())
401
            email = identification.get('MAIL', '').strip()
402
            channels = beneficiaire['CANAUX'] = []
403
            if tel1:
404
                channels.append({
405
                    'id': 'tel1',
406
                    'text': tel1[:2] + '*****' + tel1[-3:],
407
                    'phone': tel1,
408
                })
409
            if tel2:
410
                channels.append({
411
                    'id': 'tel2',
412
                    'text': tel2[:2] + '*****' + tel2[-3:],
413
                    'phone': tel2,
414
                })
415
            if email:
416
                channels.append({
417
                    'id': 'email1',
418
                    'text': email[:2] + '***@***' + email[-3:],
419
                    'email': email,
420
                })
421
            if not channels:
422
                self.logger.debug('id_per %s: no contact information, ignored', id_per)
423
                continue
424
            response['data'].append(beneficiaire)
425
        return response
384 426

  
385 427
    @endpoint(name='link-by-id-per',
386 428
              methods=['post'],
tests/test_atos_genesys.py
243 243
    <REF_PER>951858</REF_PER>
244 244
    <LIEU_NAIS>ANTIBES (006)</LIEU_NAIS>
245 245
    <PAY_NAIS>FRANCE</PAY_NAIS>
246
    <ID_PER>1234</ID_PER>
246 247
  </ROW>
247 248
</ROWSET>
248 249
</return>'''
249 250

  
250 251
    with utils.mock_url(FAKE_URL + 'WSUsagerPublik/services/PublikService/chercheBeneficiaire', RESPONSE_SEARCH):
251
        with utils.mock_url(FAKE_URL + 'WSUsagerPublik/services/PublikService/selectUsagerByRef',
252
        with utils.mock_url(FAKE_URL + 'WSUsagerPublik/services/PublikService/selectUsager',
252 253
                            RESPONSE_SELECT_USAGER):
253 254
            response = app.get(url + '?' + urlencode({
254 255
                'first_name': 'John',
......
263 264
    assert data['NOMPER'] == 'John'
264 265
    assert data['PRENOMPER'] == 'Doe'
265 266
    assert data['DATE_NAISSANCE'] == '01/01/1925'
266
    assert data['TEL_FIXE'] == '06.44.44.44.44'
267
    assert data['TEL_MOBILE'] == '06.55.55.55.55'
268
    assert data['MAIL'] == 'test@sirus.fr'
267
    assert data['CANAUX'] == [
268
        {
269
            'id': 'tel1',
270
            'text': '06*****555',
271
            'phone': '0655555555',
272
        },
273
        {
274
            'id': 'tel2',
275
            'text': '06*****444',
276
            'phone': '0644444444',
277
        },
278
        {
279
            'id': 'email1',
280
            'text': 'te***@***.fr',
281
            'email': 'test@sirus.fr'
282
        }
283
    ]
269 284

  
270 285

  
271 286
def test_ws_link_by_id_per(app, genesys):
272
-