toulouse-maelis: add endpoint to create or update quotients (#71698)
This commit is contained in:
parent
626b79fa44
commit
11882bb3f9
|
@ -376,6 +376,7 @@ def create_data(request, conn, referentials):
|
|||
'name_id': name_id, # linked
|
||||
'family_id': str(create_result['data']['number']),
|
||||
'lastname': lastname,
|
||||
'rl1_num': data['RL1']['num'],
|
||||
'family_payload': create_family_payload,
|
||||
'data': data,
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
[
|
||||
{
|
||||
"yearRev": 2021,
|
||||
"dateStart": "2022-01-02T00:00:00+01:00",
|
||||
"dateEnd": "2022-12-31T00:00:00+01:00",
|
||||
"mtt": 1500.33,
|
||||
"cdquo": "QS",
|
||||
"codeUti": null,
|
||||
"cdquo_text": "QUOTIENT SCOLAIRE"
|
||||
},
|
||||
{
|
||||
"yearRev": 2020,
|
||||
"dateStart": "2022-01-02T00:00:00+01:00",
|
||||
"dateEnd": "2022-12-31T00:00:00+01:00",
|
||||
"mtt": 1500.33,
|
||||
"cdquo": "QS",
|
||||
"codeUti": null,
|
||||
"cdquo_text": "QUOTIENT SCOLAIRE"
|
||||
},
|
||||
{
|
||||
"yearRev": 2021,
|
||||
"dateStart": "2022-01-01T00:00:00+01:00",
|
||||
"dateEnd": "2022-01-01T00:00:00+01:00",
|
||||
"mtt": 1500.33,
|
||||
"cdquo": "QS",
|
||||
"codeUti": null,
|
||||
"cdquo_text": "QUOTIENT SCOLAIRE"
|
||||
}
|
||||
]
|
|
@ -752,3 +752,49 @@ def test_update_child_indicator(conn, update_data):
|
|||
resp.raise_for_status()
|
||||
assert resp.json()['err'] == 0
|
||||
assert diff_family(conn, update_data['name_id'], 'test_update_family.json')
|
||||
|
||||
|
||||
def test_update_quotient(conn, create_data):
|
||||
unlink(conn, create_data['name_id'])
|
||||
link(conn, create_data)
|
||||
|
||||
# add quotient
|
||||
url = conn + '/update-quotient?NameID=%s&rl_id=%s' % (create_data['name_id'], create_data['rl1_num'])
|
||||
payload = {
|
||||
'yearRev': '2021',
|
||||
'dateStart': '2022-01-01',
|
||||
'dateEnd': '2022-12-31',
|
||||
'mtt': '1500.33',
|
||||
'cdquo': 'QS',
|
||||
}
|
||||
resp = requests.post(url, json=payload)
|
||||
resp.raise_for_status()
|
||||
assert resp.json()['err'] == 0
|
||||
data = read_family(conn, create_data['name_id'])
|
||||
assert data['RL1']['quotientList'] == [
|
||||
{
|
||||
'yearRev': 2021,
|
||||
'dateStart': '2022-01-01T00:00:00+01:00',
|
||||
'dateEnd': '2022-12-31T00:00:00+01:00',
|
||||
'mtt': 1500.33,
|
||||
'cdquo': 'QS',
|
||||
'codeUti': None,
|
||||
'cdquo_text': 'QUOTIENT SCOLAIRE',
|
||||
}
|
||||
]
|
||||
|
||||
# add quotient
|
||||
payload['dateStart'] = '2022-01-02'
|
||||
resp = requests.post(url, json=payload)
|
||||
resp.raise_for_status()
|
||||
assert resp.json()['err'] == 0
|
||||
data = read_family(conn, create_data['name_id'])
|
||||
assert len(data['RL1']['quotientList']) == 2
|
||||
|
||||
# add quotient on another income year
|
||||
payload['yearRev'] = '2020'
|
||||
resp = requests.post(url, json=payload)
|
||||
resp.raise_for_status()
|
||||
assert resp.json()['err'] == 0
|
||||
data = diff_rlg(conn, create_data['name_id'], 1, 'test_update_quotient.json', 'quotientList')
|
||||
assert len(data['RL1']['quotientList']) == 3
|
||||
|
|
|
@ -275,6 +275,8 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
self.add_text_value('Organ', data, ['CAFInfo', 'organ'])
|
||||
for indicator in data['indicatorList']:
|
||||
self.add_text_value_to_rl_indicator(indicator)
|
||||
for quotient in data['quotientList']:
|
||||
self.add_text_value('Quotient', quotient, ['cdquo'])
|
||||
|
||||
# sort indicators
|
||||
if data['indicatorList']:
|
||||
|
@ -1086,6 +1088,29 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
self.call('Family', 'updatePersonIndicatorList', numPerson=rl_id, **post_data)
|
||||
return {'data': 'ok'}
|
||||
|
||||
@endpoint(
|
||||
display_category='Famille',
|
||||
description="Créer ou mettre à jour un quotient d'un responsable légal",
|
||||
name='update-quotient',
|
||||
perm='can_access',
|
||||
parameters={
|
||||
'NameID': {'description': 'Publik NameID'},
|
||||
'rl_id': {'description': "Numéro du responsable légal"},
|
||||
},
|
||||
post={'request_body': {'schema': {'application/json': schemas.UPDATE_QUOTIENT_SCHEMA}}},
|
||||
)
|
||||
def update_quotient(self, request, NameID, rl_id, post_data):
|
||||
family_id = self.get_link(NameID).family_id
|
||||
self.assert_post_data_in_referential('Quotient', post_data, ['cdquo'])
|
||||
|
||||
payload = {
|
||||
'dossierNumber': family_id,
|
||||
'personNumber': rl_id,
|
||||
'quotient': post_data,
|
||||
}
|
||||
self.call('Family', 'createUpdateQuotient', **payload)
|
||||
return {'data': 'ok'}
|
||||
|
||||
@endpoint(
|
||||
display_category='Famille',
|
||||
description="Création d'une personne à prévenir en cas d'urgence",
|
||||
|
|
|
@ -720,3 +720,39 @@ UPDATE_INDICATOR_SCHEMA = {
|
|||
'additionalProperties': False,
|
||||
'unflatten': True,
|
||||
}
|
||||
|
||||
UPDATE_QUOTIENT_SCHEMA = {
|
||||
'$schema': 'http://json-schema.org/draft-04/schema#',
|
||||
'title': 'Family persons',
|
||||
'description': "Mise à jours des quotients sur les responsables légaux",
|
||||
'type': 'object',
|
||||
'required': ['yearRev', 'dateStart', 'dateEnd', 'mtt', 'cdquo'],
|
||||
'properties': {
|
||||
'yearRev': {
|
||||
'description': 'Année de revenu',
|
||||
'type': 'string',
|
||||
'pattern': '^[0-9]{4}$',
|
||||
},
|
||||
'dateStart': {
|
||||
'description': 'Date de début',
|
||||
'type': 'string',
|
||||
'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
|
||||
},
|
||||
'dateEnd': {
|
||||
'description': 'Date de fin',
|
||||
'type': 'string',
|
||||
'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$',
|
||||
},
|
||||
'mtt': {
|
||||
'description': 'Montant',
|
||||
'type': 'string',
|
||||
'pattern': r'^[0-9]+\.?[0-9]*$',
|
||||
},
|
||||
'cdquo': {
|
||||
'description': 'Code du quotient (depuis référentiel)',
|
||||
'type': 'string',
|
||||
'pattern': '.+',
|
||||
},
|
||||
},
|
||||
'additionalProperties': False,
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<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:createUpdateQuotient xmlns:ns0="family.ws.maelis.sigec.com">
|
||||
<dossierNumber>1312</dossierNumber>
|
||||
<personNumber>613878</personNumber>
|
||||
<quotient>
|
||||
<yearRev>2021</yearRev>
|
||||
<dateStart>2022-10-01</dateStart>
|
||||
<dateEnd>2023-01-31</dateEnd>
|
||||
<mtt>1500.33</mtt>
|
||||
<cdquo>QS</cdquo>
|
||||
</quotient>
|
||||
</ns0:createUpdateQuotient>
|
||||
</soap-env:Body>
|
||||
</soap-env:Envelope>
|
|
@ -0,0 +1,5 @@
|
|||
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<soap:Body>
|
||||
<ns2:createUpdateQuotientResponse xmlns:ns2="family.ws.maelis.sigec.com"/>
|
||||
</soap:Body>
|
||||
</soap:Envelope>
|
|
@ -0,0 +1,13 @@
|
|||
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<soap:Body>
|
||||
<soap:Fault>
|
||||
<faultcode>soap:Server</faultcode>
|
||||
<faultstring>E07 : Il existe déjà un quotient postérieur pour cette période</faultstring>
|
||||
<detail>
|
||||
<ns1:MaelisFamilyException xmlns:ns1="family.ws.maelis.sigec.com">
|
||||
<message xmlns:ns2="family.ws.maelis.sigec.com">E07 : Il existe déjà un quotient postérieur pour cette période</message>
|
||||
</ns1:MaelisFamilyException>
|
||||
</detail>
|
||||
</soap:Fault>
|
||||
</soap:Body>
|
||||
</soap:Envelope>
|
|
@ -45,6 +45,20 @@
|
|||
<code>AVL</code>
|
||||
<label>Auxiliaire de Vie loisirs</label>
|
||||
</indicatorList>
|
||||
<quotientList>
|
||||
<yearRev>2020</yearRev>
|
||||
<dateStart>2021-01-01T00:00:00+01:00</dateStart>
|
||||
<dateEnd>2021-12-31T00:00:00+01:00</dateEnd>
|
||||
<mtt>1500.33</mtt>
|
||||
<cdquo>QS</cdquo>
|
||||
</quotientList>
|
||||
<quotientList>
|
||||
<yearRev>2021</yearRev>
|
||||
<dateStart>2022-01-01T00:00:00+01:00</dateStart>
|
||||
<dateEnd>2022-12-31T00:00:00+01:00</dateEnd>
|
||||
<mtt>1500.44</mtt>
|
||||
<cdquo>MOY ECO</cdquo>
|
||||
</quotientList>
|
||||
</RL1>
|
||||
<RL2>
|
||||
<num>613879</num>
|
||||
|
|
|
@ -45,6 +45,20 @@
|
|||
<code>AVL</code>
|
||||
<label>Auxiliaire de Vie loisirs</label>
|
||||
</indicatorList>
|
||||
<quotientList>
|
||||
<yearRev>2020</yearRev>
|
||||
<dateStart>2021-01-01T00:00:00+01:00</dateStart>
|
||||
<dateEnd>2021-12-31T00:00:00+01:00</dateEnd>
|
||||
<mtt>1500.33</mtt>
|
||||
<cdquo>QS</cdquo>
|
||||
</quotientList>
|
||||
<quotientList>
|
||||
<yearRev>2021</yearRev>
|
||||
<dateStart>2022-01-01T00:00:00+01:00</dateStart>
|
||||
<dateEnd>2022-12-31T00:00:00+01:00</dateEnd>
|
||||
<mtt>1500.44</mtt>
|
||||
<cdquo>MOY ECO</cdquo>
|
||||
</quotientList>
|
||||
</RL1>
|
||||
<RL2>
|
||||
<num>613879</num>
|
||||
|
|
|
@ -45,6 +45,20 @@
|
|||
<code>AVL</code>
|
||||
<label>Auxiliaire de Vie loisirs</label>
|
||||
</indicatorList>
|
||||
<quotientList>
|
||||
<yearRev>2020</yearRev>
|
||||
<dateStart>2021-01-01T00:00:00+01:00</dateStart>
|
||||
<dateEnd>2021-12-31T00:00:00+01:00</dateEnd>
|
||||
<mtt>1500.33</mtt>
|
||||
<cdquo>QS</cdquo>
|
||||
</quotientList>
|
||||
<quotientList>
|
||||
<yearRev>2021</yearRev>
|
||||
<dateStart>2022-01-01T00:00:00+01:00</dateStart>
|
||||
<dateEnd>2022-12-31T00:00:00+01:00</dateEnd>
|
||||
<mtt>1500.44</mtt>
|
||||
<cdquo>MOY ECO</cdquo>
|
||||
</quotientList>
|
||||
</RL1>
|
||||
<RL2>
|
||||
<num>613879</num>
|
||||
|
|
|
@ -58,6 +58,10 @@ CREATE_CHILD_ERR = FakedResponse(content=get_xml_file('R_create_child_error.xml'
|
|||
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)
|
||||
UPDATE_QUOTIENT = FakedResponse(content=get_xml_file('R_create_update_quotient.xml'), status_code=200)
|
||||
UPDATE_QUOTIENT_500 = FakedResponse(
|
||||
content=get_xml_file('R_create_update_quotient_soap_error.xml'), status_code=500
|
||||
)
|
||||
UPDATE_DIETCODE = FakedResponse(content=get_xml_file('R_update_child_dietcode.xml'), status_code=200)
|
||||
UPDATE_PAI = FakedResponse(content=get_xml_file('R_update_child_pai.xml'), status_code=200)
|
||||
UPDATE_PAI_500 = FakedResponse(content=get_xml_file('R_update_child_pai_soap_error.xml'), status_code=500)
|
||||
|
@ -705,7 +709,6 @@ def test_read_family(mocked_post, mocked_get, read_family, con, app):
|
|||
'CAFInfo': None,
|
||||
'civility_text': 'Monsieur',
|
||||
'quality_text': 'PERE',
|
||||
'quotientList': [],
|
||||
'indicatorList': [
|
||||
{
|
||||
'choice': None,
|
||||
|
@ -722,6 +725,26 @@ def test_read_family(mocked_post, mocked_get, read_family, con, app):
|
|||
'note': 'SNPP',
|
||||
},
|
||||
],
|
||||
'quotientList': [
|
||||
{
|
||||
'cdquo': 'QS',
|
||||
'cdquo_text': 'QUOTIENT SCOLAIRE',
|
||||
'codeUti': None,
|
||||
'dateEnd': '2021-12-31T00:00:00+01:00',
|
||||
'dateStart': '2021-01-01T00:00:00+01:00',
|
||||
'mtt': 1500.33,
|
||||
'yearRev': 2020,
|
||||
},
|
||||
{
|
||||
'cdquo': 'MOY ECO',
|
||||
'cdquo_text': 'REVENU MOYEN ( MENSUEL OU ANNUEL)',
|
||||
'codeUti': None,
|
||||
'dateEnd': '2022-12-31T00:00:00+01:00',
|
||||
'dateStart': '2022-01-01T00:00:00+01:00',
|
||||
'mtt': 1500.44,
|
||||
'yearRev': 2021,
|
||||
},
|
||||
],
|
||||
'subscribeActivityList': [],
|
||||
}
|
||||
data = resp.json['data']['childList'][0]
|
||||
|
@ -2111,6 +2134,79 @@ def test_update_coordinate_wrong_referential_key_error(mocked_post, mocked_get,
|
|||
)
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
@mock.patch('passerelle.utils.Request.post')
|
||||
def test_update_quotient(mocked_post, mocked_get, con, app):
|
||||
mocked_get.return_value = FAMILY_SERVICE_WSDL
|
||||
mocked_post.return_value = UPDATE_QUOTIENT
|
||||
url = get_endpoint('update-quotient')
|
||||
params = {
|
||||
'yearRev': '2021',
|
||||
'dateStart': '2022-10-01',
|
||||
'dateEnd': '2023-01-31',
|
||||
'mtt': '1500.33',
|
||||
'cdquo': 'QS',
|
||||
}
|
||||
|
||||
Link.objects.create(resource=con, family_id='1312', name_id='local')
|
||||
resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params)
|
||||
assert_sent_payload(mocked_post, 'Q_create_update_quotient.xml')
|
||||
assert resp.json['err'] == 0
|
||||
assert resp.json['data'] == 'ok'
|
||||
|
||||
|
||||
def test_update_quotient_schema_error(con, app):
|
||||
url = get_endpoint('update-quotient')
|
||||
params = {
|
||||
'yearRev': '2021',
|
||||
'dateStart': '2022-10-01',
|
||||
'dateEnd': '2023-01-31',
|
||||
'mtt': '1500,33',
|
||||
'cdquo': 'QS',
|
||||
}
|
||||
|
||||
Link.objects.create(resource=con, family_id='1312', name_id='local')
|
||||
resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params, status=400)
|
||||
assert resp.json['err'] == 1
|
||||
assert resp.json['err_desc'] == "mtt: '1500,33' does not match '^[0-9]+\\\\.?[0-9]*$'"
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
@mock.patch('passerelle.utils.Request.post')
|
||||
def test_update_quotient_soap_error(mocked_post, mocked_get, con, app):
|
||||
mocked_get.return_value = FAMILY_SERVICE_WSDL
|
||||
mocked_post.return_value = UPDATE_QUOTIENT_500
|
||||
url = get_endpoint('update-quotient')
|
||||
params = {
|
||||
'yearRev': '2021',
|
||||
'dateStart': '2022-10-01',
|
||||
'dateEnd': '2023-01-31',
|
||||
'mtt': '1500.33',
|
||||
'cdquo': 'QS',
|
||||
}
|
||||
|
||||
Link.objects.create(resource=con, family_id='1312', name_id='local')
|
||||
resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params)
|
||||
assert resp.json['err'] == 'Family-createUpdateQuotient-soap:Server'
|
||||
assert 'E07 : Il existe déjà un quotient postérieur' in resp.json['err_desc']
|
||||
|
||||
|
||||
def test_update_quotient_wrong_referential_key_error(con, app):
|
||||
url = get_endpoint('update-quotient')
|
||||
params = {
|
||||
'yearRev': '2021',
|
||||
'dateStart': '2023-10-01',
|
||||
'dateEnd': '2023-01-31',
|
||||
'mtt': '1500.33',
|
||||
'cdquo': 'plop',
|
||||
}
|
||||
|
||||
Link.objects.create(resource=con, family_id='1312', name_id='local')
|
||||
resp = app.post_json(url + '?NameID=local&rl_id=613878', params=params)
|
||||
assert resp.json['err'] == 'wrong-key'
|
||||
assert resp.json['err_desc'] == "cdquo key value 'plop' do not belong to 'Quotient' required referential"
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
@mock.patch('passerelle.utils.Request.post')
|
||||
def test_create_person(mocked_post, mocked_get, con, app):
|
||||
|
|
Loading…
Reference in New Issue