Projet

Général

Profil

0002-toulouse-axel-annual-booking-for-next-year-44727.patch

Lauréline Guérin, 02 juillet 2020 14:58

Télécharger (5,5 ko)

Voir les différences:

Subject: [PATCH 2/2] toulouse-axel: annual booking for next year (#44727)

 passerelle/contrib/toulouse_axel/models.py  |  6 ++--
 passerelle/contrib/toulouse_axel/schemas.py |  5 +--
 tests/test_toulouse_axel.py                 | 37 ++++++++++++---------
 3 files changed, 29 insertions(+), 19 deletions(-)
passerelle/contrib/toulouse_axel/models.py
1400 1400

  
1401 1401
        # build dates of the period
1402 1402
        today = datetime.date.today()
1403
        reference_year = utils.get_reference_year_from_date(today)
1404
        start_date = today + datetime.timedelta(days=8)
1403
        start_date_min = today + datetime.timedelta(days=8)
1404
        start_date = datetime.datetime.strptime(post_data['booking_date'], utils.json_date_format).date()
1405
        start_date = max(start_date, start_date_min)
1406
        reference_year = utils.get_reference_year_from_date(start_date)
1405 1407
        end_date = datetime.date(reference_year+1, 7, 31)
1406 1408

  
1407 1409
        # get known activities for this child, to have the ids
passerelle/contrib/toulouse_axel/schemas.py
425 425
                {'type': 'null'},
426 426
                {'type': 'string', 'enum': ['', 'SV', 'AV']}
427 427
            ]
428
        }
428
        },
429
        'booking_date': copy.deepcopy(utils.date_type)
429 430
    },
430
    'required': ['booking_list_MAT', 'booking_list_MIDI', 'booking_list_SOIR', 'booking_list_GARD', 'child_id']
431
    'required': ['booking_list_MAT', 'booking_list_MIDI', 'booking_list_SOIR', 'booking_list_GARD', 'child_id', 'booking_date']
431 432
}
tests/test_toulouse_axel.py
153 153
        'booking_list_GARD': ['3535:GARD:A19P1M4:wednesday'],
154 154
        'child_id': '3535',
155 155
        'regime': 'AV',
156
        'booking_date': '2019-08-01',
156 157
    }
157 158

  
158 159

  
......
3796 3797
        assert 'ACTIVITE' not in payload['ENFANT'][0]
3797 3798

  
3798 3799

  
3799
def test_clae_booking_annual_reference_year(app, resource, annual_booking_params, child_activities_data):
3800
@freezegun.freeze_time('2019-09-01')
3801
def test_clae_booking_annual_next_year(app, resource, child_activities_data):
3800 3802
    Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
3801 3803
    activities = child_activities_data['ENFANT'][0]
3802
    with freezegun.freeze_time('2020-04-16'):
3803
        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_child_activities', return_value=activities):
3804
            with mock.patch('passerelle.contrib.toulouse_axel.schemas.reservation_annuelle') as operation:
3805
                operation.return_value = schemas.OperationResult(json_response={}, xml_request='', xml_response='')
3806
                app.post_json('/toulouse-axel/test/clae_booking_annual?NameID=yyy', params=annual_booking_params)
3807
    payload = operation.call_args_list[0][0][1]['PORTAIL']['DUI']
3808
    assert payload['ENFANT'][0]['ACTIVITE'][0]['PERIODE'][0]['DATEDEBUT'] == '2020-04-24'
3809
    assert payload['ENFANT'][0]['ACTIVITE'][0]['PERIODE'][0]['DATEDFIN'] == '2020-07-31'
3810
    with freezegun.freeze_time('2020-08-01'):
3811
        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_child_activities', return_value=activities):
3812
            with mock.patch('passerelle.contrib.toulouse_axel.schemas.reservation_annuelle') as operation:
3813
                operation.return_value = schemas.OperationResult(json_response={}, xml_request='', xml_response='')
3814
                app.post_json('/toulouse-axel/test/clae_booking_annual?NameID=yyy', params=annual_booking_params)
3804
    for activity in activities['ACTIVITE']:
3805
        activity['DATEDEBUT'] = '2020-08-01'
3806
        activity['DATEENTREE'] = '2020-08-01'
3807
        activity['DATEFIN'] = '2021-07-31'
3808
        activity['DATESORTIE'] = '2021-07-31'
3809
    annual_booking_params = {
3810
        'booking_list_MAT': [],
3811
        'booking_list_MIDI': None,
3812
        'booking_list_SOIR': None,
3813
        'booking_list_GARD': None,
3814
        'child_id': '3535',
3815
        'regime': 'AV',
3816
        'booking_date': '2020-08-01',
3817
    }
3818
    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_child_activities', return_value=activities):
3819
        with mock.patch('passerelle.contrib.toulouse_axel.schemas.reservation_annuelle') as operation:
3820
            operation.return_value = schemas.OperationResult(json_response={}, xml_request='', xml_response='')
3821
            app.post_json('/toulouse-axel/test/clae_booking_annual?NameID=yyy', params=annual_booking_params)
3815 3822
    payload = operation.call_args_list[0][0][1]['PORTAIL']['DUI']
3816
    assert payload['ENFANT'][0]['ACTIVITE'][0]['PERIODE'][0]['DATEDEBUT'] == '2020-08-09'
3823
    assert payload['ENFANT'][0]['ACTIVITE'][0]['PERIODE'][0]['DATEDEBUT'] == '2020-08-01'
3817 3824
    assert payload['ENFANT'][0]['ACTIVITE'][0]['PERIODE'][0]['DATEDFIN'] == '2021-07-31'
3818 3825

  
3819 3826

  
3820
-