caluire-axel: get_agenda endpoint enhancements (#54812)
This commit is contained in:
parent
294faace92
commit
b7b46cefcd
|
@ -16,6 +16,7 @@
|
|||
|
||||
import base64
|
||||
import datetime
|
||||
from operator import itemgetter
|
||||
|
||||
from django.core.cache import cache
|
||||
from django.db import models
|
||||
|
@ -398,6 +399,13 @@ class CaluireAxel(BaseResource):
|
|||
cache.set(cache_key, activities_data, 30) # 30 seconds
|
||||
return activities_data
|
||||
|
||||
def get_child_activity(self, child_id, activity_id, reference_year):
|
||||
activities_data = self.get_child_activities(child_id, reference_year)
|
||||
for activity in activities_data.get('ACTIVITE', []):
|
||||
if activity['IDENTACTIVITE'] == activity_id:
|
||||
return activity
|
||||
return None
|
||||
|
||||
@endpoint(
|
||||
display_category=_('Schooling'),
|
||||
display_order=3,
|
||||
|
@ -503,7 +511,7 @@ class CaluireAxel(BaseResource):
|
|||
},
|
||||
}
|
||||
|
||||
def get_bookings(self, child_id, activity_id, start_date, end_date):
|
||||
def get_bookings(self, child_id, activity_id, activity_label, start_date, end_date):
|
||||
data = {
|
||||
'IDENTINDIVIDU': child_id,
|
||||
'IDENTACTIVITE': activity_id,
|
||||
|
@ -549,6 +557,18 @@ class CaluireAxel(BaseResource):
|
|||
# wednesday, jump to next thursday
|
||||
pivot_date += datetime.timedelta(days=1)
|
||||
|
||||
# get activity_type
|
||||
if activity_id.startswith('CJ MER'):
|
||||
activity_type = 'mercredi'
|
||||
elif activity_id.startswith('CJ'):
|
||||
activity_type = 'vacances'
|
||||
elif activity_id == 'ACCMAT':
|
||||
activity_type = 'matin'
|
||||
elif activity_id in ['ETUDES', 'GARDERIES']:
|
||||
activity_type = 'soir'
|
||||
else:
|
||||
activity_type = 'midi'
|
||||
|
||||
bookings = []
|
||||
days = result.json_response['DATA']['PORTAIL']['GETAGENDA'].get('JOUR', [])
|
||||
for day in days:
|
||||
|
@ -578,6 +598,8 @@ class CaluireAxel(BaseResource):
|
|||
booking['details']['out_of_delay'] = False
|
||||
booking['disabled'] = True if day_date < datetime.date.today() or color == 'grey' else False
|
||||
booking['details']['activity_id'] = activity_id
|
||||
booking['details']['activity_type'] = activity_type
|
||||
booking['details']['activity_label'] = activity_label
|
||||
booking['details']['child_id'] = child_id
|
||||
bookings.append(booking)
|
||||
|
||||
|
@ -615,7 +637,13 @@ class CaluireAxel(BaseResource):
|
|||
if child_data is None:
|
||||
raise APIError('Child not found', err_code='not-found')
|
||||
|
||||
bookings = self.get_bookings(idpersonne, activity_id, start_date, end_date)
|
||||
reference_year = utils.get_reference_year_from_date(start_date)
|
||||
activity_data = self.get_child_activity(idpersonne, activity_id, reference_year)
|
||||
if activity_data is None:
|
||||
raise APIError('Activity not found', err_code='not-found')
|
||||
bookings = self.get_bookings(
|
||||
idpersonne, activity_id, activity_data['LIBELLEACTIVITE'], start_date, end_date
|
||||
)
|
||||
return {'data': bookings}
|
||||
|
||||
@endpoint(
|
||||
|
@ -654,10 +682,25 @@ class CaluireAxel(BaseResource):
|
|||
bookings = []
|
||||
for activity in activities_data.get('ACTIVITE', []):
|
||||
activity_id = activity['IDENTACTIVITE']
|
||||
activity_label = activity['LIBELLEACTIVITE']
|
||||
if activity_id.startswith('CJ') and not activity_id.startswith('CJ MER'):
|
||||
# vacances: ignore id
|
||||
continue
|
||||
bookings += self.get_bookings(idpersonne, activity_id, start_date, end_date)
|
||||
bookings += self.get_bookings(idpersonne, activity_id, activity_label, start_date, end_date)
|
||||
|
||||
# sort bookings
|
||||
activity_types = ['matin', 'midi', 'soir', 'mercredi']
|
||||
bookings = [
|
||||
(
|
||||
b['details']['JOURDATE'],
|
||||
activity_types.index(b['details']['activity_type']),
|
||||
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]
|
||||
|
||||
return {'data': bookings}
|
||||
|
||||
|
@ -700,10 +743,11 @@ class CaluireAxel(BaseResource):
|
|||
updated = 0
|
||||
for activity in activities_data.get('ACTIVITE', []):
|
||||
activity_id = activity['IDENTACTIVITE']
|
||||
activity_label = activity['LIBELLEACTIVITE']
|
||||
if activity_id.startswith('CJ'):
|
||||
# mercredi or vacances: not bookable
|
||||
continue
|
||||
agenda = self.get_bookings(child_id, activity_id, start_date, end_date)
|
||||
agenda = self.get_bookings(child_id, activity_id, activity_label, start_date, end_date)
|
||||
legacy_days = [b['id'] for b in agenda if b['prefill'] is True]
|
||||
available_days = [b['id'] for b in agenda if b['disabled'] is False]
|
||||
booking_date = start_date
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<CODE>1</CODE>
|
||||
<ACTIVITE>
|
||||
<IDENTACTIVITE>ELEM</IDENTACTIVITE>
|
||||
<LIBELLEACTIVITE>Restaurant Elémentaire </LIBELLEACTIVITE>
|
||||
<LIBELLEACTIVITE>Restaurant Elémentaire</LIBELLEACTIVITE>
|
||||
<ENTREE>01/09/2020</ENTREE>
|
||||
<SORTIE>31/07/2021</SORTIE>
|
||||
</ACTIVITE>
|
||||
|
|
|
@ -94,6 +94,50 @@ def activities():
|
|||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def activities_full():
|
||||
return {
|
||||
'ACTIVITE': [
|
||||
{
|
||||
'ENTREE': '2020-09-02',
|
||||
'SORTIE': '2021-08-31',
|
||||
'IDENTACTIVITE': 'GARDERIES',
|
||||
'LIBELLEACTIVITE': 'Garderie',
|
||||
},
|
||||
{
|
||||
'ENTREE': '2020-09-02',
|
||||
'SORTIE': '2021-08-31',
|
||||
'IDENTACTIVITE': 'ACCMAT',
|
||||
'LIBELLEACTIVITE': 'Matin',
|
||||
},
|
||||
{
|
||||
'ENTREE': '2020-09-02',
|
||||
'SORTIE': '2021-08-31',
|
||||
'IDENTACTIVITE': 'CJ MER',
|
||||
'LIBELLEACTIVITE': 'Mercredi',
|
||||
},
|
||||
{
|
||||
'ENTREE': '2020-09-02',
|
||||
'SORTIE': '2021-08-31',
|
||||
'IDENTACTIVITE': 'ETUDES',
|
||||
'LIBELLEACTIVITE': 'Etudes',
|
||||
},
|
||||
{
|
||||
'ENTREE': '2020-09-02',
|
||||
'SORTIE': '2021-08-31',
|
||||
'IDENTACTIVITE': 'CJ1',
|
||||
'LIBELLEACTIVITE': 'Des vacances', # ignored
|
||||
},
|
||||
{
|
||||
'ENTREE': '2020-09-02',
|
||||
'SORTIE': '2021-08-31',
|
||||
'IDENTACTIVITE': 'ECOLELEM',
|
||||
'LIBELLEACTIVITE': 'Cantine',
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def booking_params():
|
||||
return {
|
||||
|
@ -810,7 +854,7 @@ def test_register_activity_endpoint_wrong_code(app, resource, family_data, regis
|
|||
assert resp.json['err'] == 'register-activity-code-error-%s' % code
|
||||
|
||||
|
||||
def test_get_agenda_endpoint_axel_error(app, resource):
|
||||
def test_get_agenda_endpoint_axel_error(app, resource, family_data):
|
||||
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
||||
with mock.patch('passerelle.contrib.caluire_axel.schemas.get_famille_individus') as operation:
|
||||
operation.side_effect = AxelError('FooBar')
|
||||
|
@ -824,7 +868,7 @@ def test_get_agenda_endpoint_axel_error(app, resource):
|
|||
with open(filepath) as xml:
|
||||
content = xml.read()
|
||||
with mock_data(content, 'GetFamilleIndividus'):
|
||||
with mock.patch('passerelle.contrib.caluire_axel.schemas.get_agenda') as operation:
|
||||
with mock.patch('passerelle.contrib.caluire_axel.schemas.get_list_activites') as operation:
|
||||
operation.side_effect = AxelError('FooBar')
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=FOOBAR&start_date=2020-09-01&end_date=2021-08-31'
|
||||
|
@ -832,6 +876,22 @@ def test_get_agenda_endpoint_axel_error(app, resource):
|
|||
assert resp.json['err_desc'] == "Axel error: FooBar"
|
||||
assert resp.json['err'] == 'error'
|
||||
|
||||
filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/activities_info.xml')
|
||||
with open(filepath) as xml:
|
||||
content = xml.read()
|
||||
with mock_data(content, 'GetListActivites'):
|
||||
with mock.patch(
|
||||
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_family_data',
|
||||
return_value=family_data,
|
||||
):
|
||||
with mock.patch('passerelle.contrib.caluire_axel.schemas.get_agenda') as operation:
|
||||
operation.side_effect = AxelError('FooBar')
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=ELEM&start_date=2020-09-01&end_date=2021-08-31'
|
||||
)
|
||||
assert resp.json['err_desc'] == "Axel error: FooBar"
|
||||
assert resp.json['err'] == 'error'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('value', ['foo', '20/01/2020', '2020'])
|
||||
def test_get_agenda_endpoint_bad_date_format(app, resource, value):
|
||||
|
@ -852,7 +912,7 @@ def test_get_agenda_endpoint_bad_date_format(app, resource, value):
|
|||
assert resp.json['err'] == 'bad-request'
|
||||
|
||||
|
||||
def test_get_agenda_endpoint_no_result(app, resource):
|
||||
def test_get_agenda_endpoint_no_result(app, resource, family_data):
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=FOOBAR&start_date=2020-09-01&end_date=2021-08-31'
|
||||
)
|
||||
|
@ -870,6 +930,20 @@ def test_get_agenda_endpoint_no_result(app, resource):
|
|||
assert resp.json['err_desc'] == "Child not found"
|
||||
assert resp.json['err'] == 'not-found'
|
||||
|
||||
filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/activities_info.xml')
|
||||
with open(filepath) as xml:
|
||||
content = xml.read()
|
||||
with mock_data(content, 'GetListActivites'):
|
||||
with mock.patch(
|
||||
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_family_data',
|
||||
return_value=family_data,
|
||||
):
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=FOOBAR&start_date=2020-09-01&end_date=2021-08-31'
|
||||
)
|
||||
assert resp.json['err_desc'] == "Activity not found"
|
||||
assert resp.json['err'] == 'not-found'
|
||||
|
||||
|
||||
def test_get_agenda_endpoint_date_error(app, resource):
|
||||
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
||||
|
@ -886,7 +960,7 @@ def test_get_agenda_endpoint_date_error(app, resource):
|
|||
|
||||
|
||||
@freezegun.freeze_time('2020-09-01')
|
||||
def test_get_agenda_endpoint(app, resource, family_data):
|
||||
def test_get_agenda_endpoint(app, resource, family_data, activities):
|
||||
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
||||
content = '''<PORTAIL>
|
||||
<GETAGENDA>
|
||||
|
@ -905,13 +979,17 @@ def test_get_agenda_endpoint(app, resource, family_data):
|
|||
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_family_data',
|
||||
return_value=family_data,
|
||||
):
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=FOOBAR&start_date=2020-09-01&end_date=2021-08-31'
|
||||
)
|
||||
with mock.patch(
|
||||
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_child_activities',
|
||||
return_value=activities,
|
||||
):
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=ELEM&start_date=2020-09-01&end_date=2021-08-31'
|
||||
)
|
||||
assert resp.json['err'] == 0
|
||||
assert resp.json['data'] == [
|
||||
{
|
||||
'id': '50632:FOOBAR:2020-10-30',
|
||||
'id': '50632:ELEM:2020-10-30',
|
||||
'text': 'Friday 30 October 2020',
|
||||
'disabled': False,
|
||||
'prefill': False,
|
||||
|
@ -923,7 +1001,9 @@ def test_get_agenda_endpoint(app, resource, family_data):
|
|||
'FERME': False,
|
||||
'status_color': 'white',
|
||||
'out_of_delay': False,
|
||||
'activity_id': 'FOOBAR',
|
||||
'activity_id': 'ELEM',
|
||||
'activity_label': 'Restaurant Elémentaire',
|
||||
'activity_type': 'midi',
|
||||
'child_id': '50632',
|
||||
},
|
||||
},
|
||||
|
@ -951,7 +1031,7 @@ def test_get_agenda_endpoint(app, resource, family_data):
|
|||
],
|
||||
)
|
||||
@freezegun.freeze_time('2020-09-01')
|
||||
def test_get_agenda_endpoint_prefill(app, resource, family_data, value, expected):
|
||||
def test_get_agenda_endpoint_prefill(app, resource, family_data, activities, value, expected):
|
||||
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
||||
content = (
|
||||
'''<PORTAIL>
|
||||
|
@ -973,9 +1053,13 @@ def test_get_agenda_endpoint_prefill(app, resource, family_data, value, expected
|
|||
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_family_data',
|
||||
return_value=family_data,
|
||||
):
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=FOOBAR&start_date=2020-09-01&end_date=2021-08-31'
|
||||
)
|
||||
with mock.patch(
|
||||
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_child_activities',
|
||||
return_value=activities,
|
||||
):
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=ELEM&start_date=2020-09-01&end_date=2021-08-31'
|
||||
)
|
||||
assert resp.json['data'][0]['prefill'] == expected
|
||||
|
||||
|
||||
|
@ -1000,7 +1084,7 @@ def test_get_agenda_endpoint_prefill(app, resource, family_data, value, expected
|
|||
],
|
||||
)
|
||||
def test_get_agenda_endpoint_status(
|
||||
app, resource, family_data, value, color_past, color_future, disabled_future
|
||||
app, resource, family_data, activities, value, color_past, color_future, disabled_future
|
||||
):
|
||||
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
||||
content = (
|
||||
|
@ -1023,21 +1107,25 @@ def test_get_agenda_endpoint_status(
|
|||
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_family_data',
|
||||
return_value=family_data,
|
||||
):
|
||||
with freezegun.freeze_time('2020-10-31'):
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=FOOBAR&start_date=2020-09-01&end_date=2021-08-31'
|
||||
)
|
||||
assert resp.json['data'][0]['details']['status_color'] == color_past
|
||||
assert resp.json['data'][0]['disabled'] is True
|
||||
assert resp.json['data'][0]['details']['out_of_delay'] is True
|
||||
with mock.patch(
|
||||
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_child_activities',
|
||||
return_value=activities,
|
||||
):
|
||||
with freezegun.freeze_time('2020-10-31'):
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=ELEM&start_date=2020-09-01&end_date=2021-08-31'
|
||||
)
|
||||
assert resp.json['data'][0]['details']['status_color'] == color_past
|
||||
assert resp.json['data'][0]['disabled'] is True
|
||||
assert resp.json['data'][0]['details']['out_of_delay'] is True
|
||||
|
||||
with freezegun.freeze_time('2020-10-20'):
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=FOOBAR&start_date=2020-09-01&end_date=2021-08-31'
|
||||
)
|
||||
assert resp.json['data'][0]['details']['status_color'] == color_future
|
||||
assert resp.json['data'][0]['disabled'] == disabled_future
|
||||
assert resp.json['data'][0]['details']['out_of_delay'] is False
|
||||
with freezegun.freeze_time('2020-10-20'):
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=ELEM&start_date=2020-09-01&end_date=2021-08-31'
|
||||
)
|
||||
assert resp.json['data'][0]['details']['status_color'] == color_future
|
||||
assert resp.json['data'][0]['disabled'] == disabled_future
|
||||
assert resp.json['data'][0]['details']['out_of_delay'] is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -1081,7 +1169,7 @@ def test_get_agenda_endpoint_status(
|
|||
],
|
||||
)
|
||||
def test_get_agenda_endpoint_delay_periscolaire(
|
||||
app, resource, family_data, today, hour, booking_date, out_of_delay
|
||||
app, resource, family_data, activities_full, today, hour, booking_date, out_of_delay
|
||||
):
|
||||
booking = datetime.datetime.strptime(booking_date, json_date_format).date()
|
||||
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
||||
|
@ -1104,18 +1192,36 @@ def test_get_agenda_endpoint_delay_periscolaire(
|
|||
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_family_data',
|
||||
return_value=family_data,
|
||||
):
|
||||
with freezegun.freeze_time('%s %s' % (today, hour)):
|
||||
for activity_id in ['ACCMAT', 'GARDERIES', 'ETUDES', 'CANTINE', 'FOOBAR']:
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=%s&start_date=%s&end_date=%s'
|
||||
% (activity_id, booking_date, booking_date)
|
||||
)
|
||||
assert resp.json['data'][0]['disabled'] == out_of_delay
|
||||
assert resp.json['data'][0]['details']['out_of_delay'] == out_of_delay
|
||||
with mock.patch(
|
||||
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_child_activities',
|
||||
return_value=activities_full,
|
||||
):
|
||||
with freezegun.freeze_time('%s %s' % (today, hour)):
|
||||
for activity_id, activity_type in [
|
||||
('ACCMAT', 'matin'),
|
||||
('GARDERIES', 'soir'),
|
||||
('ETUDES', 'soir'),
|
||||
('ECOLELEM', 'midi'),
|
||||
]:
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=%s&start_date=%s&end_date=%s'
|
||||
% (activity_id, booking_date, booking_date)
|
||||
)
|
||||
assert resp.json['data'][0]['disabled'] == out_of_delay
|
||||
assert resp.json['data'][0]['details']['out_of_delay'] == out_of_delay
|
||||
assert resp.json['data'][0]['details']['activity_type'] == activity_type
|
||||
|
||||
|
||||
@pytest.mark.parametrize('activity_id', ['CJ MER', 'CJ MERfoo', 'CJ', 'CJ foobar'])
|
||||
def test_get_agenda_endpoint_delay_extrascolaire(app, resource, family_data, activity_id):
|
||||
@pytest.mark.parametrize(
|
||||
'activity_id, activity_type',
|
||||
[
|
||||
('CJ MER', 'mercredi'),
|
||||
('CJ1', 'vacances'),
|
||||
],
|
||||
)
|
||||
def test_get_agenda_endpoint_delay_extrascolaire(
|
||||
app, resource, family_data, activities_full, activity_id, activity_type
|
||||
):
|
||||
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
||||
content = '''<PORTAIL>
|
||||
<GETAGENDA>
|
||||
|
@ -1134,25 +1240,31 @@ def test_get_agenda_endpoint_delay_extrascolaire(app, resource, family_data, act
|
|||
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_family_data',
|
||||
return_value=family_data,
|
||||
):
|
||||
# always disabled
|
||||
with freezegun.freeze_time('2021-05-31'):
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=%s&start_date=2021-06-02&end_date=2021-06-02'
|
||||
% activity_id
|
||||
)
|
||||
assert resp.json['data'][0]['disabled'] is True
|
||||
assert resp.json['data'][0]['details']['out_of_delay'] is True
|
||||
with freezegun.freeze_time('2021-07-11'):
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=%s&start_date=2021-06-02&end_date=2021-06-02'
|
||||
% activity_id
|
||||
)
|
||||
assert resp.json['data'][0]['disabled'] is True
|
||||
assert resp.json['data'][0]['details']['out_of_delay'] is True
|
||||
with mock.patch(
|
||||
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_child_activities',
|
||||
return_value=activities_full,
|
||||
):
|
||||
# always disabled
|
||||
with freezegun.freeze_time('2021-05-31'):
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=%s&start_date=2021-06-02&end_date=2021-06-02'
|
||||
% activity_id
|
||||
)
|
||||
assert resp.json['data'][0]['disabled'] is True
|
||||
assert resp.json['data'][0]['details']['out_of_delay'] is True
|
||||
assert resp.json['data'][0]['details']['activity_type'] == activity_type
|
||||
with freezegun.freeze_time('2021-07-11'):
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=%s&start_date=2021-06-02&end_date=2021-06-02'
|
||||
% activity_id
|
||||
)
|
||||
assert resp.json['data'][0]['disabled'] is True
|
||||
assert resp.json['data'][0]['details']['out_of_delay'] is True
|
||||
assert resp.json['data'][0]['details']['activity_type'] == activity_type
|
||||
|
||||
|
||||
@pytest.mark.parametrize('code', [0, -1, -2, -3, -4])
|
||||
def test_get_agenda_endpoint_wrong_code(app, resource, family_data, code):
|
||||
def test_get_agenda_endpoint_wrong_code(app, resource, family_data, activities, code):
|
||||
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
||||
content = (
|
||||
'''<PORTAIL>
|
||||
|
@ -1167,9 +1279,13 @@ def test_get_agenda_endpoint_wrong_code(app, resource, family_data, code):
|
|||
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_family_data',
|
||||
return_value=family_data,
|
||||
):
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=FOOBAR&start_date=2020-09-01&end_date=2021-08-31'
|
||||
)
|
||||
with mock.patch(
|
||||
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_child_activities',
|
||||
return_value=activities,
|
||||
):
|
||||
resp = app.get(
|
||||
'/caluire-axel/test/get_agenda?NameID=yyy&idpersonne=50632&activity_id=ELEM&start_date=2020-09-01&end_date=2021-08-31'
|
||||
)
|
||||
assert resp.json['err_desc'] == "Wrong agenda status"
|
||||
assert resp.json['err'] == 'agenda-code-error-%s' % code
|
||||
|
||||
|
@ -1265,49 +1381,18 @@ def test_get_agenda_periscolaire_endpoint_date_error(app, resource):
|
|||
assert resp.json['err'] == 'bad-request'
|
||||
|
||||
|
||||
def test_get_agenda_periscolaire_endpoint(app, resource, family_data):
|
||||
def test_get_agenda_periscolaire_endpoint(app, resource, family_data, activities_full):
|
||||
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
||||
activities = [
|
||||
{
|
||||
'ENTREE': '2020-09-02',
|
||||
'SORTIE': '2021-08-31',
|
||||
'IDENTACTIVITE': 'ACCMAT',
|
||||
'LIBELLEACTIVITE': 'Matin',
|
||||
},
|
||||
{
|
||||
'ENTREE': '2020-09-02',
|
||||
'SORTIE': '2021-08-31',
|
||||
'IDENTACTIVITE': 'ECOLELEM',
|
||||
'LIBELLEACTIVITE': 'Cantine',
|
||||
},
|
||||
{
|
||||
'ENTREE': '2020-09-02',
|
||||
'SORTIE': '2021-08-31',
|
||||
'IDENTACTIVITE': 'ETUDES',
|
||||
'LIBELLEACTIVITE': 'Etudes',
|
||||
},
|
||||
{
|
||||
'ENTREE': '2020-09-02',
|
||||
'SORTIE': '2021-08-31',
|
||||
'IDENTACTIVITE': 'GARDERIES',
|
||||
'LIBELLEACTIVITE': 'Garderie',
|
||||
},
|
||||
{
|
||||
'ENTREE': '2020-09-02',
|
||||
'SORTIE': '2021-08-31',
|
||||
'IDENTACTIVITE': 'CJ MER',
|
||||
'LIBELLEACTIVITE': 'Mercredi',
|
||||
},
|
||||
{
|
||||
'ENTREE': '2020-09-02',
|
||||
'SORTIE': '2021-08-31',
|
||||
'IDENTACTIVITE': 'CJ1',
|
||||
'LIBELLEACTIVITE': 'Des vacances', # ignored
|
||||
},
|
||||
]
|
||||
content = '''<PORTAIL>
|
||||
<GETAGENDA>
|
||||
<CODE>1</CODE>
|
||||
<CODE>2</CODE>
|
||||
<JOUR>
|
||||
<JOURDATE>29/10/2020</JOURDATE>
|
||||
<MATIN>.</MATIN>
|
||||
<MIDI></MIDI>
|
||||
<APRESMIDI></APRESMIDI>
|
||||
<FERME>N</FERME>
|
||||
</JOUR>
|
||||
<JOUR>
|
||||
<JOURDATE>30/10/2020</JOURDATE>
|
||||
<MATIN>.</MATIN>
|
||||
|
@ -1324,17 +1409,22 @@ def test_get_agenda_periscolaire_endpoint(app, resource, family_data):
|
|||
):
|
||||
with mock.patch(
|
||||
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_child_activities',
|
||||
return_value={'ACTIVITE': activities},
|
||||
return_value=activities_full,
|
||||
):
|
||||
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']) == 5
|
||||
assert resp.json['data'][0]['details']['activity_id'] == 'ACCMAT'
|
||||
assert resp.json['data'][1]['details']['activity_id'] == 'ECOLELEM'
|
||||
assert resp.json['data'][2]['details']['activity_id'] == 'ETUDES'
|
||||
assert resp.json['data'][3]['details']['activity_id'] == 'GARDERIES'
|
||||
assert resp.json['data'][4]['details']['activity_id'] == 'CJ MER'
|
||||
assert len(resp.json['data']) == 10
|
||||
assert resp.json['data'][0]['id'] == '50632:ACCMAT:2020-10-29'
|
||||
assert resp.json['data'][1]['id'] == '50632:ECOLELEM:2020-10-29'
|
||||
assert resp.json['data'][2]['id'] == '50632:ETUDES:2020-10-29'
|
||||
assert resp.json['data'][3]['id'] == '50632:GARDERIES:2020-10-29'
|
||||
assert resp.json['data'][4]['id'] == '50632:CJ MER:2020-10-29'
|
||||
assert resp.json['data'][5]['id'] == '50632:ACCMAT:2020-10-30'
|
||||
assert resp.json['data'][6]['id'] == '50632:ECOLELEM:2020-10-30'
|
||||
assert resp.json['data'][7]['id'] == '50632:ETUDES:2020-10-30'
|
||||
assert resp.json['data'][8]['id'] == '50632:GARDERIES:2020-10-30'
|
||||
assert resp.json['data'][9]['id'] == '50632:CJ MER:2020-10-30'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('code', [0, -1, -2, -3, -4])
|
||||
|
|
Loading…
Reference in New Issue