caluire-axel: add new navette activities (#68634)

This commit is contained in:
Lauréline Guérin 2022-09-02 09:18:40 +02:00
parent 4d3efa7091
commit 85bce1522f
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 288 additions and 86 deletions

View File

@ -420,9 +420,9 @@ class CaluireAxel(BaseResource):
return 'mercredi'
if activity_id.startswith('CJ'):
return 'vacances'
if activity_id == 'ACCMAT':
if activity_id in ['ACCMAT', 'NAV MATIN']:
return 'matin'
if activity_id in ['ETUDES', 'GARDERIES']:
if activity_id in ['ETUDES', 'GARDERIES', 'NAV SOIR']:
return 'soir'
return 'midi'
@ -723,17 +723,21 @@ class CaluireAxel(BaseResource):
# sort bookings
activity_types = ['matin', 'midi', 'soir', 'mercredi', 'vacances']
activity_ids = ['NAV MATIN', 'ACCMAT', 'ETUDES', 'GARDERIES', 'NAV SOIR']
bookings = [
(
b['details']['JOURDATE'],
activity_types.index(b['details']['activity_type']),
activity_ids.index(b['details']['activity_id'])
if b['details']['activity_id'] in activity_ids
else 0,
b['details']['activity_label'],
b,
)
for b in bookings
]
bookings = sorted(bookings, key=itemgetter(0, 1, 2))
bookings = [b for d, a, l, b in bookings]
bookings = sorted(bookings, key=itemgetter(0, 1, 2, 3))
bookings = [b for d, a, i, l, b in bookings]
return {
'data': bookings,
@ -840,19 +844,20 @@ class CaluireAxel(BaseResource):
return updated
def _set_agenda(self, child_id, start_date, end_date, activities_data, current_agenda, booking_list):
# check exclusive activities (GARDERIES and ETUDES)
# check exclusive activities
exclusive_activity_ids = ['ACCMAT', 'NAV MATIN', 'GARDERIES', 'ETUDES', 'NAV SOIR']
# build list of requested booked days
exclusive_activities = defaultdict(set)
for booking in booking_list:
_child_id, activity_id, day = booking.split(':')
if _child_id != child_id:
continue
if activity_id not in ['GARDERIES', 'ETUDES']:
if activity_id not in exclusive_activity_ids:
continue
exclusive_activities[day].add(booking)
exclusive_activities["%s:%s" % (day, self.get_activity_type(activity_id))].add(booking)
# build list of existing booked days
legacy_exclusive_activities = defaultdict(set)
for activity_id in ['GARDERIES', 'ETUDES']:
for activity_id in exclusive_activity_ids:
legacy_agenda = current_agenda.get(activity_id) or []
for booking in legacy_agenda:
if booking['prefill'] is not True:
@ -860,12 +865,14 @@ class CaluireAxel(BaseResource):
_child_id, activity_id, day = booking['id'].split(':')
if _child_id != child_id:
continue
if activity_id not in ['GARDERIES', 'ETUDES']:
if activity_id not in exclusive_activity_ids:
continue
legacy_exclusive_activities[day].add(booking['id'])
legacy_exclusive_activities["%s:%s" % (day, self.get_activity_type(activity_id))].add(
booking['id']
)
# check booking exclusivity for changes only
for day, bookings in exclusive_activities.items():
if len(legacy_exclusive_activities.get(day) or []) > 1:
for key, bookings in exclusive_activities.items():
if len(legacy_exclusive_activities.get(key) or []) > 1:
# it was already booked in Axel ...
continue
if len(bookings) > 1:
@ -895,7 +902,7 @@ class CaluireAxel(BaseResource):
updated += bookings
# sort changes
activity_types = ['matin', 'midi', 'soir']
activity_types = ['nav-matin', 'matin', 'midi', 'soir', 'nav-soir']
updated = [
(
not u['booked'],

View File

@ -133,6 +133,18 @@ def activities_full():
'IDENTACTIVITE': 'ECOLELEM',
'LIBELLEACTIVITE': 'Cantine',
},
{
'ENTREE': '2020-09-02',
'SORTIE': '2021-08-31',
'IDENTACTIVITE': 'NAV MATIN',
'LIBELLEACTIVITE': 'Navette du matin',
},
{
'ENTREE': '2020-09-02',
'SORTIE': '2021-08-31',
'IDENTACTIVITE': 'NAV SOIR',
'LIBELLEACTIVITE': 'Navette du soir',
},
]
}
@ -1345,6 +1357,8 @@ def test_get_agenda_endpoint_delay_periscolaire(
('GARDERIES', 'soir'),
('ETUDES', 'soir'),
('ECOLELEM', 'midi'),
('NAV MATIN', 'matin'),
('NAV SOIR', 'soir'),
]:
resp = app.get(
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=%s&start_date=%s&end_date=%s'
@ -1601,23 +1615,31 @@ def test_get_agenda_periscolaire_endpoint(app, resource, family_data, activities
resp = app.get(
'/caluire-axel/test/get_agenda_periscolaire?NameID=yyy&idpersonne=50632&start_date=2020-09-01&end_date=2021-08-31'
)
assert len(resp.json['data']) == 16
assert resp.json['data'][0]['id'] == '50632:ACCMAT:2020-10-26'
assert resp.json['data'][1]['id'] == '50632:ECOLELEM:2020-10-26'
assert resp.json['data'][2]['id'] == '50632:ETUDES:2020-10-26'
assert resp.json['data'][3]['id'] == '50632:GARDERIES:2020-10-26'
assert resp.json['data'][4]['id'] == '50632:ACCMAT:2020-10-27'
assert resp.json['data'][5]['id'] == '50632:ECOLELEM:2020-10-27'
assert resp.json['data'][6]['id'] == '50632:ETUDES:2020-10-27'
assert resp.json['data'][7]['id'] == '50632:GARDERIES:2020-10-27'
assert resp.json['data'][8]['id'] == '50632:ACCMAT:2020-10-29'
assert resp.json['data'][9]['id'] == '50632:ECOLELEM:2020-10-29'
assert resp.json['data'][10]['id'] == '50632:ETUDES:2020-10-29'
assert resp.json['data'][11]['id'] == '50632:GARDERIES:2020-10-29'
assert resp.json['data'][12]['id'] == '50632:ACCMAT:2020-10-30'
assert resp.json['data'][13]['id'] == '50632:ECOLELEM:2020-10-30'
assert resp.json['data'][14]['id'] == '50632:ETUDES:2020-10-30'
assert resp.json['data'][15]['id'] == '50632:GARDERIES:2020-10-30'
assert len(resp.json['data']) == 24
assert resp.json['data'][0]['id'] == '50632:NAV MATIN:2020-10-26'
assert resp.json['data'][1]['id'] == '50632:ACCMAT:2020-10-26'
assert resp.json['data'][2]['id'] == '50632:ECOLELEM:2020-10-26'
assert resp.json['data'][3]['id'] == '50632:ETUDES:2020-10-26'
assert resp.json['data'][4]['id'] == '50632:GARDERIES:2020-10-26'
assert resp.json['data'][5]['id'] == '50632:NAV SOIR:2020-10-26'
assert resp.json['data'][6]['id'] == '50632:NAV MATIN:2020-10-27'
assert resp.json['data'][7]['id'] == '50632:ACCMAT:2020-10-27'
assert resp.json['data'][8]['id'] == '50632:ECOLELEM:2020-10-27'
assert resp.json['data'][9]['id'] == '50632:ETUDES:2020-10-27'
assert resp.json['data'][10]['id'] == '50632:GARDERIES:2020-10-27'
assert resp.json['data'][11]['id'] == '50632:NAV SOIR:2020-10-27'
assert resp.json['data'][12]['id'] == '50632:NAV MATIN:2020-10-29'
assert resp.json['data'][13]['id'] == '50632:ACCMAT:2020-10-29'
assert resp.json['data'][14]['id'] == '50632:ECOLELEM:2020-10-29'
assert resp.json['data'][15]['id'] == '50632:ETUDES:2020-10-29'
assert resp.json['data'][16]['id'] == '50632:GARDERIES:2020-10-29'
assert resp.json['data'][17]['id'] == '50632:NAV SOIR:2020-10-29'
assert resp.json['data'][18]['id'] == '50632:NAV MATIN:2020-10-30'
assert resp.json['data'][19]['id'] == '50632:ACCMAT:2020-10-30'
assert resp.json['data'][20]['id'] == '50632:ECOLELEM:2020-10-30'
assert resp.json['data'][21]['id'] == '50632:ETUDES:2020-10-30'
assert resp.json['data'][22]['id'] == '50632:GARDERIES:2020-10-30'
assert resp.json['data'][23]['id'] == '50632:NAV SOIR:2020-10-30'
@pytest.mark.parametrize('code', [0, -1, -2, -3, -4])
@ -1815,37 +1837,47 @@ def test_get_agenda_full_endpoint(app, resource, family_data, activities_full):
resp = app.get(
'/caluire-axel/test/get_agenda_full?NameID=yyy&idpersonne=50632&start_date=2020-09-01&end_date=2021-08-31'
)
assert len(resp.json['data']) == 30
assert resp.json['data'][0]['id'] == '50632:ACCMAT:2020-10-26'
assert resp.json['data'][1]['id'] == '50632:ECOLELEM:2020-10-26'
assert resp.json['data'][2]['id'] == '50632:ETUDES:2020-10-26'
assert resp.json['data'][3]['id'] == '50632:GARDERIES:2020-10-26'
assert resp.json['data'][4]['id'] == '50632:CJ MER:2020-10-26'
assert resp.json['data'][5]['id'] == '50632:CJ1:2020-10-26'
assert resp.json['data'][6]['id'] == '50632:ACCMAT:2020-10-27'
assert resp.json['data'][7]['id'] == '50632:ECOLELEM:2020-10-27'
assert resp.json['data'][8]['id'] == '50632:ETUDES:2020-10-27'
assert resp.json['data'][9]['id'] == '50632:GARDERIES:2020-10-27'
assert resp.json['data'][10]['id'] == '50632:CJ MER:2020-10-27'
assert resp.json['data'][11]['id'] == '50632:CJ1:2020-10-27'
assert resp.json['data'][12]['id'] == '50632:ACCMAT:2020-10-28'
assert resp.json['data'][13]['id'] == '50632:ECOLELEM:2020-10-28'
assert resp.json['data'][14]['id'] == '50632:ETUDES:2020-10-28'
assert resp.json['data'][15]['id'] == '50632:GARDERIES:2020-10-28'
assert resp.json['data'][16]['id'] == '50632:CJ MER:2020-10-28'
assert resp.json['data'][17]['id'] == '50632:CJ1:2020-10-28'
assert resp.json['data'][18]['id'] == '50632:ACCMAT:2020-10-29'
assert resp.json['data'][19]['id'] == '50632:ECOLELEM:2020-10-29'
assert resp.json['data'][20]['id'] == '50632:ETUDES:2020-10-29'
assert resp.json['data'][21]['id'] == '50632:GARDERIES:2020-10-29'
assert resp.json['data'][22]['id'] == '50632:CJ MER:2020-10-29'
assert resp.json['data'][23]['id'] == '50632:CJ1:2020-10-29'
assert resp.json['data'][24]['id'] == '50632:ACCMAT:2020-10-30'
assert resp.json['data'][25]['id'] == '50632:ECOLELEM:2020-10-30'
assert resp.json['data'][26]['id'] == '50632:ETUDES:2020-10-30'
assert resp.json['data'][27]['id'] == '50632:GARDERIES:2020-10-30'
assert resp.json['data'][28]['id'] == '50632:CJ MER:2020-10-30'
assert resp.json['data'][29]['id'] == '50632:CJ1:2020-10-30'
assert len(resp.json['data']) == 40
assert resp.json['data'][0]['id'] == '50632:NAV MATIN:2020-10-26'
assert resp.json['data'][1]['id'] == '50632:ACCMAT:2020-10-26'
assert resp.json['data'][2]['id'] == '50632:ECOLELEM:2020-10-26'
assert resp.json['data'][3]['id'] == '50632:ETUDES:2020-10-26'
assert resp.json['data'][4]['id'] == '50632:GARDERIES:2020-10-26'
assert resp.json['data'][5]['id'] == '50632:NAV SOIR:2020-10-26'
assert resp.json['data'][6]['id'] == '50632:CJ MER:2020-10-26'
assert resp.json['data'][7]['id'] == '50632:CJ1:2020-10-26'
assert resp.json['data'][8]['id'] == '50632:NAV MATIN:2020-10-27'
assert resp.json['data'][9]['id'] == '50632:ACCMAT:2020-10-27'
assert resp.json['data'][10]['id'] == '50632:ECOLELEM:2020-10-27'
assert resp.json['data'][11]['id'] == '50632:ETUDES:2020-10-27'
assert resp.json['data'][12]['id'] == '50632:GARDERIES:2020-10-27'
assert resp.json['data'][13]['id'] == '50632:NAV SOIR:2020-10-27'
assert resp.json['data'][14]['id'] == '50632:CJ MER:2020-10-27'
assert resp.json['data'][15]['id'] == '50632:CJ1:2020-10-27'
assert resp.json['data'][16]['id'] == '50632:NAV MATIN:2020-10-28'
assert resp.json['data'][17]['id'] == '50632:ACCMAT:2020-10-28'
assert resp.json['data'][18]['id'] == '50632:ECOLELEM:2020-10-28'
assert resp.json['data'][19]['id'] == '50632:ETUDES:2020-10-28'
assert resp.json['data'][20]['id'] == '50632:GARDERIES:2020-10-28'
assert resp.json['data'][21]['id'] == '50632:NAV SOIR:2020-10-28'
assert resp.json['data'][22]['id'] == '50632:CJ MER:2020-10-28'
assert resp.json['data'][23]['id'] == '50632:CJ1:2020-10-28'
assert resp.json['data'][24]['id'] == '50632:NAV MATIN:2020-10-29'
assert resp.json['data'][25]['id'] == '50632:ACCMAT:2020-10-29'
assert resp.json['data'][26]['id'] == '50632:ECOLELEM:2020-10-29'
assert resp.json['data'][27]['id'] == '50632:ETUDES:2020-10-29'
assert resp.json['data'][28]['id'] == '50632:GARDERIES:2020-10-29'
assert resp.json['data'][29]['id'] == '50632:NAV SOIR:2020-10-29'
assert resp.json['data'][30]['id'] == '50632:CJ MER:2020-10-29'
assert resp.json['data'][31]['id'] == '50632:CJ1:2020-10-29'
assert resp.json['data'][32]['id'] == '50632:NAV MATIN:2020-10-30'
assert resp.json['data'][33]['id'] == '50632:ACCMAT:2020-10-30'
assert resp.json['data'][34]['id'] == '50632:ECOLELEM:2020-10-30'
assert resp.json['data'][35]['id'] == '50632:ETUDES:2020-10-30'
assert resp.json['data'][36]['id'] == '50632:GARDERIES:2020-10-30'
assert resp.json['data'][37]['id'] == '50632:NAV SOIR:2020-10-30'
assert resp.json['data'][38]['id'] == '50632:CJ MER:2020-10-30'
assert resp.json['data'][39]['id'] == '50632:CJ1:2020-10-30'
@freezegun.freeze_time('2020-09-01')
@ -2092,14 +2124,14 @@ def test_set_agenda_endpoint_multi(app, resource, family_data, booking_params):
'booked, ok',
[
([], True),
(['50632:ETUDES:2020-09-07', '50632:CANTINE:2020-09-07'], True), # cantine & etudes are not exlusive
(['50632:GARDERIES:2020-09-07', '50632:GARDERIES:2020-09-07'], True), # same day sent twice
(['50632:ETUDES:2020-09-07', '50642:GARDERIES:2020-09-07'], True), # not the same child
(['50632:ETUDES:2020-09-07', '50632:GARDERIES:2020-09-07'], False),
(['50632:ACCMAT:2020-09-07', '50632:CANTINE:2020-09-07'], True), # cantine & accmat are not exlusive
(['50632:ACCMAT:2020-09-07', '50632:ACCMAT:2020-09-07'], True), # same day sent twice
(['50642:ACCMAT:2020-09-07', '50632:NAV MATIN:2020-09-07'], True), # not the same child
(['50632:ACCMAT:2020-09-07', '50632:NAV MATIN:2020-09-07'], False),
],
)
@freezegun.freeze_time('2020-08-01')
def test_set_agenda_endpoint_multi_soir(app, resource, family_data, booking_params, booked, ok):
def test_set_agenda_endpoint_multi_matin(app, resource, family_data, booking_params, booked, ok):
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
activities = [
{
@ -2111,20 +2143,20 @@ def test_set_agenda_endpoint_multi_soir(app, resource, family_data, booking_para
{
'ENTREE': '2020-09-02',
'SORTIE': '2021-08-31',
'IDENTACTIVITE': 'GARDERIES',
'LIBELLEACTIVITE': 'Garderie',
'IDENTACTIVITE': 'ACCMAT',
'LIBELLEACTIVITE': 'Matin',
},
{
'ENTREE': '2020-09-02',
'SORTIE': '2021-08-31',
'IDENTACTIVITE': 'ETUDES',
'LIBELLEACTIVITE': 'Etudes',
'IDENTACTIVITE': 'NAV MATIN',
'LIBELLEACTIVITE': 'Navette du matin',
},
]
booking_params['end_date'] = '2020-09-07'
booking_params['booking_list'] = booked
bookings = []
for activity_id in ['GARDERIES', 'ETUDES', 'CANTINE']:
for activity_id in ['ACCMAT', 'CANTINE', 'NAV MATIN']:
bookings.append(
{
'id': '50632:%s:2020-09-07' % activity_id,
@ -2162,35 +2194,34 @@ def test_set_agenda_endpoint_multi_soir(app, resource, family_data, booking_para
params=booking_params,
status=400,
)
assert (
resp.json['err_desc']
== "not possible to book 50632:ETUDES:2020-09-07 and 50632:GARDERIES:2020-09-07 the same day"
assert resp.json['err_desc'] == "not possible to book %s the same day" % ' and '.join(
booked
)
assert resp.json['err'] == 'bad-request'
@pytest.mark.parametrize('prefill', [True, False])
@freezegun.freeze_time('2020-08-01')
def test_set_agenda_endpoint_multi_soir_no_changes(app, resource, family_data, booking_params, prefill):
def test_set_agenda_endpoint_multi_matin_no_changes(app, resource, family_data, booking_params, prefill):
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
activities = [
{
'ENTREE': '2020-09-02',
'SORTIE': '2021-08-31',
'IDENTACTIVITE': 'GARDERIES',
'LIBELLEACTIVITE': 'Garderie',
'IDENTACTIVITE': 'ACCMAT',
'LIBELLEACTIVITE': 'Matin',
},
{
'ENTREE': '2020-09-02',
'SORTIE': '2021-08-31',
'IDENTACTIVITE': 'ETUDES',
'LIBELLEACTIVITE': 'Etudes',
'IDENTACTIVITE': 'NAV MATIN',
'LIBELLEACTIVITE': 'Navette du matin',
},
]
booking_params['end_date'] = '2020-09-07'
booking_params['booking_list'] = ['50632:ETUDES:2020-09-07', '50632:GARDERIES:2020-09-07']
booking_params['booking_list'] = ['50632:ACCMAT:2020-09-07', '50632:NAV MATIN:2020-09-07']
bookings = []
for activity_id in ['GARDERIES', 'ETUDES']:
for activity_id in ['ACCMAT', 'NAV MATIN']:
bookings.append(
{
'id': '50632:%s:2020-09-07' % activity_id,
@ -2229,9 +2260,173 @@ def test_set_agenda_endpoint_multi_soir_no_changes(app, resource, family_data, b
params=booking_params,
status=400,
)
assert (
resp.json['err_desc']
== "not possible to book 50632:ETUDES:2020-09-07 and 50632:GARDERIES:2020-09-07 the same day"
assert resp.json['err_desc'] == "not possible to book %s the same day" % ' and '.join(
booking_params['booking_list']
)
assert resp.json['err'] == 'bad-request'
@pytest.mark.parametrize(
'booked, ok',
[
([], True),
(['50632:ETUDES:2020-09-07', '50632:CANTINE:2020-09-07'], True), # cantine & etudes are not exlusive
(['50632:GARDERIES:2020-09-07', '50632:GARDERIES:2020-09-07'], True), # same day sent twice
(['50632:ETUDES:2020-09-07', '50642:GARDERIES:2020-09-07'], True), # not the same child
(['50632:ETUDES:2020-09-07', '50632:GARDERIES:2020-09-07'], False),
(['50632:ETUDES:2020-09-07', '50632:NAV SOIR:2020-09-07'], False),
(['50632:GARDERIES:2020-09-07', '50632:NAV SOIR:2020-09-07'], False),
(['50632:ETUDES:2020-09-07', '50632:GARDERIES:2020-09-07', '50632:NAV SOIR:2020-09-07'], False),
],
)
@freezegun.freeze_time('2020-08-01')
def test_set_agenda_endpoint_multi_soir(app, resource, family_data, booking_params, booked, ok):
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
activities = [
{
'ENTREE': '2020-09-02',
'SORTIE': '2021-08-31',
'IDENTACTIVITE': 'CANTINE',
'LIBELLEACTIVITE': 'Cantine',
},
{
'ENTREE': '2020-09-02',
'SORTIE': '2021-08-31',
'IDENTACTIVITE': 'GARDERIES',
'LIBELLEACTIVITE': 'Garderie',
},
{
'ENTREE': '2020-09-02',
'SORTIE': '2021-08-31',
'IDENTACTIVITE': 'ETUDES',
'LIBELLEACTIVITE': 'Etudes',
},
{
'ENTREE': '2020-09-02',
'SORTIE': '2021-08-31',
'IDENTACTIVITE': 'NAV SOIR',
'LIBELLEACTIVITE': 'Navette du soir',
},
]
booking_params['end_date'] = '2020-09-07'
booking_params['booking_list'] = booked
bookings = []
for activity_id in ['GARDERIES', 'ETUDES', 'CANTINE', 'NAV SOIR']:
bookings.append(
{
'id': '50632:%s:2020-09-07' % activity_id,
'disabled': False,
'prefill': False,
}
)
with mock.patch(
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_family_data',
return_value=family_data,
):
with mock.patch(
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_child_activities',
return_value={'ACTIVITE': activities},
):
with mock.patch(
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_bookings',
return_value=bookings,
):
with mock.patch('passerelle.contrib.caluire_axel.schemas.set_agenda') as operation:
operation.return_value = OperationResult(
json_response={'DATA': {'PORTAIL': {'SETAGENDA': {'CODE': 0}}}},
xml_request='',
xml_response='',
)
if ok:
resp = app.post_json(
'/caluire-axel/test/set_agenda?NameID=yyy',
params=booking_params,
)
assert resp.json['err'] == 0
else:
resp = app.post_json(
'/caluire-axel/test/set_agenda?NameID=yyy',
params=booking_params,
status=400,
)
assert resp.json['err_desc'] == "not possible to book %s the same day" % ' and '.join(
booked
)
assert resp.json['err'] == 'bad-request'
@pytest.mark.parametrize('prefill', [True, False])
@freezegun.freeze_time('2020-08-01')
def test_set_agenda_endpoint_multi_soir_no_changes(app, resource, family_data, booking_params, prefill):
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
activities = [
{
'ENTREE': '2020-09-02',
'SORTIE': '2021-08-31',
'IDENTACTIVITE': 'GARDERIES',
'LIBELLEACTIVITE': 'Garderie',
},
{
'ENTREE': '2020-09-02',
'SORTIE': '2021-08-31',
'IDENTACTIVITE': 'ETUDES',
'LIBELLEACTIVITE': 'Etudes',
},
{
'ENTREE': '2020-09-02',
'SORTIE': '2021-08-31',
'IDENTACTIVITE': 'NAV SOIR',
'LIBELLEACTIVITE': 'Navette du soir',
},
]
booking_params['end_date'] = '2020-09-07'
booking_params['booking_list'] = [
'50632:ETUDES:2020-09-07',
'50632:GARDERIES:2020-09-07',
'50632:NAV SOIR:2020-09-07',
]
bookings = []
for activity_id in ['GARDERIES', 'ETUDES', 'NAV SOIR']:
bookings.append(
{
'id': '50632:%s:2020-09-07' % activity_id,
'disabled': False,
'prefill': prefill,
}
)
with mock.patch(
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_family_data',
return_value=family_data,
):
with mock.patch(
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_child_activities',
return_value={'ACTIVITE': activities},
):
with mock.patch(
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_bookings',
return_value=bookings,
):
with mock.patch('passerelle.contrib.caluire_axel.schemas.set_agenda') as operation:
operation.return_value = OperationResult(
json_response={'DATA': {'PORTAIL': {'SETAGENDA': {'CODE': 0}}}},
xml_request='',
xml_response='',
)
if prefill:
# was already booked, no changes => no error
resp = app.post_json(
'/caluire-axel/test/set_agenda?NameID=yyy',
params=booking_params,
)
assert resp.json['err'] == 0
else:
resp = app.post_json(
'/caluire-axel/test/set_agenda?NameID=yyy',
params=booking_params,
status=400,
)
assert resp.json['err_desc'] == "not possible to book %s the same day" % ' and '.join(
booking_params['booking_list']
)
assert resp.json['err'] == 'bad-request'
@ -2251,7 +2446,7 @@ def test_set_agenda_endpoint_prefill_periscolaire(
):
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
booking_params['end_date'] = '2020-09-01'
for activity_id in ['ACCMAT', 'GARDERIES', 'ETUDES', 'CANTINE', 'FOOBAR']:
for activity_id in ['ACCMAT', 'GARDERIES', 'ETUDES', 'CANTINE', 'FOOBAR', 'NAV MATIN', 'NAV SOIR']:
activity = {
'ENTREE': '2020-09-02',
'SORTIE': '2021-08-31',
@ -3142,7 +3337,7 @@ def test_set_activity_agenda_typical_week_endpoint_prefill_periscolaire(
app, resource, family_data, week_booking_params, prefill
):
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
for activity_id in ['ACCMAT', 'GARDERIES', 'ETUDES', 'CANTINE', 'FOOBAR']:
for activity_id in ['ACCMAT', 'GARDERIES', 'ETUDES', 'CANTINE', 'FOOBAR', 'NAV MATIN', 'NAV SOIR']:
activity = {
'ENTREE': '2020-09-02',
'SORTIE': '2021-08-31',