toulouse_maelis: add child webservices (#68788)

This commit is contained in:
Nicolas Roche 2022-09-06 10:56:53 +02:00
parent 00e5aa1047
commit f6cad0ba22
7 changed files with 296 additions and 0 deletions

View File

@ -558,6 +558,66 @@ class ToulouseMaelis(BaseResource, HTTPResource):
self.call('Family', 'updateFamily', **payload)
return {'data': 'ok'}
@endpoint(
display_category='Famille',
description="Ajout d'un enfant",
name='create-child',
perm='can_access',
parameters={
'NameID': {'description': 'Publik NameID'},
'force': {
'description': 'boolean to bypass doublon error',
'type': 'bool',
'example_value': 'false',
},
},
post={'request_body': {'schema': {'application/json': schemas.CREATE_CHILD_SCHEMA}}},
)
def create_child(self, request, NameID, post_data, force=False):
family_id = self.get_link(NameID).family_id
payload = {
'numDossier': family_id,
'isForceCreateChild': force,
'child': post_data,
}
response = self.call('Family', 'createChild', **payload)
data = serialize_object(response)
child_id = data.get('number')
if not child_id:
errors = data.get('childErrorList') or []
raise APIError(' ; '.join(errors), err_code='already-child')
return {'data': {'child_id': child_id}}
@endpoint(
display_category='Famille',
description="Modification d'un enfant",
name='update-child',
perm='can_access',
parameters={
'NameID': {'description': 'Publik NameID'},
'child_id': {'description': "Numéro de l'enfant"},
},
post={'request_body': {'schema': {'application/json': schemas.UPDATE_CHILD_SCHEMA}}},
)
def update_child(self, request, NameID, child_id, post_data):
family_id = self.get_link(NameID).family_id
family = self.get_family_raw(family_id)
if child_id not in [x['num'] for x in family['childList']]:
raise APIError('No child %s to update on family' % child_id, err_code='no-child')
self.replace_null_values(post_data)
child = post_data
child['num'] = child_id
payload = {
'dossierNumber': family_id,
'categorie': family['category'],
'situation': family['situation'],
'childList': [child],
}
self.call('Family', 'updateFamily', **payload)
return {'data': 'ok'}
@endpoint(
display_category='Famille',
description="Mise à jour des coordonnées d'une personne",

View File

@ -687,6 +687,17 @@ del CREATE_RL2_SCHEMA['properties']['CAFInfo']
UPDATE_RL2_SCHEMA = copy.deepcopy(UPDATE_RL1_SCHEMA)
CREATE_CHILD_SCHEMA = copy.deepcopy(CHILD_SCHEMA)
CREATE_CHILD_SCHEMA['unflatten'] = True
del CREATE_CHILD_SCHEMA['properties']['dietcode']
del CREATE_CHILD_SCHEMA['properties']['bPhoto']
del CREATE_CHILD_SCHEMA['properties']['bLeaveAlone']
del CREATE_CHILD_SCHEMA['properties']['fsl']
del CREATE_CHILD_SCHEMA['properties']['medicalRecord']
del CREATE_CHILD_SCHEMA['properties']['paiInfoBean']
UPDATE_CHILD_SCHEMA = copy.deepcopy(CREATE_CHILD_SCHEMA)
UPDATE_COORDINATE_SCHEMA = {
'$schema': 'http://json-schema.org/draft-04/schema#',
'title': 'Update coordinate',

View File

@ -0,0 +1,25 @@
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>maelis-webservice</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">maelis-password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap-env:Header>
<soap-env:Body>
<ns0:createChild xmlns:ns0="family.ws.maelis.sigec.com">
<numDossier>1312</numDossier>
<child>
<firstname>JANNIS</firstname>
<lastname>DOE</lastname>
<sexe>F</sexe>
<birth>
<dateBirth>1943-01-19</dateBirth>
<place>Port Arthur</place>
</birth>
</child>
<isForceCreateChild>false</isForceCreateChild>
</ns0:createChild>
</soap-env:Body>
</soap-env:Envelope>

View File

@ -0,0 +1,27 @@
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>maelis-webservice</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">maelis-password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap-env:Header>
<soap-env:Body>
<ns0:updateFamily xmlns:ns0="family.ws.maelis.sigec.com">
<dossierNumber>1312</dossierNumber>
<categorie>BI</categorie>
<situation>M</situation>
<childList>
<num>613880</num>
<lastname>DOE</lastname>
<firstname>JANNIS</firstname>
<sexe>F</sexe>
<birth>
<dateBirth>1943-01-19</dateBirth>
<place>Port Arthur</place>
</birth>
</childList>
</ns0:updateFamily>
</soap-env:Body>
</soap-env:Envelope>

View File

@ -0,0 +1,9 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:createChildResponse xmlns:ns2="family.ws.maelis.sigec.com">
<resultBean>
<number>613880</number>
</resultBean>
</ns2:createChildResponse>
</soap:Body>
</soap:Envelope>

View File

@ -0,0 +1,11 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:createChildResponse xmlns:ns2="family.ws.maelis.sigec.com">
<resultBean>
<number>0</number>
<childErrorList>E54a : Il existe déjà un enfant correspondant au nom [DOE], prénom [JANNIS], date de naissance [19/01/1943] - Personne n°[613988] - Famille n°[196562]</childErrorList>
<childErrorList>E54a : Il existe déjà un enfant correspondant au nom [DOE], prénom [JANNIS], date de naissance [19/01/1943] - Personne n°[613989] - Famille n°[196563]</childErrorList>
</resultBean>
</ns2:createChildResponse>
</soap:Body>
</soap:Envelope>

View File

@ -62,6 +62,8 @@ IS_CHILD_EXISTS_FALSE = FakedResponse(
)
CREATE_FAMILY = FakedResponse(content=get_xml_file('R_create_family.xml'), status_code=200)
CREATE_FAMILY_ERR = FakedResponse(content=get_xml_file('R_create_family_error.xml'), status_code=200)
CREATE_CHILD = FakedResponse(content=get_xml_file('R_create_child.xml'), status_code=200)
CREATE_CHILD_ERR = FakedResponse(content=get_xml_file('R_create_child_error.xml'), status_code=200)
UPDATE_FAMILY = FakedResponse(content=get_xml_file('R_update_family.xml'), status_code=200)
UPDATE_FAMILY_ERR = FakedResponse(content=get_xml_file('R_update_family_error.xml'), status_code=200)
UPDATE_FAMILY_500 = FakedResponse(content=get_xml_file('R_update_family_soap_error.xml'), status_code=500)
@ -1404,6 +1406,157 @@ def test_update_rl2_not_exists_error(mocked_post, mocked_get, con, app):
assert resp.json['err_desc'] == 'No RL2 to update on family'
@mock.patch('passerelle.utils.Request.get')
@mock.patch('passerelle.utils.Request.post')
def test_create_child(mocked_post, mocked_get, con, app):
mocked_get.return_value = FAMILY_SERVICE_WSDL
mocked_post.return_value = CREATE_CHILD
url = get_endpoint('create-child')
params = {
'lastname': 'DOE',
'firstname': 'JANNIS',
'sexe': 'F',
'birth/dateBirth': '1943-01-19',
'birth/place': 'Port Arthur',
}
Link.objects.create(resource=con, family_id='1312', name_id='local')
resp = app.post_json(url + '?NameID=local', params=params)
assert_sent_payload(mocked_post, 'Q_create_child.xml')
assert resp.json['err'] == 0
assert resp.json['data'] == {'child_id': 613880}
def test_create_child_not_linked_error(con, app):
url = get_endpoint('create-child')
params = {
'lastname': 'DOE',
'firstname': 'JANNIS',
'sexe': 'F',
'birth/dateBirth': '1943-01-19',
'birth/place': 'Port Arthur',
}
resp = app.post_json(url + '?NameID=local', params=params)
assert resp.json['err'] == 'not-linked'
assert resp.json['err_desc'] == 'User not linked to family'
@mock.patch('passerelle.utils.Request.get')
@mock.patch('passerelle.utils.Request.post')
def test_create_child_connection_error(mocked_post, mocked_get, con, app):
mocked_get.return_value = FAMILY_SERVICE_WSDL
mocked_post.side_effect = CONNECTION_ERROR
url = get_endpoint('create-child')
params = {
'lastname': 'DOE',
'firstname': 'JANNIS',
'sexe': 'F',
'birth/dateBirth': '1943-01-19',
'birth/place': 'Port Arthur',
}
Link.objects.create(resource=con, family_id='1312', name_id='local')
resp = app.post_json(url + '?NameID=local', params=params, status=500)
assert resp.json['err']
assert resp.json['err_desc'] == 'No address associated with hostname'
@mock.patch('passerelle.utils.Request.get')
@mock.patch('passerelle.utils.Request.post')
def test_create_child_maelis_error(mocked_post, mocked_get, con, app):
mocked_get.return_value = FAMILY_SERVICE_WSDL
mocked_post.return_value = CREATE_CHILD_ERR
url = get_endpoint('create-child')
params = {
'lastname': 'DOE',
'firstname': 'JANNIS',
'sexe': 'F',
'birth/dateBirth': '1943-01-19',
'birth/place': 'Port Arthur',
}
Link.objects.create(resource=con, family_id='1312', name_id='local')
resp = app.post_json(url + '?NameID=local', params=params)
assert resp.json['err'] == 'already-child'
assert 'Il existe déjà' in resp.json['err_desc']
@mock.patch('passerelle.utils.Request.get')
@mock.patch('passerelle.utils.Request.post')
def test_update_child(mocked_post, mocked_get, con, app):
mocked_get.return_value = FAMILY_SERVICE_WSDL
mocked_post.side_effect = [READ_FAMILY, UPDATE_FAMILY]
url = get_endpoint('update-child')
params = {
'lastname': 'DOE',
'firstname': 'JANNIS',
'sexe': 'F',
'birth/dateBirth': '1943-01-19',
'birth/place': 'Port Arthur',
}
Link.objects.create(resource=con, family_id='1312', name_id='local')
resp = app.post_json(url + '?NameID=local&child_id=613880', params=params)
assert_sent_payload(mocked_post, 'Q_update_child.xml')
assert resp.json['err'] == 0
def test_update_child_not_linked_error(con, app):
url = get_endpoint('update-child')
params = {
'lastname': 'DOE',
'firstname': 'JANNIS',
'sexe': 'F',
'birth/dateBirth': '1943-01-19',
'birth/place': 'Port Arthur',
}
resp = app.post_json(url + '?NameID=local&child_id=613880', params=params)
assert resp.json['err'] == 'not-linked'
assert resp.json['err_desc'] == 'User not linked to family'
@mock.patch('passerelle.utils.Request.get')
@mock.patch('passerelle.utils.Request.post')
def test_update_child_connection_error(mocked_post, mocked_get, con, app):
mocked_get.return_value = FAMILY_SERVICE_WSDL
mocked_post.side_effect = CONNECTION_ERROR
url = get_endpoint('update-child')
params = {
'lastname': 'DOE',
'firstname': 'JANNIS',
'sexe': 'F',
'birth/dateBirth': '1943-01-19',
'birth/place': 'Port Arthur',
}
Link.objects.create(resource=con, family_id='1312', name_id='local')
resp = app.post_json(url + '?NameID=local&child_id=613880', params=params, status=500)
assert resp.json['err']
assert resp.json['err_desc'] == 'No address associated with hostname'
@mock.patch('passerelle.utils.Request.get')
@mock.patch('passerelle.utils.Request.post')
def test_update_child_not_exists_error(mocked_post, mocked_get, con, app):
mocked_get.return_value = FAMILY_SERVICE_WSDL
mocked_post.return_value = READ_RL1_FAMILY
url = get_endpoint('update-child')
params = {
'lastname': 'DOE',
'firstname': 'JANNIS',
'sexe': 'F',
'birth/dateBirth': '1943-01-19',
'birth/place': 'Port Arthur',
}
Link.objects.create(resource=con, family_id='1312', name_id='local')
resp = app.post_json(url + '?NameID=local&child_id=42', params=params)
assert resp.json['err'] == 'no-child'
assert resp.json['err_desc'] == 'No child 42 to update on family'
@mock.patch('passerelle.utils.Request.get')
@mock.patch('passerelle.utils.Request.post')
def test_update_coordinate(mocked_post, mocked_get, con, app):