toulouse-maelis: cache invoices on link call (#74790)
gitea/passerelle/pipeline/head This commit looks good Details

This commit is contained in:
Nicolas Roche 2023-03-21 19:15:17 +01:00
parent e4089b33a0
commit 3d99dd40d5
3 changed files with 41 additions and 0 deletions

View File

@ -977,6 +977,11 @@ class ToulouseMaelis(BaseResource, HTTPResource):
and response['RL1']['birth']['dateBirth'].strftime('%Y-%m-%d') == post_data['dateBirth']
):
raise APIError("RL1 does not match '%s' family" % family_id)
# put invoices into cache
for regie in self.get_referential('Regie'):
self.get_invoices(family_id, regie['id'])
Link.objects.update_or_create(resource=self, name_id=NameID, defaults={'family_id': family_id})
return {'data': 'ok'}

View File

@ -0,0 +1,5 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:readInvoicesResponse xmlns:ns2="ws.maelis.sigec.com"/>
</soap:Body>
</soap:Envelope>

View File

@ -528,6 +528,9 @@ def test_link(family_service, con, app):
url = get_endpoint('link')
assert Link.objects.count() == 0
# skip caching invoice
con.referential.filter(referential_name='Regie').delete()
params = {
'family_id': '1312',
'firstname': 'Jhon',
@ -546,6 +549,34 @@ def test_link(family_service, con, app):
assert resp.json['err_desc'] == "RL1 does not match '1312' family"
@mock.patch('passerelle.utils.Request.get')
@mock.patch('passerelle.utils.Request.post')
def test_link_caching_invoices(mocked_post, mocked_get, con, app):
mocked_get.side_effect = [FAMILY_SERVICE_WSDL, INVOICE_SERVICE_WSDL]
mocked_post.side_effect = [
FakedResponse(content=get_xml_file('R_read_family.xml'), status_code=200),
FakedResponse(content=get_xml_file('R_read_invoices.xml'), status_code=200),
] + [
FakedResponse(content=get_xml_file('R_read_invoices_empty.xml'), status_code=200),
] * 8
url = get_endpoint('link')
assert con.invoice_set.count() == 0
assert Link.objects.count() == 0
params = {
'family_id': '1312',
'firstname': 'Jhon',
'lastname': 'Doe',
'dateBirth': '1938-07-26',
}
resp = app.post_json(url + '?NameID=local', params=params)
assert len(mocked_post.mock_calls) == 10
assert Link.objects.count() == 1
assert resp.json['err'] == 0
assert resp.json['data'] == 'ok'
assert con.invoice_set.count() == 2
def test_link_additional_properties_error(con, app):
url = get_endpoint('link')
params = {