toulouse-maelis: add RL2 webservices (#68788)
This commit is contained in:
parent
6bdd314d6f
commit
00e5aa1047
|
@ -508,6 +508,56 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
self.call('Family', 'updateFamily', **payload)
|
||||
return {'data': 'ok'}
|
||||
|
||||
@endpoint(
|
||||
display_category='Famille',
|
||||
description='Création du RL2',
|
||||
name='create-rl2',
|
||||
perm='can_access',
|
||||
parameters={'NameID': {'description': 'Publik NameID'}},
|
||||
post={'request_body': {'schema': {'application/json': schemas.CREATE_RL2_SCHEMA}}},
|
||||
)
|
||||
def create_rl2(self, request, NameID, post_data):
|
||||
family_id = self.get_link(NameID).family_id
|
||||
family = self.get_family_raw(family_id)
|
||||
if family['RL2']:
|
||||
raise APIError('RL2 already defined on family', err_code='already-rl2')
|
||||
|
||||
payload = {
|
||||
'dossierNumber': family_id,
|
||||
'categorie': family['category'],
|
||||
'situation': family['situation'],
|
||||
'rl2': post_data,
|
||||
}
|
||||
self.call('Family', 'updateFamily', **payload)
|
||||
return {'data': 'ok'}
|
||||
|
||||
@endpoint(
|
||||
display_category='Famille',
|
||||
description='Modification du RL2',
|
||||
name='update-rl2',
|
||||
perm='can_access',
|
||||
parameters={'NameID': {'description': 'Publik NameID'}},
|
||||
post={'request_body': {'schema': {'application/json': schemas.UPDATE_RL2_SCHEMA}}},
|
||||
)
|
||||
def update_rl2(self, request, NameID, post_data):
|
||||
family_id = self.get_link(NameID).family_id
|
||||
family = self.get_family_raw(family_id)
|
||||
if not family['RL2']:
|
||||
raise APIError('No RL2 to update on family', err_code='no-rl2')
|
||||
self.replace_null_values(post_data)
|
||||
|
||||
rl2 = post_data
|
||||
rl2['num'] = family['RL2']['num']
|
||||
rl2['adresse'] = family['RL2']['adresse']
|
||||
payload = {
|
||||
'dossierNumber': family_id,
|
||||
'categorie': family['category'],
|
||||
'situation': family['situation'],
|
||||
'rl2': rl2,
|
||||
}
|
||||
self.call('Family', 'updateFamily', **payload)
|
||||
return {'data': 'ok'}
|
||||
|
||||
@endpoint(
|
||||
display_category='Famille',
|
||||
description="Mise à jour des coordonnées d'une personne",
|
||||
|
|
|
@ -679,6 +679,13 @@ del UPDATE_RL1_SCHEMA['properties']['contact']
|
|||
del UPDATE_RL1_SCHEMA['properties']['profession']
|
||||
del UPDATE_RL1_SCHEMA['properties']['CAFInfo']
|
||||
|
||||
CREATE_RL2_SCHEMA = copy.deepcopy(RLINFO_SCHEMA)
|
||||
CREATE_RL2_SCHEMA['unflatten'] = True
|
||||
del CREATE_RL2_SCHEMA['properties']['contact']
|
||||
del CREATE_RL2_SCHEMA['properties']['profession']
|
||||
del CREATE_RL2_SCHEMA['properties']['CAFInfo']
|
||||
|
||||
UPDATE_RL2_SCHEMA = copy.deepcopy(UPDATE_RL1_SCHEMA)
|
||||
|
||||
UPDATE_COORDINATE_SCHEMA = {
|
||||
'$schema': 'http://json-schema.org/draft-04/schema#',
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<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>
|
||||
<rl2>
|
||||
<lastname>DOE</lastname>
|
||||
<firstname>JANE</firstname>
|
||||
<quality>MERE</quality>
|
||||
<civility>MME</civility>
|
||||
<dateBirth>1940-06-22</dateBirth>
|
||||
<adresse>
|
||||
<num>170</num>
|
||||
<street1>Chateau d'eau</street1>
|
||||
<town>Paris</town>
|
||||
<zipcode>75014</zipcode>
|
||||
</adresse>
|
||||
</rl2>
|
||||
</ns0:updateFamily>
|
||||
</soap-env:Body>
|
||||
</soap-env:Envelope>
|
|
@ -0,0 +1,31 @@
|
|||
<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>
|
||||
<rl2>
|
||||
<num>613879</num>
|
||||
<lastname>DOE</lastname>
|
||||
<firstname>JANE</firstname>
|
||||
<quality>MERE</quality>
|
||||
<civility>MME</civility>
|
||||
<dateBirth>1940-06-22</dateBirth>
|
||||
<adresse>
|
||||
<num>170</num>
|
||||
<street1>Chateau d'eau</street1>
|
||||
<town>Paris</town>
|
||||
<zipcode>75014</zipcode>
|
||||
</adresse>
|
||||
</rl2>
|
||||
</ns0:updateFamily>
|
||||
</soap-env:Body>
|
||||
</soap-env:Envelope>
|
|
@ -1237,6 +1237,173 @@ def test_update_rl1_connection_error(mocked_post, mocked_get, con, app):
|
|||
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_rl2(mocked_post, mocked_get, con, app):
|
||||
mocked_get.return_value = FAMILY_SERVICE_WSDL
|
||||
mocked_post.side_effect = [READ_RL1_FAMILY, UPDATE_FAMILY]
|
||||
url = get_endpoint('create-rl2')
|
||||
params = {
|
||||
'civility': 'MME',
|
||||
'firstname': 'JANE',
|
||||
'lastname': 'DOE',
|
||||
'quality': 'MERE',
|
||||
'dateBirth': '1940-06-22',
|
||||
'adresse/num': '170',
|
||||
'adresse/street1': "Chateau d'eau",
|
||||
'adresse/town': 'Paris',
|
||||
'adresse/zipcode': '75014',
|
||||
}
|
||||
|
||||
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_rl2.xml')
|
||||
assert resp.json['err'] == 0
|
||||
assert resp.json['data'] == 'ok'
|
||||
|
||||
|
||||
def test_create_rl2_not_linked_error(con, app):
|
||||
url = get_endpoint('create-rl2')
|
||||
params = {
|
||||
'civility': 'MME',
|
||||
'firstname': 'JANE',
|
||||
'lastname': 'DOE',
|
||||
'quality': 'MERE',
|
||||
'dateBirth': '1940-06-22',
|
||||
'adresse/num': '170',
|
||||
'adresse/street1': "Chateau d'eau",
|
||||
'adresse/town': 'Paris',
|
||||
'adresse/zipcode': '75014',
|
||||
}
|
||||
|
||||
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_rl2_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-rl2')
|
||||
params = {
|
||||
'civility': 'MME',
|
||||
'firstname': 'JANE',
|
||||
'lastname': 'DOE',
|
||||
'quality': 'MERE',
|
||||
'dateBirth': '1940-06-22',
|
||||
'adresse/num': '170',
|
||||
'adresse/street1': "Chateau d'eau",
|
||||
'adresse/town': 'Paris',
|
||||
'adresse/zipcode': '75014',
|
||||
}
|
||||
|
||||
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_rl2_already_exists_error(mocked_post, mocked_get, con, app):
|
||||
mocked_get.return_value = FAMILY_SERVICE_WSDL
|
||||
mocked_post.return_value = READ_FAMILY
|
||||
url = get_endpoint('create-rl2')
|
||||
params = {
|
||||
'civility': 'MME',
|
||||
'firstname': 'JANE',
|
||||
'lastname': 'DOE',
|
||||
'quality': 'MERE',
|
||||
'dateBirth': '1940-06-22',
|
||||
'adresse/num': '170',
|
||||
'adresse/street1': "Chateau d'eau",
|
||||
'adresse/town': 'Paris',
|
||||
'adresse/zipcode': '75014',
|
||||
}
|
||||
|
||||
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-rl2'
|
||||
assert resp.json['err_desc'] == 'RL2 already defined on family'
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
@mock.patch('passerelle.utils.Request.post')
|
||||
def test_update_rl2(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-rl2')
|
||||
params = {
|
||||
'civility': 'MME',
|
||||
'firstname': 'JANE',
|
||||
'lastname': 'DOE',
|
||||
'quality': 'MERE',
|
||||
'dateBirth': '1940-06-22',
|
||||
}
|
||||
|
||||
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_update_rl2.xml')
|
||||
assert resp.json['err'] == 0
|
||||
|
||||
|
||||
def test_update_rl2_not_linked_error(con, app):
|
||||
url = get_endpoint('update-rl2')
|
||||
params = {
|
||||
'civility': 'MME',
|
||||
'firstname': 'JANE',
|
||||
'lastname': 'DOE',
|
||||
'quality': 'MERE',
|
||||
'dateBirth': '1940-06-22',
|
||||
}
|
||||
|
||||
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_update_rl2_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-rl2')
|
||||
params = {
|
||||
'civility': 'MME',
|
||||
'firstname': 'JANE',
|
||||
'lastname': 'DOE',
|
||||
'quality': 'MERE',
|
||||
'dateBirth': '1940-06-22',
|
||||
}
|
||||
|
||||
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_update_rl2_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-rl2')
|
||||
params = {
|
||||
'civility': 'MME',
|
||||
'firstname': 'JANE',
|
||||
'lastname': 'DOE',
|
||||
'quality': 'MERE',
|
||||
'dateBirth': '1940-06-22',
|
||||
}
|
||||
|
||||
Link.objects.create(resource=con, family_id='1312', name_id='local')
|
||||
resp = app.post_json(url + '?NameID=local', params=params)
|
||||
assert resp.json['err'] == 'no-rl2'
|
||||
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_update_coordinate(mocked_post, mocked_get, con, app):
|
||||
|
|
Loading…
Reference in New Issue