solis_afi_mss: add an agent endpoint (#51011)

This commit is contained in:
Nicolas Roche 2021-02-10 18:42:25 +01:00
parent 648e0c6f58
commit 6571375a46
2 changed files with 29 additions and 1 deletions

View File

@ -166,7 +166,18 @@ class SolisAfiMss(BaseResource, HTTPResource):
return {'data': adults + children}
@endpoint(
display_category=_('Agent'), display_order=1,
display_category=_('Agent'), display_order=2,
perm='can_access', methods=['get'],
description=_('Retrieve agent'),
parameters={
'email': {'description': _("Agent's email address")},
})
def agent(self, request, email):
index, adults = self.search_from_email(email)[:2]
return {'data': [x for x in adults if x['id'] == index]}
@endpoint(
display_category=_('Agent'), display_order=3,
perm='can_access', methods=['get'],
description=_('Retrieve adults from family composition'),
parameters={

View File

@ -202,6 +202,23 @@ def test_family_error(mocked_get, app, connector):
assert resp.json['err_desc'] == "L'adresse mail n'appartient à aucun agent"
@mock.patch('passerelle.utils.Request.get')
@pytest.mark.parametrize('response1, index, name', [
(RECHERCHE_PAR_EMAIL_1, 389227, 'Jacques ROUSSEAU'),
(RECHERCHE_PAR_EMAIL_2, 388412, 'Louise PIED'),
(RECHERCHE_PAR_EMAIL_3, 388420, 'Marie-Noëlle BASDEVANT'),
(RECHERCHE_PAR_EMAIL_4, 388405, 'Jean-Christophe HUREL'),
])
def test_agent(mocked_get, app, connector, response1, index, name):
mocked_get.side_effect = [response1]
endpoint = get_endpoint('agent') + '?email=foo@dummy.org'
resp = app.get(endpoint)
assert not resp.json['err']
assert len(resp.json['data']) == 1
assert resp.json['data'][0]['id'] == index
assert resp.json['data'][0]['text'] == name
@mock.patch('passerelle.utils.Request.get')
@pytest.mark.parametrize('response1, adults', [
(RECHERCHE_PAR_EMAIL_1, [