solis_afi_mss: allow indexIndividus in declare-tax endpoint (#76820)
gitea/passerelle/pipeline/head There was a failure building this commit Details

This commit is contained in:
Thomas NOËL 2023-04-20 14:32:50 +02:00
parent 6d55216e43
commit a75835584b
2 changed files with 38 additions and 1 deletions

View File

@ -66,6 +66,11 @@ TAX_SCHEMA = {
'description': 'Tax amount',
'type': 'string',
},
'indexIndividus': {
'description': "List of related family member indexes separated by ':'",
'type': 'string',
'pattern': r'^[0-9 :]+$',
},
},
}
@ -332,7 +337,15 @@ class SolisAfiMss(BaseResource, HTTPResource):
post={'request_body': {'schema': {'application/json': TAX_SCHEMA}}},
)
def declare_tax(self, request, email, post_data):
post_data['indexAgent'] = str(self.search_from_email(email)['index'])
results = self.search_from_email(email)
post_data['indexAgent'] = str(results['index'])
if post_data.get('indexIndividus'):
related_persons = []
for person in results['adults'] + results['children']:
for index in [x.strip() for x in post_data['indexIndividus'].split(':') if x.strip()]:
if str(person['indexIndividu']) == index:
related_persons.append(index)
post_data['indexIndividus'] = related_persons
response = self.request(self.base_url + 'afi/budget/declarerImpot/', json=post_data)
return {'data': response}

View File

@ -523,6 +523,30 @@ def test_declare_tax(mocked_post, mocked_get, app, connector, response1, respons
data.pop('err_desc')
assert resp.json == {'err': 0, 'data': data}
mocked_post.reset_mock()
mocked_get.side_effect = [response1]
mocked_post.side_effect = [response2]
payload['indexIndividus'] = '434729:389229 :389230: ::424242:'
resp = app.post_json(endpoint + '?email=foo@dummy.org', params=payload)
assert mocked_post.mock_calls == [
mock.call(
'https://solis-afi-mss.example.net/afi/budget/declarerImpot/',
headers={'Accept': 'application/json'},
json={
'indexAgent': '389227',
'indexImposition': '368',
'anneeImposition': '2011',
'nombrePartImposition': '3.2',
'montantImposition': '777.77',
'indexIndividus': ['434729', '389229', '389230'],
},
)
]
data = json.loads(response2.content)
data.pop('err')
data.pop('err_desc')
assert resp.json == {'err': 0, 'data': data}
@mock.patch('passerelle.utils.Request.get')
@mock.patch('passerelle.utils.Request.post')