From 664b00b16cd805ac06c8850b87126eb8677969da Mon Sep 17 00:00:00 2001 From: Justine Fricou Date: Tue, 9 Jul 2024 16:10:38 +0200 Subject: [PATCH] Add test case for route_geometry view: error 500 --- geotrek/core/tests/test_views.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/geotrek/core/tests/test_views.py b/geotrek/core/tests/test_views.py index be62bb3d73..9bb9e7cb80 100644 --- a/geotrek/core/tests/test_views.py +++ b/geotrek/core/tests/test_views.py @@ -97,6 +97,10 @@ def test_delete_multiple_path(self): self.assertEqual(Path.objects.filter(pk__in=[path_1.pk, path_2.pk]).count(), 0) +def get_route_exception_mock(steps): + raise Exception + + @skipIf(not settings.TREKKING_TOPOLOGY_ENABLED, 'Test with dynamic segmentation only') class PathViewsTest(CommonTest): model = Path @@ -684,6 +688,16 @@ def test_route_geometry_fail_incorrect_lng(self): response = self.get_route_geometry({"steps": [{"lat": 48.866667, "lng": "abc"}, {"lat": 47.866667, "lng": 1.333333}]}) self.assertEqual(response.status_code, 400) + @mock.patch('geotrek.core.path_router.PathRouter.get_route', get_route_exception_mock) + def test_route_geometry_fail_error_500(self): + response = self.get_route_geometry({ + "steps": [ + {"lat": 40.5267991, "lng": 0.5305685}, + {"lat": 40.5266465, "lng": 0.5765381} + ] + }) + self.assertEqual(response.status_code, 500) + def test_route_geometry_fail_steps_not_on_paths(self): path_geom = LineString([ [1.3664246, 43.4569065],