toulouse-maelis: accept indicator on subscription (#74978) #127
|
@ -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',
|
||||
|
@ -78,6 +103,15 @@ SUBSCRIPTION_SCHEMA = {
|
|||
'type': 'array',
|
||||
'items': {'type': 'string'},
|
||||
},
|
||||
'indicatorList': {
|
||||
'oneOf': [
|
||||
{
|
||||
'type': 'array',
|
||||
'items': INDICATOR_SCHEMA,
|
||||
},
|
||||
{'type': 'null'},
|
||||
],
|
||||
},
|
||||
},
|
||||
'required': [
|
||||
'person_id',
|
||||
|
@ -87,6 +121,7 @@ SUBSCRIPTION_SCHEMA = {
|
|||
'start_date',
|
||||
'end_date',
|
||||
],
|
||||
'unflatten': True,
|
||||
}
|
||||
|
||||
DELETE_BASKET_LINE_SCHEMA = {
|
||||
|
|
|
@ -2782,6 +2782,28 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
family_id=None,
|
||||
):
|
||||
family_id = family_id or self.get_link(NameID).family_id
|
||||
params = {
|
||||
'numDossier': family_id,
|
||||
'numPerson': post_data['person_id'],
|
||||
'activityUnitPlace': {
|
||||
'idActivity': post_data['activity_id'],
|
||||
'idUnit': post_data['unit_id'],
|
||||
'idPlace': post_data['place_id'],
|
||||
},
|
||||
}
|
||||
subscription_info = self.call('Activity', 'getPersonUnitInfo', getPersonUnitInfoRequestBean=params)
|
||||
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)
|
||||
|
||||
recurrent_week = []
|
||||
for item in post_data.get('recurrent_week') or []:
|
||||
|
@ -2803,6 +2825,7 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
'dateStartSubscribe': post_data['start_date'],
|
||||
'dateEndSubscribe': post_data['end_date'],
|
||||
'dayWeekInfoList': recurrent_week,
|
||||
'indicatorList': indicators,
|
||||
}
|
||||
}
|
||||
response = self.call('Activity', 'addPersonUnitBasket', **payload)
|
||||
|
|
|
@ -6070,6 +6070,10 @@ def test_get_person_subscription_info_loisir_date_error(con, app):
|
|||
|
||||
|
||||
def test_add_person_basket_subscription(activity_service, con, app):
|
||||
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'),
|
||||
|
@ -6142,6 +6146,10 @@ def test_add_person_basket_subscription_with_recurrent_week(activity_service, co
|
|||
{'dayNum': 2, 'isPresent': True, 'isOpen': None, 'calendarLetter': 'C'},
|
||||
]
|
||||
|
||||
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'),
|
||||
|
@ -6166,7 +6174,84 @@ def test_add_person_basket_subscription_with_recurrent_week(activity_service, co
|
|||
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, activity_service, con, app
|
||||
):
|
||||
def request_check(request):
|
||||
assert [(x['code'], x['isActive']) for x in request.indicatorList] == [('AUT_SEUL', is_active_result)]
|
||||
|
||||
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': '246423',
|
||||
'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(activity_service, con, app):
|
||||
def request_check(request):
|
||||
assert request.indicatorList == []
|
||||
|
||||
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': '246423',
|
||||
'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
|
||||
|
||||
|
||||
def test_add_person_basket_subscription_error(activity_service, con, app):
|
||||
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_error.xml'),
|
||||
|
@ -6201,6 +6286,50 @@ def test_add_person_basket_subscription_not_linked_error(con, app):
|
|||
assert resp.json['err_desc'] == 'User not linked to family'
|
||||
|
||||
|
||||
def test_add_person_basket_subscription_with_indicators_schema_error(con, app):
|
||||
url = get_endpoint('add-person-basket-subscription')
|
||||
params = {
|
||||
'person_id': '246423',
|
||||
'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(
|
||||
activity_service, con, app
|
||||
):
|
||||
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': '246423',
|
||||
'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_get_basket(activity_service, con, app):
|
||||
activity_service.add_soap_response('getFamilyBasket', get_xml_file('R_get_family_basket.xml'))
|
||||
url = get_endpoint('get-basket')
|
||||
|
|
Loading…
Reference in New Issue