toulouse-axel: add active_dui endpoint (#43755)
This commit is contained in:
parent
ff309c1cda
commit
26931166d6
|
@ -133,6 +133,23 @@ class ToulouseAxel(BaseResource):
|
|||
def management_dates(self, request):
|
||||
return {'data': self.get_management_dates()}
|
||||
|
||||
def check_dui(self, post_data):
|
||||
try:
|
||||
result = schemas.ref_verif_dui(self, {'PORTAIL': {'DUI': post_data}})
|
||||
except AxelError as e:
|
||||
raise APIError(
|
||||
'Axel error: %s' % e,
|
||||
err_code='error',
|
||||
data={'xml_request': e.xml_request,
|
||||
'xml_response': e.xml_response})
|
||||
|
||||
dui_data = result.json_response['DATA']['PORTAIL']['DUI']
|
||||
code = dui_data['CODE']
|
||||
if code not in [2, 3]:
|
||||
# 2: RL1; 3: RL2
|
||||
raise APIError('Wrong DUI status', err_code='dui-code-error-%s' % code)
|
||||
return result
|
||||
|
||||
@endpoint(
|
||||
display_category='DUI',
|
||||
display_order=1,
|
||||
|
@ -154,19 +171,13 @@ class ToulouseAxel(BaseResource):
|
|||
|
||||
post_data['IDPERSONNE'] = ''
|
||||
try:
|
||||
result = schemas.ref_verif_dui(self, {'PORTAIL': {'DUI': post_data}})
|
||||
except AxelError as e:
|
||||
raise APIError(
|
||||
'Axel error: %s' % e,
|
||||
err_code='error',
|
||||
data={'xml_request': e.xml_request,
|
||||
'xml_response': e.xml_response})
|
||||
result = self.check_dui(post_data)
|
||||
except APIError as e:
|
||||
if e.err_code == 'error':
|
||||
raise
|
||||
raise APIError('Person not found', err_code='not-found')
|
||||
|
||||
dui_data = result.json_response['DATA']['PORTAIL']['DUI']
|
||||
code = dui_data['CODE']
|
||||
if code not in [2, 3]:
|
||||
# 2: RL1; 3: RL2
|
||||
raise APIError('Person not found', err_code='not-found')
|
||||
link, created = self.link_set.get_or_create(
|
||||
name_id=NameID,
|
||||
defaults={
|
||||
|
@ -205,6 +216,50 @@ class ToulouseAxel(BaseResource):
|
|||
link.delete()
|
||||
return {'link': link_id, 'deleted': True, 'dui': link.dui}
|
||||
|
||||
@endpoint(
|
||||
display_category='DUI',
|
||||
display_order=3,
|
||||
description=_("Check DUI status"),
|
||||
perm='can_access',
|
||||
parameters={
|
||||
'NameID': {'description': _('Publik ID')},
|
||||
})
|
||||
def active_dui(self, request, NameID):
|
||||
# get link if exists
|
||||
try:
|
||||
link = self.get_link(NameID)
|
||||
except APIError:
|
||||
raise APIError('Unknown NameID', err_code='unknown')
|
||||
|
||||
# get family info
|
||||
try:
|
||||
family_data = self.get_family_data(link.dui)
|
||||
except APIError:
|
||||
raise APIError('No family info', err_code='no-family-info')
|
||||
|
||||
# to get the corresponding RL
|
||||
rl = None
|
||||
for key in ['RL1', 'RL2']:
|
||||
if key not in family_data:
|
||||
continue
|
||||
if family_data[key]['IDPERSONNE'] == link.person_id:
|
||||
rl = family_data[key]
|
||||
break
|
||||
if rl is None:
|
||||
raise APIError('No corresponding RL', err_code='no-rl')
|
||||
|
||||
# now check DUI status
|
||||
post_data = {
|
||||
'IDDUI': family_data['IDDUI'],
|
||||
'IDPERSONNE': '',
|
||||
'PRENOM': rl['PRENOM'],
|
||||
'NOM': rl['NOM'],
|
||||
'NAISSANCE': rl['DATENAISSANCE'],
|
||||
}
|
||||
self.check_dui(post_data)
|
||||
|
||||
return {'data': family_data}
|
||||
|
||||
@endpoint(
|
||||
display_order=5,
|
||||
description=_("Get a referential"),
|
||||
|
@ -272,7 +327,7 @@ class ToulouseAxel(BaseResource):
|
|||
|
||||
@endpoint(
|
||||
display_category='DUI',
|
||||
display_order=3,
|
||||
display_order=4,
|
||||
description=_("Get information about user's family"),
|
||||
perm='can_access',
|
||||
parameters={
|
||||
|
@ -285,7 +340,7 @@ class ToulouseAxel(BaseResource):
|
|||
|
||||
@endpoint(
|
||||
display_category='DUI',
|
||||
display_order=4,
|
||||
display_order=5,
|
||||
description=_("Get information about children"),
|
||||
perm='can_access',
|
||||
parameters={
|
||||
|
@ -298,7 +353,7 @@ class ToulouseAxel(BaseResource):
|
|||
|
||||
@endpoint(
|
||||
display_category='DUI',
|
||||
display_order=5,
|
||||
display_order=6,
|
||||
description=_("Get information about a child"),
|
||||
perm='can_access',
|
||||
parameters={
|
||||
|
@ -317,7 +372,7 @@ class ToulouseAxel(BaseResource):
|
|||
|
||||
@endpoint(
|
||||
display_category='DUI',
|
||||
display_order=6,
|
||||
display_order=7,
|
||||
description=_("Get information about a child's contacts"),
|
||||
perm='can_access',
|
||||
parameters={
|
||||
|
@ -519,7 +574,7 @@ class ToulouseAxel(BaseResource):
|
|||
|
||||
@endpoint(
|
||||
display_category='DUI',
|
||||
display_order=7,
|
||||
display_order=8,
|
||||
description=_("Update information about user's family"),
|
||||
perm='can_access',
|
||||
parameters={
|
||||
|
|
|
@ -680,6 +680,92 @@ def test_unlink_endpoint(app, resource):
|
|||
assert resp.json['deleted'] is True
|
||||
|
||||
|
||||
def test_active_dui_endpoint_axel_error(app, resource):
|
||||
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
|
||||
with mock.patch('passerelle.contrib.toulouse_axel.schemas.ref_famille_dui') as operation:
|
||||
operation.side_effect = AxelError('FooBar')
|
||||
resp = app.get('/toulouse-axel/test/active_dui?NameID=yyy')
|
||||
assert resp.json['err_desc'] == "No family info"
|
||||
assert resp.json['err'] == 'no-family-info'
|
||||
|
||||
filepath = os.path.join(os.path.dirname(__file__), 'data/toulouse_axel/family_info.xml')
|
||||
with open(filepath) as xml:
|
||||
content = xml.read()
|
||||
with mock_getdata(content, 'RefFamilleDui'):
|
||||
with mock.patch('passerelle.contrib.toulouse_axel.schemas.ref_verif_dui') as operation:
|
||||
operation.side_effect = AxelError('FooBar')
|
||||
resp = app.get('/toulouse-axel/test/active_dui?NameID=yyy')
|
||||
assert resp.json['err_desc'] == "Axel error: FooBar"
|
||||
assert resp.json['err'] == 'error'
|
||||
|
||||
|
||||
def test_active_dui_endpoint_no_result(app, resource, family_data):
|
||||
resp = app.get('/toulouse-axel/test/active_dui?NameID=yyy')
|
||||
assert resp.json['err_desc'] == "Unknown NameID"
|
||||
assert resp.json['err'] == 'unknown'
|
||||
|
||||
|
||||
def test_active_dui_endpoint_wrong_rl(app, resource):
|
||||
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='1234')
|
||||
filepath = os.path.join(os.path.dirname(__file__), 'data/toulouse_axel/family_info.xml')
|
||||
with open(filepath) as xml:
|
||||
content = xml.read()
|
||||
with mock_getdata(content, 'RefFamilleDui'):
|
||||
resp = app.get('/toulouse-axel/test/active_dui?NameID=yyy')
|
||||
assert resp.json['err_desc'] == "No corresponding RL"
|
||||
assert resp.json['err'] == 'no-rl'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('xml_response,code', [
|
||||
('<IDDUI>XXX</IDDUI><IDPERSONNE/><CODE>0</CODE>', 0),
|
||||
('<IDDUI>XXX</IDDUI><IDPERSONNE>42</IDPERSONNE><CODE>1</CODE>', 1),
|
||||
('<IDDUI>XXX</IDDUI><IDPERSONNE>42</IDPERSONNE><CODE>4</CODE>', 4),
|
||||
])
|
||||
def test_active_dui_endpoint_wrong_dui_code(app, resource, family_data, xml_response, code):
|
||||
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
|
||||
content = '''<PORTAIL>
|
||||
<DUI>
|
||||
%s
|
||||
</DUI>
|
||||
</PORTAIL>''' % xml_response
|
||||
with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
|
||||
with mock_getdata(content, 'RefVerifDui'):
|
||||
resp = app.get('/toulouse-axel/test/active_dui?NameID=yyy')
|
||||
assert resp.json['err_desc'] == "Wrong DUI status"
|
||||
assert resp.json['err'] == 'dui-code-error-%s' % code
|
||||
|
||||
|
||||
@pytest.mark.parametrize('code', [2, 3])
|
||||
def test_active_dui_endpoint(app, resource, family_data, code):
|
||||
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
|
||||
content = '''<PORTAIL>
|
||||
<DUI>
|
||||
<IDDUI>XXX</IDDUI>
|
||||
<IDPERSONNE>42</IDPERSONNE>
|
||||
<CODE>%s</CODE>
|
||||
</DUI>
|
||||
</PORTAIL>''' % code
|
||||
with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_family_data', return_value=family_data):
|
||||
with mock_getdata(content, 'RefVerifDui'):
|
||||
resp = app.get('/toulouse-axel/test/active_dui?NameID=yyy')
|
||||
assert resp.json['err'] == 0
|
||||
assert set(resp.json['data'].keys()) == set([
|
||||
'ADRESSE',
|
||||
'CODEMISEAJOUR',
|
||||
'DEMATFACTURES',
|
||||
'ENFANT',
|
||||
'IDDUI',
|
||||
'NBENFANTACTIF',
|
||||
'NBRLACTIF',
|
||||
'REACTUALISATIONENLIGNE',
|
||||
'REVENUS',
|
||||
'RL1',
|
||||
'RL2',
|
||||
'SITUATIONFAMILIALE',
|
||||
'TELFIXE',
|
||||
])
|
||||
|
||||
|
||||
def test_referential_endpoint_no_result(app, resource):
|
||||
resp = app.get('/toulouse-axel/test/referential/foo/')
|
||||
assert resp.json['err_desc'] == "Referential not found"
|
||||
|
|
Loading…
Reference in New Issue