caluire-axel: family_info endpoint (#53825)

This commit is contained in:
Lauréline Guérin 2021-05-07 11:37:34 +02:00
parent 8fd262b6e9
commit fe5aa8da1c
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
9 changed files with 371 additions and 40 deletions

View File

@ -20,11 +20,20 @@ def test_link(conn, user):
assert res['err'] == 0
print('\n')
print("GET family info")
url = conn + '/family_info?NameID=%s' % name_id
resp = requests.get(url)
resp.raise_for_status()
data = resp.json()
pprint.pprint(data)
assert data['err'] == 0
print('\n')
print("Deleting link")
url = conn + '/unlink?NameID=%s' % name_id
resp = requests.post(url)
resp.raise_for_status()
res = resp.json()
assert res['err'] == 0
pprint.pprint(res)
assert res['err'] == 0
print('\n')

View File

@ -130,6 +130,40 @@ class CaluireAxel(BaseResource):
link.delete()
return {'link': link_id, 'deleted': True, 'family_id': link.family_id}
def get_family_data(self, family_id):
try:
result = schemas.get_famille_individus(
self, {'PORTAIL': {'GETFAMILLE': {'IDENTFAMILLE': family_id}}}
)
except axel.AxelError as e:
raise APIError(
'Axel error: %s' % e,
err_code='error',
data={'xml_request': e.xml_request, 'xml_response': e.xml_response},
)
family_data = result.json_response['DATA']['PORTAIL']['GETFAMILLE']
for child in family_data.get('MEMBRE', []):
child['id'] = child['IDENT']
child['text'] = '{} {}'.format(child['PRENOM'].strip(), child['NOM'].strip()).strip()
return family_data
@endpoint(
display_category=_('Family account'),
display_order=3,
description=_("Get information about user's family"),
perm='can_access',
parameters={
'NameID': {'description': _('Publik ID')},
},
)
def family_info(self, request, NameID):
link = self.get_link(NameID)
family_data = self.get_family_data(link.family_id)
return {'data': family_data}
class Link(models.Model):
resource = models.ForeignKey(CaluireAxel, on_delete=models.CASCADE)

View File

@ -27,6 +27,7 @@ class Operation(axel.Operation):
find_individus = Operation('FindIndividus')
get_famille_individus = Operation('GetFamilleIndividus')
LINK_SCHEMA = copy.deepcopy(

View File

@ -19,6 +19,25 @@
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="PLACEType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="" />
<xsd:enumeration value="1" />
<xsd:enumeration value="2" />
<xsd:enumeration value="3" />
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="FAMILLEType">
<xsd:sequence>
<xsd:element name="IDENTFAMILLE" type="all:IDENTType"/>
<xsd:element name="PLACE" type="ind:PLACEType"/>
<xsd:element name="SITUATION" type="all:FOOBARType" minOccurs="0" maxOccurs="1"/><!-- CUSTOM -->
<xsd:element name="QUALITER1" type="all:FOOBARType" minOccurs="0" maxOccurs="1"/><!-- CUSTOM -->
<xsd:element name="QUALITER2" type="all:FOOBARType" minOccurs="0" maxOccurs="1"/><!-- CUSTOM -->
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="INDIVIDUType">
<xsd:sequence>
<xsd:element name="IDENT" type="all:IDENTType"/>
@ -31,13 +50,15 @@
<xsd:element name="TELFIXE" type="all:TEL2Type"/>
<xsd:element name="TELPORTABLE" type="all:TEL2Type"/>
<xsd:element name="MAIL" type="all:COURRIELType"/>
<xsd:element name="CSP" type="all:FOOBARType"/><!-- CUSTOM -->
<xsd:element name="EMPLOYEUR" type="all:FOOBARType"/><!-- CUSTOM -->
<xsd:element name="VILLEEMP" type="all:FOOBARType"/><!-- CUSTOM -->
<xsd:element name="PAI" type="all:FOOBARType"/><!-- CUSTOM -->
<xsd:element name="CSP" type="all:FOOBARType" minOccurs="0" maxOccurs="1"/><!-- CUSTOM -->
<xsd:element name="EMPLOYEUR" type="all:FOOBARType" minOccurs="0" maxOccurs="1"/><!-- CUSTOM -->
<xsd:element name="VILLEEMP" type="all:FOOBARType" minOccurs="0" maxOccurs="1"/><!-- CUSTOM -->
<xsd:element name="REGIME1" type="all:FOOBARType" minOccurs="0" maxOccurs="1"/><!-- CUSTOM -->
<xsd:element name="PAI" type="all:FOOBARType" minOccurs="0" maxOccurs="1"/><!-- CUSTOM -->
<xsd:element name="GARDEALTERNEE" type="all:FOOBARType"/><!-- CUSTOM -->
<xsd:element name="ADRESSE" type="adr:ADRESSEType" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
<xsd:element name="FAMILLE" type="ind:FAMILLEType" minOccurs="0" maxOccurs="unbounded"/><!-- CUSTOM -->
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:all="urn:AllAxelTypes">
<xsd:import schemaLocation="./AllAxelTypes.xsd" namespace="urn:AllAxelTypes" />
<xsd:complexType name="PORTAILType">
<xsd:sequence>
<xsd:element ref="GETFAMILLE" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="GETFAMILLEType">
<xsd:sequence>
<xsd:element ref="IDENTFAMILLE"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="IDENTFAMILLE" type="all:IDENTREQUIREDType"/>
<xsd:element name="GETFAMILLE" type="GETFAMILLEType"/>
<xsd:element name="PORTAIL" type="PORTAILType"/>
</xsd:schema>

View File

@ -22,46 +22,15 @@
</xsd:complexType>
</xsd:redefine>
<xsd:complexType name="INDIType">
<xsd:complexContent>
<xsd:extension base="ind:INDIVIDUType">
<xsd:sequence>
<xsd:element ref="FAMILLE" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="FAMILLEType">
<xsd:sequence>
<xsd:element ref="IDENTFAMILLE" />
<xsd:element ref="PLACE"/>
<xsd:element ref="SITUATION" minOccurs="0" maxOccurs="1"/><!-- CUSTOM -->
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="PLACEType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="" />
<xsd:enumeration value="1" />
<xsd:enumeration value="2" />
<xsd:enumeration value="3" />
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="FINDINDIVIDUSType">
<xsd:sequence>
<xsd:element ref="CODE" />
<xsd:element ref="INDIVIDU" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="CODE" type="xsd:integer"/>
<xsd:element name="INDIVIDU" type="INDIType"/>
<xsd:element name="FAMILLE" type="FAMILLEType"/>
<xsd:element name="IDENTFAMILLE" type="all:IDENTType"/>
<xsd:element name="PLACE" type="PLACEType"/>
<xsd:element name="SITUATION" type="all:FOOBARType"/><!-- CUSTOM -->
<xsd:element name="INDIVIDU" type="ind:INDIVIDUType"/>
<xsd:element name="FINDINDIVIDUS" type="FINDINDIVIDUSType"/>

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema xmlns:all="urn:AllAxelTypes" xmlns:ind="urn:Individu" xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<xsd:import schemaLocation="./Individu.xsd" namespace="urn:Individu" />
<xsd:import schemaLocation="./AllAxelTypes.xsd" namespace="urn:AllAxelTypes" />
<xsd:redefine schemaLocation="./R_ShemaResultat.xsd">
<xsd:simpleType name="TYPEType">
<xsd:restriction base="TYPEType">
<xsd:enumeration value="GetFamilleIndividus" />
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="PORTAILType">
<xsd:complexContent>
<xsd:extension base="PORTAILType">
<xsd:sequence>
<xsd:element ref="GETFAMILLE" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:redefine>
<xsd:complexType name="GETFAMILLEType">
<xsd:sequence>
<xsd:element ref="CODE" />
<xsd:element ref="RESPONSABLE1" minOccurs="0" maxOccurs="1" />
<xsd:element ref="RESPONSABLE2" minOccurs="0" maxOccurs="1" />
<xsd:element ref="MEMBRE" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="CODE" type="xsd:integer"/>
<xsd:element name="RESPONSABLE1" type="ind:INDIVIDUType"/>
<xsd:element name="RESPONSABLE2" type="ind:INDIVIDUType"/>
<xsd:element name="MEMBRE" type="ind:INDIVIDUType"/>
<xsd:element name="GETFAMILLE" type="GETFAMILLEType"/>
</xsd:schema>

View File

@ -0,0 +1,197 @@
<PORTAIL>
<GETFAMILLE>
<CODE>0</CODE>
<RESPONSABLE1>
<IDENT>50630</IDENT>
<CIVILITE>MME</CIVILITE>
<NOM>CALUIRE TEST 1</NOM>
<PRENOM>Maman</PRENOM>
<NAISSANCE>07/07/1975</NAISSANCE>
<SEXE>F</SEXE>
<NOMJF />
<TELFIXE>0235384722</TELFIXE>
<TELPORTABLE>0619290316</TELPORTABLE>
<MAIL>mamanbobo@caluire.fr</MAIL>
<CSP />
<EMPLOYEUR />
<VILLEEMP />
<PAI>N</PAI>
<GARDEALTERNEE>N</GARDEALTERNEE>
<ADRESSE>
<ADRESSE3 />
<ADRESSE4 />
<NORUE>30</NORUE>
<ADRESSE1>RUE PASTEUR</ADRESSE1>
<ADRESSE2 />
<CODEPOSTAL>69300</CODEPOSTAL>
<VILLE>CALUIRE ET CUIRE</VILLE>
<PAYS />
<NPAI />
</ADRESSE>
<FAMILLE>
<IDENTFAMILLE>16777</IDENTFAMILLE>
<PLACE>1</PLACE>
<SITUATION>S&#233;par&#233;</SITUATION>
</FAMILLE>
</RESPONSABLE1>
<RESPONSABLE2>
<IDENT>50631</IDENT>
<CIVILITE>M</CIVILITE>
<NOM>CALUIRE TEST 1</NOM>
<PRENOM>Papa </PRENOM>
<NAISSANCE>06/09/1875</NAISSANCE>
<SEXE>M</SEXE>
<NOMJF />
<TELFIXE>02 00 00 00 00</TELFIXE>
<TELPORTABLE>09 00 00 00 00</TELPORTABLE>
<MAIL>papaben@caluire.fr</MAIL>
<CSP />
<EMPLOYEUR />
<VILLEEMP />
<PAI>N</PAI>
<GARDEALTERNEE>N</GARDEALTERNEE>
<ADRESSE>
<ADRESSE3 />
<ADRESSE4 />
<NORUE>50</NORUE>
<ADRESSE1>RUE CURIE</ADRESSE1>
<ADRESSE2 />
<CODEPOSTAL>69300</CODEPOSTAL>
<VILLE>CALUIRE ET CUIRE</VILLE>
<PAYS />
<NPAI />
</ADRESSE>
<FAMILLE>
<IDENTFAMILLE>16777</IDENTFAMILLE>
<PLACE>2</PLACE>
<SITUATION>S&#233;par&#233;</SITUATION>
</FAMILLE>
</RESPONSABLE2>
<MEMBRE>
<IDENT>50632</IDENT>
<CIVILITE />
<NOM>CALUIRE TEST</NOM>
<PRENOM>Enfant 1 </PRENOM>
<NAISSANCE>10/10/2013</NAISSANCE>
<SEXE>M</SEXE>
<NOMJF />
<TELFIXE />
<TELPORTABLE />
<MAIL />
<PAI>N</PAI>
<GARDEALTERNEE>O</GARDEALTERNEE>
<ADRESSE>
<ADRESSE3 />
<ADRESSE4 />
<NORUE>30</NORUE>
<ADRESSE1>RUE PASTEUR</ADRESSE1>
<ADRESSE2 />
<CODEPOSTAL>69300</CODEPOSTAL>
<VILLE>CALUIRE ET CUIRE</VILLE>
<PAYS />
<NPAI />
</ADRESSE>
<FAMILLE>
<IDENTFAMILLE>16777</IDENTFAMILLE>
<PLACE>3</PLACE>
<SITUATION>S&#233;par&#233;</SITUATION>
<QUALITER1>M&#232;re</QUALITER1>
<QUALITER2>P&#232;re</QUALITER2>
</FAMILLE>
</MEMBRE>
<MEMBRE>
<IDENT>50633</IDENT>
<CIVILITE />
<NOM>CALUIRE TEST</NOM>
<PRENOM>Enfant 2 </PRENOM>
<NAISSANCE>12/12/2012</NAISSANCE>
<SEXE>F</SEXE>
<NOMJF />
<TELFIXE />
<TELPORTABLE />
<MAIL />
<PAI>N</PAI>
<GARDEALTERNEE>N</GARDEALTERNEE>
<ADRESSE>
<ADRESSE3 />
<ADRESSE4 />
<NORUE>30</NORUE>
<ADRESSE1>RUE PASTEUR</ADRESSE1>
<ADRESSE2 />
<CODEPOSTAL>69300</CODEPOSTAL>
<VILLE>CALUIRE ET CUIRE</VILLE>
<PAYS />
<NPAI />
</ADRESSE>
<FAMILLE>
<IDENTFAMILLE>16777</IDENTFAMILLE>
<PLACE>3</PLACE>
<SITUATION>S&#233;par&#233;</SITUATION>
<QUALITER1>M&#232;re</QUALITER1>
<QUALITER2>P&#232;re</QUALITER2>
</FAMILLE>
</MEMBRE>
<MEMBRE>
<IDENT>54621</IDENT>
<CIVILITE />
<NOM>CALUIRE TEST</NOM>
<PRENOM>Enfant 3</PRENOM>
<NAISSANCE>15/03/2010</NAISSANCE>
<SEXE>M</SEXE>
<NOMJF />
<TELFIXE />
<TELPORTABLE />
<MAIL />
<REGIME1>MALL</REGIME1>
<PAI>N</PAI>
<GARDEALTERNEE>N</GARDEALTERNEE>
<ADRESSE>
<ADRESSE3 />
<ADRESSE4 />
<NORUE>30</NORUE>
<ADRESSE1>RUE PASTEUR</ADRESSE1>
<ADRESSE2 />
<CODEPOSTAL>69300</CODEPOSTAL>
<VILLE>CALUIRE ET CUIRE</VILLE>
<PAYS />
<NPAI />
</ADRESSE>
<FAMILLE>
<IDENTFAMILLE>16777</IDENTFAMILLE>
<PLACE>3</PLACE>
<SITUATION>S&#233;par&#233;</SITUATION>
<QUALITER1>M&#232;re</QUALITER1>
<QUALITER2>P&#232;re</QUALITER2>
</FAMILLE>
</MEMBRE>
<MEMBRE>
<IDENT>59509</IDENT>
<CIVILITE />
<NOM>CALUIRE TEST </NOM>
<PRENOM>Enfant 5</PRENOM>
<NAISSANCE>16/11/2009</NAISSANCE>
<SEXE>F</SEXE>
<NOMJF />
<TELFIXE />
<TELPORTABLE />
<MAIL />
<GARDEALTERNEE>N</GARDEALTERNEE>
<ADRESSE>
<ADRESSE3 />
<ADRESSE4 />
<NORUE>30</NORUE>
<ADRESSE1>RUE PASTEUR</ADRESSE1>
<ADRESSE2 />
<CODEPOSTAL>69300</CODEPOSTAL>
<VILLE>CALUIRE ET CUIRE</VILLE>
<PAYS />
<NPAI />
</ADRESSE>
<FAMILLE>
<IDENTFAMILLE>16777</IDENTFAMILLE>
<PLACE>3</PLACE>
<SITUATION>S&#233;par&#233;</SITUATION>
</FAMILLE>
</MEMBRE>
</GETFAMILLE>
</PORTAIL>

View File

@ -15,6 +15,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
from contextlib import contextmanager
import mock
@ -365,3 +366,37 @@ def test_unlink_endpoint(app, resource):
assert resp.json['link'] == link.pk
assert resp.json['family_id'] == 'XXX'
assert resp.json['deleted'] is True
def test_family_info_endpoint_axel_error(app, resource):
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
with mock.patch('passerelle.contrib.caluire_axel.schemas.get_famille_individus') as operation:
operation.side_effect = AxelError('FooBar')
resp = app.get('/caluire-axel/test/family_info?NameID=yyy')
assert resp.json['err_desc'] == "Axel error: FooBar"
assert resp.json['err'] == 'error'
def test_family_info_endpoint_no_result(app, resource):
resp = app.get('/caluire-axel/test/family_info?NameID=yyy')
assert resp.json['err_desc'] == "Person not found"
assert resp.json['err'] == 'not-found'
def test_family_info_endpoint(app, resource):
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/family_info.xml')
with open(filepath) as xml:
content = xml.read()
with mock_getdata(content, 'GetFamilleIndividus'):
resp = app.get('/caluire-axel/test/family_info?NameID=yyy')
assert resp.json['err'] == 0
assert set(resp.json['data'].keys()) == set(['CODE', 'MEMBRE', 'RESPONSABLE1', 'RESPONSABLE2'])
assert resp.json['data']['MEMBRE'][0]['id'] == '50632'
assert resp.json['data']['MEMBRE'][0]['text'] == 'Enfant 1 CALUIRE TEST'
assert resp.json['data']['MEMBRE'][1]['id'] == '50633'
assert resp.json['data']['MEMBRE'][1]['text'] == 'Enfant 2 CALUIRE TEST'
assert resp.json['data']['MEMBRE'][2]['id'] == '54621'
assert resp.json['data']['MEMBRE'][2]['text'] == 'Enfant 3 CALUIRE TEST'
assert resp.json['data']['MEMBRE'][3]['id'] == '59509'
assert resp.json['data']['MEMBRE'][3]['text'] == 'Enfant 5 CALUIRE TEST'