From faf474521dfc470e85ad9811f6123d1d0659892e Mon Sep 17 00:00:00 2001 From: antoine-de Date: Tue, 7 Jul 2015 14:45:08 +0200 Subject: [PATCH] Jormungandr: update the test and return a nice error when no solution found --- .../jormungandr/tests/authentication_tests.py | 2 +- source/jormungandr/tests/isochrone_tests.py | 32 +++++++++++-------- source/routing/raptor_api.cpp | 6 ++++ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/source/jormungandr/tests/authentication_tests.py b/source/jormungandr/tests/authentication_tests.py index fcb1c4a5100..77379ce4be1 100644 --- a/source/jormungandr/tests/authentication_tests.py +++ b/source/jormungandr/tests/authentication_tests.py @@ -183,7 +183,7 @@ def test_unkown_region(self): the authentication process must not mess if the region is not found """ with user_set(app, 'bob'): - r, status = self.query_no_assert('/v1/coverage/the_marvelous_unknown_region/stop_areas', display=True) + r, status = self.query_no_assert('/v1/coverage/the_marvelous_unknown_region/stop_areas') assert status == 404 assert 'error' in r diff --git a/source/jormungandr/tests/isochrone_tests.py b/source/jormungandr/tests/isochrone_tests.py index 8302dc7a562..8701e10f237 100644 --- a/source/jormungandr/tests/isochrone_tests.py +++ b/source/jormungandr/tests/isochrone_tests.py @@ -62,31 +62,37 @@ def test_stop_point_isochrone_coord(self): assert response["journeys"][1]["to"]["stop_point"]["id"] == "D" def test_to_isochrone_coord(self): - #NOTE: we query /v1/coverage/basic_routing_test/journeys and not directly /v1/journeys - #not to use the jormungandr database - query = "v1/coverage/basic_routing_test/journeys?from={}&datetime={}&datetime_represents=arrival" + query = "v1/coverage/basic_routing_test/journeys?from={}&datetime={}" query = query.format(s_coord, "20120614T080000") self.query(query) def test_from_isochrone_sa(self): - #NOTE: we query /v1/coverage/basic_routing_test/journeys and not directly /v1/journeys - #not to use the jormungandr database query = "v1/coverage/basic_routing_test/journeys?from={}&datetime={}" query = query.format("stopA", "20120614T080000") self.query(query) def test_to_isochrone_sa(self): - #NOTE: we query /v1/coverage/basic_routing_test/journeys and not directly /v1/journeys - #not to use the jormungandr database - query = "v1/coverage/basic_routing_test/journeys?from={}&datetime={}&datetime_represents=arrival" + query = "v1/coverage/basic_routing_test/journeys?to={}&datetime={}&datetime_represents=arrival" query = query.format("stopA", "20120614T080000") self.query(query) def test_reverse_isochrone_coord(self): - q = "v1/coverage/basic_routing_test/journeys?max_duration=25500&datetime=20120614T080000" - normal_response = self.query(q + "&from=A") + q = "v1/coverage/basic_routing_test/journeys?max_duration=100000" \ + "&datetime=20120615T200000&datetime_represents=arrival&to=D" + normal_response = self.query(q, display=True) assert len(normal_response["journeys"]) == 2 - # the reverse isochrone should also find 2 journeys - normal_response = self.query(q + "&to=A") - assert len(normal_response["journeys"]) == 2 + def test_reverse_isochrone_coord_clockwise(self): + q = "v1/coverage/basic_routing_test/journeys?datetime=20120614T080000&to=A" + normal_response, error_code = self.query_no_assert(q) + + assert error_code == 404 + assert normal_response['error']['message'] == 'reverse isochrone works only for anti-clockwise request' + + + def test_isochrone_non_clockwise(self): + q = "v1/coverage/basic_routing_test/journeys?datetime=20120614T080000&from=A&datetime_represents=arrival" + normal_response, error_code = self.query_no_assert(q) + + assert error_code == 404 + assert normal_response['error']['message'] == 'isochrone works only for clockwise request' \ No newline at end of file diff --git a/source/routing/raptor_api.cpp b/source/routing/raptor_api.cpp index 30ecef15eb6..59fe66b8070 100644 --- a/source/routing/raptor_api.cpp +++ b/source/routing/raptor_api.cpp @@ -1072,6 +1072,12 @@ pbnavitia::Response make_isochrone(RAPTOR &raptor, return journey1.destination().uri() < journey2.destination().uri(); }); + if (response.journeys().size() == 0) { + fill_pb_error(pbnavitia::Error::no_solution, "no solution found for this isochrone", + response.mutable_error()); + response.set_response_type(pbnavitia::NO_SOLUTION); + } + return response; }