toulouse-maelis: filter subscribable school years (#83262)
gitea/passerelle/pipeline/head This commit looks good
Details
gitea/passerelle/pipeline/head This commit looks good
Details
This commit is contained in:
parent
2a73e4dfb3
commit
81f58cad59
|
@ -2632,9 +2632,29 @@ class ToulouseMaelis(BaseResource, HTTPResource):
|
|||
display_category='Inscriptions',
|
||||
description='Lister les années scolaires',
|
||||
name='read-school-years-list',
|
||||
parameters={
|
||||
'subscribable': {
|
||||
'description': "N'afficher que les années ouvertes aux inscriptions",
|
||||
'example_value': '0',
|
||||
},
|
||||
},
|
||||
)
|
||||
def read_school_years_list(self, request):
|
||||
return {'data': self.get_referential('YearSchool')}
|
||||
def read_school_years_list(self, request, subscribable='1'):
|
||||
subscribable = utils.strtobool(subscribable)
|
||||
referential = self.get_referential('YearSchool')
|
||||
data = []
|
||||
for item in referential:
|
||||
if subscribable is True:
|
||||
start_date = item.get('dateStartSubscribeSchool')
|
||||
end_date = item.get('dateEndSubscribeSchool')
|
||||
if not (start_date and end_date):
|
||||
continue
|
||||
start_date = parse_datetime(start_date)
|
||||
end_date = parse_datetime(end_date)
|
||||
if not (start_date <= now() <= end_date):
|
||||
continue
|
||||
data.append(item)
|
||||
return {'data': data}
|
||||
|
||||
@endpoint(
|
||||
display_category='Inscriptions',
|
||||
|
|
|
@ -17,6 +17,8 @@ from math import inf
|
|||
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
json_date_format = '%Y-%m-%d'
|
||||
|
||||
|
||||
|
@ -47,3 +49,12 @@ def get_public_criterias(today, start_dob, end_dob):
|
|||
data.append((str(i), publics_txt[i]))
|
||||
break
|
||||
return data
|
||||
|
||||
|
||||
def strtobool(val):
|
||||
val = val.lower()
|
||||
if val in ('y', 'yes', 't', 'true', 'on', '1'):
|
||||
return True
|
||||
elif val in ('n', 'no', 'f', 'false', 'off', '0'):
|
||||
return False
|
||||
raise APIError('invalid truth value %r' % val)
|
||||
|
|
|
@ -5,15 +5,20 @@
|
|||
<schoolYear>2022</schoolYear>
|
||||
<dateStartYearSchool>2022-09-01T00:00:00+02:00</dateStartYearSchool>
|
||||
<dateEndYearSchool>2023-07-07T00:00:00+02:00</dateEndYearSchool>
|
||||
<dateStartSubscribeSchool>2022-04-01T00:00:00+02:00</dateStartSubscribeSchool>
|
||||
<dateEndSubscribeSchool>2023-07-08T00:00:00+02:00</dateEndSubscribeSchool>
|
||||
<dateStartSubscribeSchool>2022-09-01T00:00:00+02:00</dateStartSubscribeSchool>
|
||||
<dateEndSubscribeSchool>2023-09-01T00:00:00+02:00</dateEndSubscribeSchool>
|
||||
</yearSchoolList>
|
||||
<yearSchoolList>
|
||||
<schoolYear>2023</schoolYear>
|
||||
<dateStartYearSchool>2023-09-01T00:00:00+02:00</dateStartYearSchool>
|
||||
<dateStartYearSchool>2023-09-04T00:00:00+02:00</dateStartYearSchool>
|
||||
<dateEndYearSchool>2024-07-07T00:00:00+02:00</dateEndYearSchool>
|
||||
<dateStartSubscribeSchool>2022-12-01T00:00:00+01:00</dateStartSubscribeSchool>
|
||||
<dateEndSubscribeSchool>2023-07-08T00:00:00+02:00</dateEndSubscribeSchool>
|
||||
<dateStartSubscribeSchool>2022-09-01T00:00:00+02:00</dateStartSubscribeSchool>
|
||||
<dateEndSubscribeSchool>2024-07-01T00:00:00+02:00</dateEndSubscribeSchool>
|
||||
</yearSchoolList>
|
||||
<yearSchoolList>
|
||||
<schoolYear>2024</schoolYear>
|
||||
<dateStartYearSchool>2024-09-01T00:00:00+02:00</dateStartYearSchool>
|
||||
<dateEndYearSchool>2025-07-07T00:00:00+02:00</dateEndYearSchool>
|
||||
</yearSchoolList>
|
||||
</ns2:readYearSchoolListResponse>
|
||||
</soap:Body>
|
||||
|
|
|
@ -5069,32 +5069,52 @@ def test_get_rl1_direct_debit_order_soap_error(family_service, invoice_service,
|
|||
)
|
||||
|
||||
|
||||
def test_read_school_year_list(con, app):
|
||||
def test_read_school_year_list(con, app, freezer):
|
||||
url = get_endpoint('read-school-years-list')
|
||||
resp = app.get(url)
|
||||
freezer.move_to('2023-11-09')
|
||||
|
||||
resp = app.get(url + '?subscribable=0')
|
||||
assert resp.json['err'] == 0
|
||||
assert len(resp.json['data']) == 2
|
||||
assert len(resp.json['data']) == 3
|
||||
assert resp.json['data'] == [
|
||||
{
|
||||
'id': 2022,
|
||||
'text': '2022',
|
||||
'schoolYear': 2022,
|
||||
'dateStartYearSchool': '2022-09-01T00:00:00+02:00',
|
||||
'dateEndYearSchool': '2023-07-07T00:00:00+02:00',
|
||||
'dateStartSubscribeSchool': '2022-04-01T00:00:00+02:00',
|
||||
'dateEndSubscribeSchool': '2023-07-08T00:00:00+02:00',
|
||||
'dateStartYearSchool': '2022-09-01T00:00:00+02:00',
|
||||
'dateEndSubscribeSchool': '2023-09-01T00:00:00+02:00',
|
||||
'dateStartSubscribeSchool': '2022-09-01T00:00:00+02:00',
|
||||
},
|
||||
{
|
||||
'id': 2023,
|
||||
'text': '2023',
|
||||
'schoolYear': 2023,
|
||||
'dateStartYearSchool': '2023-09-01T00:00:00+02:00',
|
||||
'dateEndYearSchool': '2024-07-07T00:00:00+02:00',
|
||||
'dateStartSubscribeSchool': '2022-12-01T00:00:00+01:00',
|
||||
'dateEndSubscribeSchool': '2023-07-08T00:00:00+02:00',
|
||||
'dateStartYearSchool': '2023-09-04T00:00:00+02:00',
|
||||
'dateEndSubscribeSchool': '2024-07-01T00:00:00+02:00',
|
||||
'dateStartSubscribeSchool': '2022-09-01T00:00:00+02:00',
|
||||
},
|
||||
{
|
||||
'id': 2024,
|
||||
'text': '2024',
|
||||
'schoolYear': 2024,
|
||||
'dateEndYearSchool': '2025-07-07T00:00:00+02:00',
|
||||
'dateStartYearSchool': '2024-09-01T00:00:00+02:00',
|
||||
'dateEndSubscribeSchool': None,
|
||||
'dateStartSubscribeSchool': None,
|
||||
},
|
||||
]
|
||||
|
||||
# get only subscribable school years by default
|
||||
resp = app.get(url)
|
||||
assert resp.json['err'] == 0
|
||||
assert [x['text'] for x in resp.json['data']] == ['2023']
|
||||
|
||||
resp = app.get(url + '?subscribable=plop')
|
||||
assert resp.json['err'] == 1
|
||||
assert resp.json['err_desc'] == "invalid truth value 'plop'"
|
||||
|
||||
|
||||
def test_read_school_levels_list(con, app):
|
||||
url = get_endpoint('read-school-levels-list')
|
||||
|
|
Loading…
Reference in New Issue