Projet

Général

Profil

0003-caluire-axel-children_info-endpoint-53825.patch

Lauréline Guérin, 07 mai 2021 14:48

Télécharger (4,16 ko)

Voir les différences:

Subject: [PATCH 3/4] caluire-axel: children_info endpoint (#53825)

 functests/caluire_axel/test_caluire_axel.py |  9 ++++++
 passerelle/contrib/caluire_axel/models.py   | 14 +++++++++
 tests/test_caluire_axel.py                  | 34 +++++++++++++++++++++
 3 files changed, 57 insertions(+)
functests/caluire_axel/test_caluire_axel.py
29 29
    assert data['err'] == 0
30 30
    print('\n')
31 31

  
32
    print("GET children info")
33
    url = conn + '/children_info?NameID=%s' % (name_id)
34
    resp = requests.get(url)
35
    resp.raise_for_status()
36
    res = resp.json()
37
    pprint.pprint(res)
38
    assert res['err'] == 0
39
    print('\n')
40

  
32 41
    print("Deleting link")
33 42
    url = conn + '/unlink?NameID=%s' % name_id
34 43
    resp = requests.post(url)
passerelle/contrib/caluire_axel/models.py
164 164
        family_data = self.get_family_data(link.family_id)
165 165
        return {'data': family_data}
166 166

  
167
    @endpoint(
168
        display_category=_('Family account'),
169
        display_order=4,
170
        description=_("Get information about children"),
171
        perm='can_access',
172
        parameters={
173
            'NameID': {'description': _('Publik ID')},
174
        },
175
    )
176
    def children_info(self, request, NameID):
177
        link = self.get_link(NameID)
178
        family_data = self.get_family_data(link.family_id)
179
        return {'data': family_data.get('MEMBRE', [])}
180

  
167 181

  
168 182
class Link(models.Model):
169 183
    resource = models.ForeignKey(CaluireAxel, on_delete=models.CASCADE)
tests/test_caluire_axel.py
400 400
    assert resp.json['data']['MEMBRE'][2]['text'] == 'Enfant 3 CALUIRE TEST'
401 401
    assert resp.json['data']['MEMBRE'][3]['id'] == '59509'
402 402
    assert resp.json['data']['MEMBRE'][3]['text'] == 'Enfant 5 CALUIRE TEST'
403

  
404

  
405
def test_children_info_endpoint_axel_error(app, resource):
406
    Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
407
    with mock.patch('passerelle.contrib.caluire_axel.schemas.get_famille_individus') as operation:
408
        operation.side_effect = AxelError('FooBar')
409
        resp = app.get('/caluire-axel/test/children_info?NameID=yyy')
410
    assert resp.json['err_desc'] == "Axel error: FooBar"
411
    assert resp.json['err'] == 'error'
412

  
413

  
414
def test_children_info_endpoint_no_result(app, resource):
415
    resp = app.get('/caluire-axel/test/children_info?NameID=yyy')
416
    assert resp.json['err_desc'] == "Person not found"
417
    assert resp.json['err'] == 'not-found'
418

  
419

  
420
def test_children_info_endpoint(app, resource):
421
    Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
422
    filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/family_info.xml')
423
    with open(filepath) as xml:
424
        content = xml.read()
425
    with mock_getdata(content, 'GetFamilleIndividus'):
426
        resp = app.get('/caluire-axel/test/children_info?NameID=yyy')
427
    assert resp.json['err'] == 0
428
    assert len(resp.json['data']) == 4
429
    assert resp.json['data'][0]['id'] == '50632'
430
    assert resp.json['data'][0]['text'] == 'Enfant 1 CALUIRE TEST'
431
    assert resp.json['data'][1]['id'] == '50633'
432
    assert resp.json['data'][1]['text'] == 'Enfant 2 CALUIRE TEST'
433
    assert resp.json['data'][2]['id'] == '54621'
434
    assert resp.json['data'][2]['text'] == 'Enfant 3 CALUIRE TEST'
435
    assert resp.json['data'][3]['id'] == '59509'
436
    assert resp.json['data'][3]['text'] == 'Enfant 5 CALUIRE TEST'
403
-