Compare commits
2 Commits
main
...
wip/74978-
Author | SHA1 | Date |
---|---|---|
Nicolas Roche | fcc7d06aad | |
Nicolas Roche | f0c59ab0f1 |
|
@ -13,6 +13,31 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from . import schemas
|
||||
|
||||
INDICATOR_SCHEMA = {
|
||||
'type': 'object',
|
||||
'required': ['code', 'isActive'],
|
||||
'properties': {
|
||||
'code': {
|
||||
'description': "Code de l'indicateur (depuis référentiel)",
|
||||
'type': 'string',
|
||||
'pattern': '.+',
|
||||
},
|
||||
'note': {
|
||||
'description': "Commentaire pour les indicateurs de type NOTE",
|
||||
'oneOf': [{'type': 'string'}, {'type': 'null'}],
|
||||
},
|
||||
'isActive': {
|
||||
'description': "True pour ajouter/modifier l'indicateur ou False pour le retirer",
|
||||
'oneOf': schemas.BOOLEAN_TYPES
|
||||
+ [
|
||||
{'type': 'string', 'pattern': '^$'},
|
||||
{'type': 'null'},
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
BOOKING_SCHEMA = {
|
||||
'type': 'object',
|
||||
|
@ -199,6 +224,15 @@ SUBSCRIPTION_SCHEMA = {
|
|||
{'type': 'null'},
|
||||
],
|
||||
},
|
||||
'indicatorList': {
|
||||
'oneOf': [
|
||||
{
|
||||
'type': 'array',
|
||||
'items': INDICATOR_SCHEMA,
|
||||
},
|
||||
{'type': 'null'},
|
||||
],
|
||||
},
|
||||
},
|
||||
'required': [
|
||||
'person_id',
|
||||
|
|
|
@ -3363,7 +3363,21 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
'isPresent': True,
|
||||
}
|
||||
)
|
||||
return recurrent_week
|
||||
|
||||
expected_codes = [x['code'] for x in subscription_info.get('indicatorList', [])]
|
||||
indicators = []
|
||||
for i, item in enumerate(post_data.get('indicatorList') or []):
|
||||
item['isActive'] = self.encode_bool(item['isActive'])
|
||||
if item['isActive'] is None: # no value, skip indicator
|
||||
continue
|
||||
if item['code'] not in expected_codes:
|
||||
raise APIError(
|
||||
"indicatorList/%i/code key value '%s' do not belong to activity indicators"
|
||||
% (i, item['code'])
|
||||
)
|
||||
indicators.append(item)
|
||||
|
||||
return recurrent_week, indicators
|
||||
|
||||
@endpoint(
|
||||
display_category='Inscriptions',
|
||||
|
@ -3386,7 +3400,7 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
):
|
||||
family_id = family_id or self.get_link(NameID).family_id
|
||||
self.get_rl_or_child_raw(family_id, post_data['person_id'])
|
||||
recurrent_week = self.process_subscription_payload(family_id, post_data)
|
||||
recurrent_week, indicators = self.process_subscription_payload(family_id, post_data)
|
||||
|
||||
form_number = post_data.get('form_number')
|
||||
if form_number and self.subscription_set.filter(wcs_form_number=form_number):
|
||||
|
@ -3403,6 +3417,7 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
'dateEndSubscribe': post_data['end_date'],
|
||||
'dayWeekInfoList': recurrent_week,
|
||||
'conveyanceSubscribe': post_data.get('conveyanceSubscribe'),
|
||||
'indicatorList': indicators,
|
||||
}
|
||||
}
|
||||
response = self.call('Activity', 'addPersonUnitBasket', **payload)
|
||||
|
@ -3459,7 +3474,7 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
):
|
||||
family_id = family_id or self.get_link(NameID).family_id
|
||||
self.get_rl_or_child_raw(family_id, post_data['person_id'])
|
||||
recurrent_week = self.process_subscription_payload(family_id, post_data)
|
||||
recurrent_week, indicators = self.process_subscription_payload(family_id, post_data)
|
||||
payload = {
|
||||
'AddPersonSubscribeRequestBean': {
|
||||
'numFamily': family_id,
|
||||
|
@ -3471,6 +3486,7 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
'dateEndSubscribe': post_data['end_date'],
|
||||
'dayWeekInfoList': recurrent_week,
|
||||
'conveyanceSubscribe': post_data.get('conveyanceSubscribe'),
|
||||
'indicatorList': indicators,
|
||||
}
|
||||
}
|
||||
response = self.call('Activity', 'addPersonUnitSubscribe', **payload)
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
</controlResult>
|
||||
<personInfo>
|
||||
<idMaelis>S10055586371</idMaelis>
|
||||
<num>261768</num>
|
||||
<num>613880</num>
|
||||
<lastname>NICO</lastname>
|
||||
<firstname>BART</firstname>
|
||||
<dateBirth>2014-04-01T00:00:00+02:00</dateBirth>
|
||||
|
|
|
@ -8060,6 +8060,84 @@ def test_add_person_basket_subscription_with_recurrent_week_empty(family_service
|
|||
'end_date': '2023-08-31',
|
||||
'recurrent_week': '',
|
||||
}
|
||||
|
||||
resp = app.post_json(url + '?family_id=311323', params=params)
|
||||
assert resp.json['err'] == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'is_active_value, is_active_result',
|
||||
[
|
||||
(True, True),
|
||||
(False, False),
|
||||
(1, True),
|
||||
(0, False),
|
||||
('oui', True),
|
||||
('NON', False),
|
||||
],
|
||||
)
|
||||
def test_add_person_basket_subscription_with_indicators(
|
||||
is_active_value, is_active_result, family_service, activity_service, con, app
|
||||
):
|
||||
def request_check(request):
|
||||
assert [(x['code'], x['isActive']) for x in request.indicatorList] == [('AUT_SEUL', is_active_result)]
|
||||
|
||||
family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
|
||||
activity_service.add_soap_response(
|
||||
'getPersonUnitInfo',
|
||||
get_xml_file('R_get_person_unit_info_with_indicator_list.xml'),
|
||||
)
|
||||
activity_service.add_soap_response(
|
||||
'addPersonUnitBasket',
|
||||
get_xml_file('R_add_person_unit_basket.xml'),
|
||||
request_check=request_check,
|
||||
)
|
||||
url = get_endpoint('add-person-basket-subscription')
|
||||
|
||||
params = {
|
||||
'person_id': '613880',
|
||||
'activity_id': 'A10049354913',
|
||||
'unit_id': 'A10049354915',
|
||||
'place_id': 'M10053212196',
|
||||
'start_date': '2022-09-01',
|
||||
'end_date': '2023-08-31',
|
||||
'indicatorList/0/code': 'AUT_SEUL',
|
||||
'indicatorList/0/isActive': is_active_value,
|
||||
}
|
||||
|
||||
resp = app.post_json(url + '?family_id=311323', params=params)
|
||||
assert resp.json['err'] == 0
|
||||
|
||||
|
||||
def test_add_person_basket_subscription_with_indicators_skipping_undef_isActive_value(
|
||||
family_service, activity_service, con, app
|
||||
):
|
||||
def request_check(request):
|
||||
assert request.indicatorList == []
|
||||
|
||||
family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
|
||||
activity_service.add_soap_response(
|
||||
'getPersonUnitInfo',
|
||||
get_xml_file('R_get_person_unit_info_with_indicator_list.xml'),
|
||||
)
|
||||
activity_service.add_soap_response(
|
||||
'addPersonUnitBasket',
|
||||
get_xml_file('R_add_person_unit_basket.xml'),
|
||||
request_check=request_check,
|
||||
)
|
||||
url = get_endpoint('add-person-basket-subscription')
|
||||
|
||||
params = {
|
||||
'person_id': '613880',
|
||||
'activity_id': 'A10049354913',
|
||||
'unit_id': 'A10049354915',
|
||||
'place_id': 'M10053212196',
|
||||
'start_date': '2022-09-01',
|
||||
'end_date': '2023-08-31',
|
||||
'indicatorList/0/code': 'AUT_SEUL',
|
||||
'indicatorList/0/isActive': '',
|
||||
}
|
||||
|
||||
resp = app.post_json(url + '?family_id=311323', params=params)
|
||||
assert resp.json['err'] == 0
|
||||
|
||||
|
@ -8121,7 +8199,7 @@ def test_add_person_basket_subscription_with_recurrent_week_forbidden_error(
|
|||
assert resp.json['err_desc'] == "recurrent item '1-B' is not available no on this activity"
|
||||
|
||||
|
||||
def test_basket_subscription_providing_wcs_demand(family_service, activity_service, con, app):
|
||||
def test_add_basket_subscription_providing_wcs_demand(family_service, activity_service, con, app):
|
||||
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'))
|
||||
|
@ -8343,6 +8421,51 @@ def test_add_person_basket_subscription_with_none_conveyance(family_service, act
|
|||
assert resp.json['err'] == 0
|
||||
|
||||
|
||||
def test_add_person_basket_subscription_with_indicators_schema_error(con, app):
|
||||
url = get_endpoint('add-person-basket-subscription')
|
||||
params = {
|
||||
'person_id': '613880',
|
||||
'activity_id': 'A10049354913',
|
||||
'unit_id': 'A10049354915',
|
||||
'place_id': 'M10053212196',
|
||||
'start_date': '2022-09-01',
|
||||
'end_date': '2023-08-31',
|
||||
'indicatorList/0/code': 'AUTH_SEUL',
|
||||
'indicatorList/0/isActive': 'plop',
|
||||
}
|
||||
resp = app.post_json(url + '?family_id=311323', params=params, status=400)
|
||||
assert resp.json['err'] == 1
|
||||
assert resp.json['err_desc'] == "'plop' is not of type 'boolean'"
|
||||
|
||||
|
||||
def test_add_person_basket_subscription_with_indicators_wrong_referential_key_error(
|
||||
family_service, activity_service, con, app
|
||||
):
|
||||
family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
|
||||
activity_service.add_soap_response(
|
||||
'getPersonUnitInfo',
|
||||
get_xml_file('R_get_person_unit_info_with_indicator_list.xml'),
|
||||
)
|
||||
url = get_endpoint('add-person-basket-subscription')
|
||||
|
||||
params = {
|
||||
'person_id': '613880',
|
||||
'activity_id': 'A10049354913',
|
||||
'unit_id': 'A10049354915',
|
||||
'place_id': 'M10053212196',
|
||||
'start_date': '2022-09-01',
|
||||
'end_date': '2023-08-31',
|
||||
'indicatorList/0/code': 'plop',
|
||||
'indicatorList/0/isActive': 'False',
|
||||
}
|
||||
|
||||
resp = app.post_json(url + '?family_id=311323', params=params)
|
||||
assert resp.json['err'] == 1
|
||||
assert (
|
||||
resp.json['err_desc'] == "indicatorList/0/code key value 'plop' do not belong to activity indicators"
|
||||
)
|
||||
|
||||
|
||||
def test_add_person_subscription(family_service, activity_service, con, app):
|
||||
family_service.add_soap_response('readFamily', get_xml_file('R_read_family.xml'))
|
||||
activity_service.add_soap_response(
|
||||
|
|
Loading…
Reference in New Issue