0002-maelis-allow-school-year-computation-from-a-given-da.patch
passerelle/apps/maelis/models.py | ||
---|---|---|
132 | 132 |
try: |
133 | 133 |
return self.link_set.get(name_id=name_id) |
134 | 134 |
except Link.DoesNotExist: |
135 | 135 |
raise APIError('User not linked to family', err_code='not-found') |
136 | 136 | |
137 | 137 |
def get_family_data(self, family_id, school_year=None): |
138 | 138 |
if not school_year: |
139 | 139 |
# fallback to current year if not provided |
140 |
school_year = utils.get_default_school_year()
|
|
140 |
school_year = utils.get_school_year() |
|
141 | 141 |
family_data = serialize_object(self.call('FamilyService?wsdl', |
142 | 142 |
'readFamily', |
143 | 143 |
dossierNumber=family_id, |
144 | 144 |
schoolYear=school_year)) |
145 | 145 |
for child in family_data['childInfoList']: |
146 | 146 |
utils.normalize_person(child) |
147 | 147 |
return family_data |
148 | 148 | |
... | ... | |
165 | 165 |
'schema': { |
166 | 166 |
'application/json': LINK_SCHEMA |
167 | 167 |
} |
168 | 168 |
} |
169 | 169 |
}) |
170 | 170 |
def link(self, request, NameID, post_data): |
171 | 171 |
if 'school_year' not in post_data: |
172 | 172 |
# fallback to default year if not provided |
173 |
post_data['school_year'] = utils.get_default_school_year()
|
|
173 |
post_data['school_year'] = utils.get_school_year() |
|
174 | 174 |
r = self.call('FamilyService?wsdl', 'readFamilyByPassword', |
175 | 175 |
dossierNumber=post_data['family_id'], |
176 | 176 |
password=post_data['password'], |
177 | 177 |
schoolYear=post_data['school_year'] |
178 | 178 |
) |
179 | 179 |
if not r.number: |
180 | 180 |
raise APIError('Family not found', err_code='not-found') |
181 | 181 |
Link.objects.update_or_create(resource=self, name_id=NameID, |
... | ... | |
380 | 380 |
}) |
381 | 381 |
def activity_list(self, request, NameID, personID, school_year=None, start_datetime=None, |
382 | 382 |
end_datetime=None): |
383 | 383 |
link = self.get_link(NameID) |
384 | 384 |
family_data = self.get_family_data(link.family_id) |
385 | 385 |
if personID not in [c['id'] for c in family_data['childInfoList']]: |
386 | 386 |
raise APIError('Child not found', err_code='not-found') |
387 | 387 |
if not school_year: |
388 |
school_year = utils.get_default_school_year()
|
|
388 |
school_year = utils.get_school_year() |
|
389 | 389 |
if not start_datetime: |
390 | 390 |
start_datetime = timezone.now() |
391 | 391 |
if not end_datetime: |
392 | 392 |
end_datetime = start_datetime + timezone.timedelta(days=62) |
393 | 393 |
r = self.call('ActivityService?wsdl', 'readActivityList', |
394 | 394 |
schoolyear=school_year, numPerson=personID, |
395 | 395 |
dateStartCalend=start_datetime, |
396 | 396 |
dateEndCalend=end_datetime) |
passerelle/apps/maelis/utils.py | ||
---|---|---|
54 | 54 | |
55 | 55 |
def normalize_person(person): |
56 | 56 |
person['id'] = person['num'] |
57 | 57 |
person['text'] = '{} {}'.format( |
58 | 58 |
person['firstname'], person['lastname']).strip() |
59 | 59 |
return person |
60 | 60 | |
61 | 61 | |
62 |
def get_default_school_year(): |
|
63 |
now = timezone.now() |
|
64 |
if now.strftime('%m-%d') >= '07-31': |
|
65 |
return now.year |
|
62 |
def get_school_year(date=None): |
|
63 |
if not date: |
|
64 |
date = timezone.now().date() |
|
65 |
if date.strftime('%m-%d') >= '07-31': |
|
66 |
return date.year |
|
66 | 67 |
else: |
67 |
return now.year - 1 |
|
68 |
return date.year - 1 |
tests/test_maelis.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 | 2 | |
3 | 3 |
import mock |
4 | 4 |
import os |
5 | 5 |
import pytest |
6 | 6 | |
7 |
from django.utils.dateparse import parse_date |
|
8 | ||
7 | 9 |
from passerelle.apps.maelis.models import Maelis, Link |
10 |
from passerelle.apps.maelis.utils import get_school_year |
|
8 | 11 | |
9 | 12 |
from passerelle.utils.jsonresponse import APIError |
10 | 13 | |
11 | 14 |
import utils |
12 | 15 | |
13 | 16 |
pytestmark = pytest.mark.django_db |
14 | 17 | |
15 | 18 | |
... | ... | |
193 | 196 |
status_code=200, |
194 | 197 |
headers={'Content-Type': 'text/xml'} |
195 | 198 |
) |
196 | 199 |
Link.objects.create(resource=connector, family_id='3264', name_id='local') |
197 | 200 |
resp = app.get('/maelis/test/regie/1/invoice/3264-53186?NameID=local') |
198 | 201 |
assert resp.json['data'] |
199 | 202 |
assert resp.json['data']['label'] == 'FACTURATION SEPTEMBRE 2014' |
200 | 203 |
assert resp.json['data']['display_id'] == '53186' |
204 | ||
205 | ||
206 |
@pytest.mark.parametrize('date, schoolyear', [ |
|
207 |
('2020-07-30', 2019), |
|
208 |
('2020-07-31', 2020), |
|
209 |
]) |
|
210 |
def test_get_school_year(date, schoolyear): |
|
211 |
date = parse_date(date) |
|
212 |
assert schoolyear == get_school_year(date) |
|
201 |
- |