Projet

Général

Profil

0001-maelis-add-child-month-planning-listing-47172.patch

Serghei Mihai, 12 novembre 2020 10:57

Télécharger (7,79 ko)

Voir les différences:

Subject: [PATCH] maelis add child month planning listing (#47172)

 passerelle/apps/maelis/models.py              | 33 +++++++++++++++++++
 passerelle/apps/maelis/utils.py               | 13 ++++++++
 .../maelis/readChildMonthPlanningResponse.xml |  1 +
 tests/test_maelis.py                          | 32 ++++++++++++++++++
 4 files changed, 79 insertions(+)
 create mode 100644 tests/data/maelis/readChildMonthPlanningResponse.xml
passerelle/apps/maelis/models.py
370 370
        pass
371 371

  
372 372
    @endpoint(
373
        display_category=_('Activities'),
373 374
        perm='can_access',
375
        display_order=1,
374 376
        description=_('Get activity list'),
375 377
        name='activity-list',
376 378
        parameters={
......
397 399
        activities = serialize_object(r)
398 400
        return {'data': [utils.normalize_activity(a) for a in activities]}
399 401

  
402
    @endpoint(
403
        display_category=_('Activities'),
404
        perm='can_access',
405
        display_order=2,
406
        description=_('Read child month planning'),
407
        name='child-month-planning',
408
        parameters={
409
            'NameID': {'description': _('Publik ID')},
410
            'personID': {'description': _('Person ID')},
411
            'year': {'description': _('Year')},
412
            'month': {'description': _('Month')},
413
        })
414
    def child_month_planning(self, request, NameID, personID, activityID,
415
                             year=None, month=None):
416
        link = self.get_link(NameID)
417
        family_data = self.get_family_data(link.family_id)
418
        if personID not in [c['id'] for c in family_data['childInfoList']]:
419
            raise APIError('Child not found', err_code='not-found')
420
        if not year:
421
            year = timezone.now().year
422
        if not month:
423
            month = timezone.now().month
424

  
425
        r = self.call('ActivityService?wsdl', 'readChildMonthPlanning',
426
                      year=timezone.now().year,
427
                      numMonth=month,
428
                      idActivity=activityID,
429
                      numPerson=personID)
430
        planning = serialize_object(r['calendList'])
431
        return {'data': [utils.normalize_schedule(s) for s in planning]}
432

  
400 433

  
401 434
class Link(models.Model):
402 435
    resource = models.ForeignKey(Maelis, on_delete=models.CASCADE)
passerelle/apps/maelis/utils.py
63 63
        return now.year
64 64
    else:
65 65
        return now.year - 1
66

  
67

  
68
def normalize_schedule(schedule):
69
    schedule['id'] = schedule['unit']['idActivity']
70
    schedule['text'] = schedule['unit']['libelle']
71
    schedule['days'] = []
72
    for day in schedule.pop('listDays'):
73
        schedule['days'].append(
74
            {'type': day['dayType']['code'],
75
             'id': day['datePlanning'],
76
             'text': day['datePlanning'].strftime(datetime_format)
77
             })
78
    return schedule
tests/data/maelis/readChildMonthPlanningResponse.xml
1
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:readChildMonthPlanningResponse xmlns:ns1="activity.ws.maelis.sigec.com"><ResultCalendarList><person><num>0</num></person><calendList><unit><id>A10003123492</id><idActivity>A10003123490</idActivity><libelle>2 2020-2021  RESTAURATION SCOLAIRE</libelle><motif>X</motif></unit><listDays><datePlanning>2020-11-02T18:12:36.038+01:00</datePlanning><dayType><code>DAY</code></dayType></listDays><listDays><datePlanning>2020-11-03T18:12:36.038+01:00</datePlanning><dayType><code>DAY</code></dayType></listDays><listDays><datePlanning>2020-11-05T18:12:36.038+01:00</datePlanning><dayType><code>DAY</code></dayType></listDays><listDays><datePlanning>2020-11-06T18:12:36.038+01:00</datePlanning><dayType><code>DAY</code></dayType></listDays><listDays><datePlanning>2020-11-09T18:12:36.038+01:00</datePlanning><dayType><code>DAY</code></dayType></listDays><listDays><datePlanning>2020-11-10T18:12:36.038+01:00</datePlanning><dayType><code>DAY</code></dayType></listDays><listDays><datePlanning>2020-11-12T18:12:36.038+01:00</datePlanning><dayType><code>DAY</code></dayType></listDays><listDays><datePlanning>2020-11-13T18:12:36.038+01:00</datePlanning><dayType><code>DAY</code></dayType></listDays><listDays><datePlanning>2020-11-16T18:12:36.038+01:00</datePlanning><dayType><code>DAY</code></dayType></listDays><listDays><datePlanning>2020-11-17T18:12:36.038+01:00</datePlanning><dayType><code>DAY</code></dayType></listDays><listDays><datePlanning>2020-11-19T18:12:36.038+01:00</datePlanning><dayType><code>DAY</code></dayType></listDays><listDays><datePlanning>2020-11-20T18:12:36.038+01:00</datePlanning><dayType><code>DAY</code></dayType></listDays><listDays><datePlanning>2020-11-23T18:12:36.038+01:00</datePlanning><dayType><code>DAY</code></dayType></listDays><listDays><datePlanning>2020-11-24T18:12:36.038+01:00</datePlanning><dayType><code>DAY</code></dayType></listDays><listDays><datePlanning>2020-11-26T18:12:36.038+01:00</datePlanning><dayType><code>DAY</code></dayType></listDays><listDays><datePlanning>2020-11-27T18:12:36.038+01:00</datePlanning><dayType><code>DAY</code></dayType></listDays><listDays><datePlanning>2020-11-30T18:12:36.038+01:00</datePlanning><dayType><code>DAY</code></dayType></listDays></calendList></ResultCalendarList></ns1:readChildMonthPlanningResponse></soap:Body></soap:Envelope>
tests/test_maelis.py
198 198
    assert resp.json['data']
199 199
    assert resp.json['data']['label'] == 'FACTURATION SEPTEMBRE 2014'
200 200
    assert resp.json['data']['display_id'] == '53186'
201

  
202

  
203
@mock.patch('passerelle.utils.Request.get')
204
@mock.patch('passerelle.utils.Request.post')
205
def test_get_child_month_planning(mocked_post, mocked_get, family_service_wsdl,
206
                                  activity_service_wsdl, app, connector):
207
    mocked_get.side_effect = (
208
        utils.FakedResponse(content=family_service_wsdl,
209
                            status_code=200,
210
                            headers={'Content-Type': 'text/xml'}),
211
        utils.FakedResponse(content=activity_service_wsdl,
212
                            status_code=200,
213
                            headers={'Content-Type': 'text/xml'})
214
    )
215
    mocked_post.side_effect = (
216
        utils.FakedResponse(content=get_xml_file('readFamily.xml'),
217
                            status_code=200,
218
                            headers={'Content-Type': 'text/xml'}),
219
        utils.FakedResponse(content=get_xml_file('readChildMonthPlanningResponse.xml'),
220
                            status_code=200,
221
                            headers={'Content-Type': 'text/xml'})
222
    )
223
    Link.objects.create(resource=connector, family_id='3264', name_id='local')
224
    resp = app.get('/maelis/test/child-month-planning?NameID=local&personID=21293&activityID=A10003132293')
225
    assert resp.json['data']
226
    for planning in resp.json['data']:
227
        assert planning['id']
228
        assert planning['text']
229
        assert planning['days']
230
        for day in planning['days']:
231
            assert day['id']
232
            assert day['text']
201
-