def next_passage_for_route_point_timeo_failure_test(): """ test the whole next_passage_for_route_point the timeo's response is in error (status = 404), we should get 'None' """ timeo = Timeo(id='tata', timezone='UTC', service_url='http://bob.com/tata', service_args={ 'a': 'bobette', 'b': '12' }) mock_requests = MockRequests({ 'http://bob.com/tata?a=bobette&b=12&StopDescription=?StopTimeoCode=stop_tutu&LineTimeoCode' '=line_toto&Way=route_tata&NextStopTimeNumber=5&StopTimeType=TR;': (mock_good_timeo_response(), 404) }) route_point = MockRoutePoint(route_id='route_tata', line_id='line_toto', stop_id='stop_tutu') with mock.patch('requests.get', mock_requests.get): passages = timeo.next_passage_for_route_point(route_point, current_dt=_dt("02:02")) assert passages is None
def next_passage_for_route_point_test(): """ test the whole next_passage_for_route_point mock the http call to return a good timeo response, we should get some next_passages """ timeo = Timeo(id='tata', timezone='UTC', service_url='http://bob.com/tata', service_args={ 'a': 'bobette', 'b': '12' }) mock_requests = MockRequests({ 'http://bob.com/tata?a=bobette&b=12&StopDescription=?StopTimeoCode=stop_tutu&LineTimeoCode' '=line_toto&Way=route_tata&NextStopTimeNumber=5&StopTimeType=TR;': (mock_good_timeo_response(), 200) }) route_point = MockRoutePoint(route_id='route_tata', line_id='line_toto', stop_id='stop_tutu') # we mock the http call to return the hard coded mock_response with mock.patch('requests.get', mock_requests.get): with mock.patch( 'jormungandr.realtime_schedule.timeo.Timeo._get_direction_name', lambda timeo, **kwargs: None): passages = timeo.next_passage_for_route_point( route_point, 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')