def get_passages_wrong_response_test(): """ test that if timeo returns a not valid response, we get None (and not an empty list) """ timeo = Timeo(id='tata', timezone='UTC', service_url='http://bob.com/tata', service_args={ 'a': 'bobette', 'b': '12' }) mock_response = { "CorrelationID": "GetNextStopTimesResponse-16022016 15:30", "MessageResponse": [{ "ResponseCode": "0", "ResponseComment": "success" }] } # we need to mock the datetime.now() because for timeo we don't have a choice but to combine # the current day with the timeo's response with mock.patch( 'jormungandr.realtime_schedule.timeo.Timeo._get_direction_name', lambda timeo, **kwargs: None): passages = timeo._get_passages(mock_response, current_dt=_dt("02:02")) assert passages is None
def get_passages_test(): """ test the next departures get from timeo's response the timezone is UTC for convenience """ timeo = Timeo(id='tata', timezone='UTC', service_url='http://bob.com/tata', service_args={ 'a': 'bobette', 'b': '12' }) mock_response = mock_good_timeo_response() # we need to mock the datetime.now() because for timeo we don't have a choice but to combine # the current day with the timeo's response with mock.patch( 'jormungandr.realtime_schedule.timeo.Timeo._get_direction_name', lambda timeo, **kwargs: None): passages = timeo._get_passages(mock_response, current_dt=_dt("02:02")) assert len(passages) == 3 assert passages[0].datetime == _dt('15:40:04') assert passages[1].datetime == _dt('15:55:04') assert passages[2].datetime == _dt('16:10:04')
def get_passages_stop_time_with_is_realtime_test(): """ test the next departures get from timeo's response the timezone is UTC for convenience """ timeo = Timeo(id='tata', timezone='UTC', service_url='http://bob.com/tata', service_args={ 'a': 'bobette', 'b': '12' }) mock_response = mock_good_timeo_response(criteria=3) # we need to mock the datetime.now() because for timeo we don't have a choice but to combine # the current day with the timeo's response with mock.patch( 'jormungandr.realtime_schedule.timeo.Timeo._get_direction', lambda timeo, **kwargs: Direction("StopPoint_Bob", "A direction"), ): passages = timeo._get_passages(MockResponse(200, 'http://bob.com/tata', mock_response), current_dt=_dt("02:02")) assert len(passages) == 1 assert passages[0].datetime == _dt('16:10:04')
def get_passages_no_passages_test(): """ test that if timeo returns 0 response, we return an empty list """ timeo = Timeo(id='tata', timezone='UTC', service_url='http://bob.com/tata', service_args={ 'a': 'bobette', 'b': '12' }) mock_response = { "CorrelationID": "GetNextStopTimesResponse-16022016 15:30", "MessageResponse": [{ "ResponseCode": 0, "ResponseComment": "success" }], "StopTimesResponse": [{ "StopID": "StopPoint_OLS01070201", "StopTimeoCode": "3331", "StopLongName": "André Malraux", "StopShortName": "André Malraux", "StopVocalName": "André Malraux", "ReferenceTime": "15:30:06", "NextStopTimesMessage": { "LineID": "line_id", "LineTimeoCode": "line_toto", "Way": "route_tata", "LineMainDirection": "Bicharderies", "NextExpectedStopTime": [], # emtpy list }, }], } # we need to mock the datetime.now() because for timeo we don't have a choice but to combine # the current day with the timeo's response with mock.patch( 'jormungandr.realtime_schedule.timeo.Timeo._get_direction_name', lambda timeo, **kwargs: None): passages = timeo._get_passages(MockResponse(200, 'http://bob.com/tata', mock_response), current_dt=_dt("02:02")) assert len(passages) == 0