Skip to content

Commit

Permalink
Refacto unit tests: use path3 instead of path4 in some tests so that …
Browse files Browse the repository at this point in the history
…the response data doesn't have to be checked again
  • Loading branch information
justinefricou committed Dec 11, 2024
1 parent d3f0b86 commit efda6bd
Showing 1 changed file with 29 additions and 37 deletions.
66 changes: 29 additions & 37 deletions geotrek/core/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1562,26 +1562,26 @@ def test_route_geometry_succeed_with_detour_then_add_path_and_succeed(self):

def test_route_geometry_succeed_then_delete_path_and_fail(self):
"""
Route once from path2 to path1 going through path4, then delete path4: routing now fails
Route once from path2 to path1 going through path3, then delete path3: routing now fails
─ : path
> : path direction
X : route step
start path1
X────────>────────
^ path4 (deleted after 1st routing)
X────────>────────
X────────>────────
^ path3
X────────>────────
end path2
"""
path1 = PathFactory(geom=self.path_geometries['1'])
path2 = PathFactory(geom=self.path_geometries['2'])
path4 = PathFactory(geom=self.path_geometries['4'])
path3 = PathFactory(geom=self.path_geometries['3'])
steps = {
"steps": [
dict(ChainMap({"path_id": path1.pk}, self.steps_coordinates['1'])),
Expand All @@ -1590,15 +1590,11 @@ def test_route_geometry_succeed_then_delete_path_and_fail(self):
}

response1 = self.get_route_geometry(steps)
# This response data is already tested in test_route_geometry_steps_on_different_paths,
# so we only make sure that it succeeds:
self.assertEqual(response1.status_code, 200)
expected_data = self.get_expected_data('through_path4', {
'1': path1.pk,
'2': path2.pk,
'4': path4.pk,
})
self.check_route_geometry_response(response1.data, expected_data)

path4.delete()
path3.delete()
response = self.get_route_geometry(steps)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.data.get('error'), "No path between the given points")
Expand Down Expand Up @@ -1702,26 +1698,26 @@ def test_route_geometry_fail_then_edit_and_succeed(self):

def test_route_geometry_fail_after_editing_path(self):
"""
Route once from path1 to path2 (going through path4), then edit path4
Route once from path1 to path2 (going through path3), then edit path3
so it doesn't link path1 with path2 anymore: there is no possible route
─ : path
> : path direction
X : route step
start path1 start path1
X───────>── X───────>────
/
/
^ path4 -> / path4
/
X─────>──── X──────>─────
end path2 end path2
start path1 start path1
X───────>── X───────>────
/
/
path3 ^ -> / path3
/
X─────>──── X──────>─────
end path2 end path2
"""
path1 = PathFactory(geom=self.path_geometries['1'])
path2 = PathFactory(geom=self.path_geometries['2'])
path4 = PathFactory(geom=self.path_geometries['4'])
path3 = PathFactory(geom=self.path_geometries['3'])

steps = {
"steps": [
Expand All @@ -1730,21 +1726,17 @@ def test_route_geometry_fail_after_editing_path(self):
]
}
response1 = self.get_route_geometry(steps)
# This response data is already tested in test_route_geometry_steps_on_different_paths,
# so we only make sure that it succeeds:
self.assertEqual(response1.status_code, 200)
expected_data = self.get_expected_data('through_path4', {
'1': path1.pk,
'2': path2.pk,
'4': path4.pk,
})
self.check_route_geometry_response(response1.data, expected_data)

newPathGeom4 = LineString([
newPathGeom3 = LineString([
[1.4507103, 43.5547065],
[1.4611816, 43.5567592]
], srid=settings.API_SRID)
newPathGeom4.transform(settings.SRID)
path4.geom = newPathGeom4
path4.save()
newPathGeom3.transform(settings.SRID)
path3.geom = newPathGeom3
path3.save()

response2 = self.get_route_geometry(steps)
self.assertEqual(response2.status_code, 400)
Expand Down

0 comments on commit efda6bd

Please sign in to comment.