toulouse-maelis: don't validate a basket unrelated to new subscriptions (#86374)
gitea/passerelle/pipeline/head This commit looks good
Details
gitea/passerelle/pipeline/head This commit looks good
Details
This commit is contained in:
parent
f841e98049
commit
eac67cb852
|
@ -4019,6 +4019,11 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
basket_id = post_data['basket_id']
|
||||
self.get_basket_raw(family_id, basket_id)
|
||||
|
||||
# prevent maelis creating an invoice if the is no related new subscriptions
|
||||
subscriptions = self.subscription_set.filter(maelis_data__basket__id=basket_id)
|
||||
if not any(x.status() == 'pending_basket' for x in subscriptions):
|
||||
raise APIError("Basket '%s' has no related pending subscription" % basket_id)
|
||||
|
||||
response = self.call(
|
||||
'Activity',
|
||||
'validateBasket',
|
||||
|
|
|
@ -10376,6 +10376,53 @@ def test_validate_basket_having_a_previously_removed_line(
|
|||
assert invoice.subscription_set.get() == con.subscription_set.get(wcs_form_number='13-13')
|
||||
|
||||
|
||||
def test_validate_basket_error_having_all_previously_removed_line(
|
||||
family_service, activity_service, con, app, freezer
|
||||
):
|
||||
family_service.add_soap_response('readFamily', get_xml_file('R_read_family_for_subscription.xml'))
|
||||
activity_service.add_soap_response('getPersonUnitInfo', get_xml_file('R_get_person_unit_info.xml'))
|
||||
activity_service.add_soap_response('addPersonUnitBasket', get_xml_file('R_add_person_unit_basket.xml'))
|
||||
activity_service.add_soap_response('getFamilyBasket', get_xml_file('R_get_family_basket_empty.xml'))
|
||||
activity_service.add_soap_response('getFamilyBasket', get_xml_file('R_get_family_basket.xml'))
|
||||
activity_service.add_soap_response('validateBasket', get_xml_file('R_validate_basket.xml'))
|
||||
url = get_endpoint('validate-basket')
|
||||
params = {'basket_id': 'S10055641698'}
|
||||
Link.objects.create(resource=con, family_id='1312', name_id='local')
|
||||
|
||||
# subscribe
|
||||
freezer.move_to('2023-03-03 18:20:00')
|
||||
resp = app.post_json(
|
||||
get_endpoint('add-person-basket-subscription') + '?NameID=local',
|
||||
params={
|
||||
'person_id': '266145',
|
||||
'activity_id': 'A10053179798',
|
||||
'unit_id': 'A10053179809',
|
||||
'place_id': 'A10053179757',
|
||||
'start_date': '2023-02-01',
|
||||
'end_date': '2023-06-30',
|
||||
'form_api_url': 'https://wcs.example.com/api/forms/exemple-inscription-loisirs-1/12/',
|
||||
'form_number': '13-12',
|
||||
},
|
||||
)
|
||||
assert resp.json['err'] == 0
|
||||
assert con.subscription_set.count() == 1
|
||||
|
||||
# maelis send an empty basket
|
||||
freezer.move_to('2023-03-03 18:25:00')
|
||||
resp = app.get(get_endpoint('get-baskets') + '?family_id=1312')
|
||||
assert resp.json['err'] == 0
|
||||
subscription = con.subscription_set.get(wcs_form_number='13-12')
|
||||
assert subscription.basket_removal_date.isoformat() == '2023-03-03T18:25:00+00:00'
|
||||
assert subscription.status() == 'removed'
|
||||
assert subscription.trigger_status() == 'triggering'
|
||||
|
||||
# refuse to validate the basket so as to prevent maelis building an invoice
|
||||
freezer.move_to('2023-03-03 18:30:00')
|
||||
resp = app.post_json(url + '?NameID=local', params=params)
|
||||
assert resp.json['err'] == 1
|
||||
assert resp.json['err_desc'] == "Basket 'S10055641698' has no related pending subscription"
|
||||
|
||||
|
||||
def test_validate_basket_not_linked_error(con, app):
|
||||
url = get_endpoint('validate-basket')
|
||||
params = {'basket_id': 'S10055641698'}
|
||||
|
|
Loading…
Reference in New Issue