def test_best_route_logs(self): with self.assertLogs('backend', level='INFO') as log: route = FindRoute('GRU', 'CDG', FILE) route.dijkstra() route.best_route() self.assertIn('best route: GRU - BRC - SCL - ORL - CDG > 40', log.output[0])
def test_get_route_brc_cdg(self): route = FindRoute('BRC', 'CDG', FILE) route.dijkstra() route.best_route() self.assertEqual(route.result, { 'route': 'BRC - SCL - ORL - CDG', 'price': 30 })
def test_get_route_gru_cdg(self): route = FindRoute('GRU', 'CDG', FILE) route.dijkstra() route.best_route() self.assertEqual(route.result, { 'route': 'GRU - BRC - SCL - ORL - CDG', 'price': 40 })
def test_get_route_brc_cdg_with_lowercase(self): route = FindRoute('brc', 'cdg', FILE) route.dijkstra() route.best_route() self.assertEqual(route.result, { 'route': 'BRC - SCL - ORL - CDG', 'price': 30 })
def get_route(self): route = FindRoute( self.route_data['query_params']['source'].upper(), self.route_data['query_params']['destination'].upper(), self.data ) route.dijkstra() route.best_route() result = { 'route': f"{route.source} - {' - '.join(route.path)}", 'price': route.price } return result
def test_best_route(self): route = FindRoute('GRU', 'CDG', FILE) route.dijkstra() best_route = route.best_route() result_string_expected = ( f"best route: {route.source} - {' - '.join(route.path)}" f" > {route.shortest_distance[route.destination]}") self.assertEqual(best_route, result_string_expected)
def test_get_route_without_file(self): route = FindRoute('brc', 'cdg') route.dijkstra() route.best_route() self.assertEqual(route.result, {})
def test_get_route_without_destination(self): route = FindRoute('brc', '', FILE) route.dijkstra() route.best_route() self.assertEqual(route.result, {})
def test_get_route_without_source(self): route = FindRoute('', 'cdg', FILE) route.dijkstra() route.best_route() self.assertEqual(route.result, {})