0001-maelis-add-Activity-calendar-endpoints-47172.patch
passerelle/apps/maelis/models.py | ||
---|---|---|
90 | 90 |
}, |
91 | 91 |
"mail": { |
92 | 92 |
"description": "mail", |
93 | 93 |
"type": "string", |
94 | 94 |
} |
95 | 95 |
} |
96 | 96 |
} |
97 | 97 | |
98 | ||
99 | 98 |
class Maelis(BaseResource): |
100 | 99 |
base_url = models.URLField(_('Base API URL'), |
101 | 100 |
default='http://www3.sigec.fr/entrouvertws/services/') |
102 | 101 |
login = models.CharField(_('API Login'), max_length=256) |
103 | 102 |
password = models.CharField(_('API Password'), max_length=256) |
104 | 103 | |
105 | 104 |
category = _('Business Process Connectors') |
106 | 105 | |
... | ... | |
425 | 424 |
r = self.call('ActivityService?wsdl', 'readChildMonthPlanning', |
426 | 425 |
year=timezone.now().year, |
427 | 426 |
numMonth=month, |
428 | 427 |
idActivity=activityID, |
429 | 428 |
numPerson=personID) |
430 | 429 |
planning = serialize_object(r['calendList']) |
431 | 430 |
return {'data': [utils.normalize_schedule(s) for s in planning]} |
432 | 431 | |
432 |
@endpoint( |
|
433 |
display_category=_('Activity'), |
|
434 |
perm='can_access', |
|
435 |
display_order=3, |
|
436 |
description=_('Update week calendar'), |
|
437 |
name='update-week-calendar', |
|
438 |
parameters={ |
|
439 |
'NameID': {'description': _('Publik ID')}, |
|
440 |
'personID': {'description': _('Person ID')}, |
|
441 |
'activityID': {'description': _('Activity ID')}, |
|
442 |
'dateStart': {'description': _('Booking start date ?')}, |
|
443 |
'dateEnd': {'description': _('Booking end date ?')}, |
|
444 |
'weeklyPlanningAM': {'description': _('?')}, |
|
445 |
'weeklyPlanningPM': {'description': _('?')}, |
|
446 |
}) |
|
447 |
def update_week_calendar(self, request, NameID, personID, activityID, |
|
448 |
dateStart, dateEnd, weeklyPlanningAM, weeklyPlanningPM): |
|
449 |
link = self.get_link(NameID) |
|
450 |
family_data = self.get_family_data(link.family_id) |
|
451 |
if personID not in [c['id'] for c in family_data['childInfoList']]: |
|
452 |
raise APIError('Child not found', err_code='not-found') |
|
453 | ||
454 |
r = self.call('ActivityService?wsdl', 'updateWeekCalendar', |
|
455 |
numPerson=personID, |
|
456 |
idActivity=activityID, |
|
457 |
dateStart=dateStart, |
|
458 |
dateEnd=dateEnd, |
|
459 |
weeklyPlanningAM=weeklyPlanningAM, |
|
460 |
weeklyPlanningPM=weeklyPlanningPM) |
|
461 |
return {'data': serialize_object(r)} |
|
462 | ||
463 |
@endpoint( |
|
464 |
display_category=_('Activity'), |
|
465 |
perm='can_access', |
|
466 |
display_order=4, |
|
467 |
description=_('Update schedule calendars'), |
|
468 |
name='update-schedule-calendars', |
|
469 |
parameters={ |
|
470 |
'NameID': {'description': _('Publik ID')}, |
|
471 |
'personID': {'description': _('Person ID')}, |
|
472 |
'activityID': {'description': _('Activity ID')}, |
|
473 |
'unitID': {'description': _('Unit ID')}, |
|
474 |
'placeID': {'description': _('Place ID')}, |
|
475 |
'day': {'description': _('Date')}, |
|
476 |
'action': {'description': _('Booking action: ADD_PRES_PREVI or DEL_PRES_PREVI')}, |
|
477 |
}) |
|
478 |
def update_schedule_calendars(self, request, NameID, personID, activityID, unitID, placeID, |
|
479 |
day, action): |
|
480 |
link = self.get_link(NameID) |
|
481 |
family_data = self.get_family_data(link.family_id) |
|
482 |
if personID not in [c['id'] for c in family_data['childInfoList']]: |
|
483 |
raise APIError('Child not found', err_code='not-found') |
|
484 | ||
485 |
client = self.get_client('ActivityService?wsdl') |
|
486 |
type_event1 = client.get_type('ns1:updateScheduleCalendarsRequestBean') |
|
487 |
type_event2 = client.get_type('ns1:unitPersonDayInfoBean') |
|
488 |
event = type_event1(type_event2( |
|
489 |
numPerson=personID, |
|
490 |
idAct=activityID, |
|
491 |
idUni=unitID, |
|
492 |
idPlace=placeID, |
|
493 |
date=day, |
|
494 |
action=action, |
|
495 |
)) |
|
496 | ||
497 |
r = self.call('ActivityService?wsdl', 'updateScheduleCalendars', |
|
498 |
updateScheduleCalendarsRequestBean=event) |
|
499 |
return {'data': serialize_object(r)} |
|
500 | ||
501 |
@endpoint( |
|
502 |
display_category=_('Activity'), |
|
503 |
perm='can_access', |
|
504 |
display_order=5, |
|
505 |
description=_('Update real calendars'), |
|
506 |
name='update-real-calendars', |
|
507 |
parameters={ |
|
508 |
'NameID': {'description': _('Publik ID')}, |
|
509 |
'personID': {'description': _('Person ID')}, |
|
510 |
'activityID': {'description': _('Activity ID')}, |
|
511 |
'unitID': {'description': _('Unit ID')}, |
|
512 |
'placeID': {'description': _('Place ID')}, |
|
513 |
'day': {'description': _('Date')}, |
|
514 |
'action': {'description': _('Booking action: ADD_PRES_REAL or DEL_PRES_REAL')}, |
|
515 |
}) |
|
516 |
def update_real_calendars(self, request, NameID, personID, activityID, unitID, placeID, |
|
517 |
day, action): |
|
518 |
link = self.get_link(NameID) |
|
519 |
family_data = self.get_family_data(link.family_id) |
|
520 |
if personID not in [c['id'] for c in family_data['childInfoList']]: |
|
521 |
raise APIError('Child not found', err_code='not-found') |
|
522 | ||
523 |
client = self.get_client('ActivityService?wsdl') |
|
524 |
type_event1 = client.get_type('ns1:updateRealCalendarsRequestBean') |
|
525 |
type_event2 = client.get_type('ns1:unitPersonDayInfoBean') |
|
526 |
event = type_event1(type_event2( |
|
527 |
numPerson=personID, |
|
528 |
idAct=activityID, |
|
529 |
idUni=unitID, |
|
530 |
idPlace=placeID, |
|
531 |
date=day, |
|
532 |
action=action, |
|
533 |
)) |
|
534 | ||
535 |
r = self.call('ActivityService?wsdl', 'updateRealCalendars', |
|
536 |
updateRealCalendarsRequestBean=event) |
|
537 |
return {'data': serialize_object(r)} |
|
538 | ||
433 | 539 | |
434 | 540 |
class Link(models.Model): |
435 | 541 |
resource = models.ForeignKey(Maelis, on_delete=models.CASCADE) |
436 | 542 |
name_id = models.CharField(blank=False, max_length=256) |
437 | 543 |
family_id = models.CharField(blank=False, max_length=128) |
438 | 544 |
created = models.DateTimeField(auto_now_add=True) |
439 | 545 |
updated = models.DateTimeField(auto_now=True) |
440 | 546 |
tests/data/maelis/updateRealCalendarsResponse.xml | ||
---|---|---|
1 |
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:updateScheduleCalendarsResponse xmlns:ns1="activity.ws.maelis.sigec.com"><return><result>true</result></return></ns1:updateScheduleCalendarsResponse></soap:Body></soap:Envelope> |
tests/data/maelis/updateScheduleCalendarsResponse.xml | ||
---|---|---|
1 |
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:updateScheduleCalendarsResponse xmlns:ns1="activity.ws.maelis.sigec.com"><return><result>true</result></return></ns1:updateScheduleCalendarsResponse></soap:Body></soap:Envelope> |
tests/data/maelis/updateWeekCalendarResponse.xml | ||
---|---|---|
1 |
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:updateWeekCalendarResponse xmlns:ns1="activity.ws.maelis.sigec.com"></ns1:updateWeekCalendarResponse></soap:Body></soap:Envelope> |
tests/test_maelis.py | ||
---|---|---|
225 | 225 |
assert resp.json['data'] |
226 | 226 |
for planning in resp.json['data']: |
227 | 227 |
assert planning['id'] |
228 | 228 |
assert planning['text'] |
229 | 229 |
assert planning['days'] |
230 | 230 |
for day in planning['days']: |
231 | 231 |
assert day['id'] |
232 | 232 |
assert day['text'] |
233 | ||
234 | ||
235 |
@mock.patch('passerelle.utils.Request.get') |
|
236 |
@mock.patch('passerelle.utils.Request.post') |
|
237 |
def test_update_week_calendar(mocked_post, mocked_get, family_service_wsdl, |
|
238 |
activity_service_wsdl, app, connector): |
|
239 |
mocked_get.side_effect = ( |
|
240 |
utils.FakedResponse(content=family_service_wsdl, |
|
241 |
status_code=200, |
|
242 |
headers={'Content-Type': 'text/xml'}), |
|
243 |
utils.FakedResponse(content=activity_service_wsdl, |
|
244 |
status_code=200, |
|
245 |
headers={'Content-Type': 'text/xml'}) |
|
246 |
) |
|
247 |
mocked_post.side_effect = ( |
|
248 |
utils.FakedResponse(content=get_xml_file('readFamily.xml'), |
|
249 |
status_code=200, |
|
250 |
headers={'Content-Type': 'text/xml'}), |
|
251 |
utils.FakedResponse(content=get_xml_file('updateWeekCalendarResponse.xml'), |
|
252 |
status_code=200, |
|
253 |
headers={'Content-Type': 'text/xml'}) |
|
254 |
) |
|
255 |
Link.objects.create(resource=connector, family_id='3264', name_id='local') |
|
256 |
resp = app.get('/maelis/test/update-week-calendar?NameID=local&personID=21293' |
|
257 |
+ '&activityID=A10003132293&dateStart=2020-11-24&dateEnd=2020-11-25' |
|
258 |
+ '&weeklyPlanningAM=bof&weeklyPlanningPM=bof') |
|
259 |
assert resp.json == {'data': None, 'err': 0} |
|
260 | ||
261 | ||
262 |
@mock.patch('passerelle.utils.Request.get') |
|
263 |
@mock.patch('passerelle.utils.Request.post') |
|
264 |
def test_update_schedule_calendars(mocked_post, mocked_get, family_service_wsdl, |
|
265 |
activity_service_wsdl, app, connector): |
|
266 |
mocked_get.side_effect = ( |
|
267 |
utils.FakedResponse(content=family_service_wsdl, |
|
268 |
status_code=200, |
|
269 |
headers={'Content-Type': 'text/xml'}), |
|
270 |
utils.FakedResponse(content=activity_service_wsdl, |
|
271 |
status_code=200, |
|
272 |
headers={'Content-Type': 'text/xml'}) |
|
273 |
) |
|
274 |
mocked_post.side_effect = ( |
|
275 |
utils.FakedResponse(content=get_xml_file('readFamily.xml'), |
|
276 |
status_code=200, |
|
277 |
headers={'Content-Type': 'text/xml'}), |
|
278 |
utils.FakedResponse(content=get_xml_file('updateScheduleCalendarsResponse.xml'), |
|
279 |
status_code=200, |
|
280 |
headers={'Content-Type': 'text/xml'}) |
|
281 |
) |
|
282 |
Link.objects.create(resource=connector, family_id='3264', name_id='local') |
|
283 |
resp = app.get('/maelis/test/update-schedule-calendars?NameID=local&personID=21293' |
|
284 |
+ '&activityID=A10003132030&unitID=A10003132038&placeID=A10000000212' |
|
285 |
+ '&day=2020-11-25&action=ADD_PRES_PREVI') |
|
286 |
assert resp.json['data'] == {'result' : True, 'unitPersonDayInfoList' : []} |
|
287 | ||
288 | ||
289 |
@mock.patch('passerelle.utils.Request.get') |
|
290 |
@mock.patch('passerelle.utils.Request.post') |
|
291 |
def test_update_real_calendars(mocked_post, mocked_get, family_service_wsdl, |
|
292 |
activity_service_wsdl, app, connector): |
|
293 |
mocked_get.side_effect = ( |
|
294 |
utils.FakedResponse(content=family_service_wsdl, |
|
295 |
status_code=200, |
|
296 |
headers={'Content-Type': 'text/xml'}), |
|
297 |
utils.FakedResponse(content=activity_service_wsdl, |
|
298 |
status_code=200, |
|
299 |
headers={'Content-Type': 'text/xml'}) |
|
300 |
) |
|
301 |
mocked_post.side_effect = ( |
|
302 |
utils.FakedResponse(content=get_xml_file('readFamily.xml'), |
|
303 |
status_code=200, |
|
304 |
headers={'Content-Type': 'text/xml'}), |
|
305 |
utils.FakedResponse(content=get_xml_file('updateRealCalendarsResponse.xml'), |
|
306 |
status_code=200, |
|
307 |
headers={'Content-Type': 'text/xml'}) |
|
308 |
) |
|
309 |
Link.objects.create(resource=connector, family_id='3264', name_id='local') |
|
310 |
resp = app.get('/maelis/test/update-real-calendars?NameID=local&personID=21293' |
|
311 |
+ '&activityID=A10003132030&unitID=A10003132038&placeID=A10000000212' |
|
312 |
+ '&day=2020-11-25&action=ADD_PRES_PREVI') |
|
313 |
assert resp.json['data'] == {'result' : True, 'unitPersonDayInfoList' : []} |
|
233 |
- |