def make_url_invalid_code_test(): """ test make_url when RoutePoint does not have a mandatory code we should not get any url """ cleverage = Cleverage(id='tata', timezone='Europe/Paris', service_url='http://bob.com/', service_args={'a': 'bobette', 'b': '12'}) url = cleverage._make_url(MockRoutePoint(line_code='line_toto', stop_id=None)) assert url is None
def status_test(): cleverage = Cleverage( id=u'tata-é$~#@"*!\'`§èû', timezone='Europe/Paris', service_url='http://bob.com/', service_args={ 'a': 'bobette', 'b': '12' }, ) status = cleverage.status() assert status['id'] == u"tata-é$~#@\"*!'`§èû"
def make_url_test(): cleverage = Cleverage(id='tata', timezone='Europe/Paris', service_url='http://bob.com/', service_args={ 'a': 'bobette', 'b': '12' }) url = cleverage._make_url( MockRoutePoint(line_code='line_toto', stop_id='stop_tutu')) # it should be a valid url assert validators.url(url) assert url == 'http://bob.com/stop_tutu'
def next_passage_for_missing_line_response_test(mock_missing_line_response): """ test the whole next_passage_for_route_point mock the http call to return a response without wanted line we should get no departure """ cleverage = Cleverage(id='tata', timezone='UTC', service_url='http://bob.com/', service_args={'a': 'bobette', 'b': '12'}) mock_requests = MockRequests({ 'http://bob.com/stop_tutu': (mock_missing_line_response, 200) }) route_point = MockRoutePoint(line_code='05', stop_id='stop_tutu') with mock.patch('requests.get', mock_requests.get): passages = cleverage.next_passage_for_route_point(route_point) assert passages is None
def next_passage_for_route_point_local_timezone_test(mock_good_response): """ test the whole next_passage_for_route_point mock the http call to return a good response, we should get some next_passages """ cleverage = Cleverage( id='tata', timezone='Europe/Paris', service_url='http://bob.com/', service_args={ 'a': 'bobette', 'b': '12' }, ) mock_requests = MockRequests( {'http://bob.com/stop_tutu': (mock_good_response, 200)}) route_point = MockRoutePoint(line_code='05', stop_id='stop_tutu') with mock.patch('requests.get', mock_requests.get): passages = cleverage.next_passage_for_route_point(route_point) assert len(passages) == 2 assert passages[0].datetime == datetime.datetime(2016, 4, 11, 12, 37, 15, tzinfo=pytz.UTC) assert passages[0].is_real_time assert passages[1].datetime == datetime.datetime(2016, 4, 11, 12, 45, 35, tzinfo=pytz.UTC) assert passages[1].is_real_time
def next_passage_with_theoric_time_response_test(mock_theoric_response): """ test the whole next_passage_for_route_point mock the http call to return a response with a theoric time we should get one departure """ cleverage = Cleverage(id='tata', timezone='UTC', service_url='http://bob.com/', service_args={ 'a': 'bobette', 'b': '12' }) mock_requests = MockRequests( {'http://bob.com/stop_tutu': (mock_theoric_response, 200)}) route_point = MockRoutePoint(line_code='05', stop_id='stop_tutu') with mock.patch('requests.get', mock_requests.get): passages = cleverage.next_passage_for_route_point(route_point) assert len(passages) == 2 assert passages[0].datetime == datetime.datetime(2016, 4, 11, 14, 37, 15, tzinfo=pytz.UTC) assert not passages[0].is_real_time assert passages[1].datetime == datetime.datetime(2016, 4, 11, 14, 45, 35, tzinfo=pytz.UTC) assert passages[1].is_real_time