Skip to content

Commit

Permalink
Modify route_geometry tests: more precision when checking results
Browse files Browse the repository at this point in the history
  • Loading branch information
justinefricou committed Jul 11, 2024
1 parent 0e2f942 commit a4d732b
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions geotrek/core/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ def test_route_geometry_not_fail_no_via_point_one_path(self):
[1.6108704, 43.4539158],
], srid=settings.API_SRID)
path_geom.transform(settings.SRID)
PathFactory(geom=path_geom)
path = PathFactory(geom=path_geom)

response = self.get_route_geometry({
"steps": [
Expand All @@ -761,22 +761,22 @@ def test_route_geometry_not_fail_no_via_point_one_path(self):
self.assertEqual(len(serialized), 1)
self.assertEqual(len(serialized[0].get('positions').items()), 1)
self.assertEqual(len(serialized[0].get('positions').get(0)), 2)
self.assertEqual(len(serialized[0].get('paths')), 1)
self.assertListEqual(serialized[0].get('paths'), [path.pk])

def test_route_geometry_not_fail_no_via_point_several_paths(self):
pathGeom1 = LineString([
[1.3904572, 43.5271443],
[1.4451303, 43.5270311],
], srid=settings.API_SRID)
pathGeom1.transform(settings.SRID)
PathFactory(geom=pathGeom1)
path1 = PathFactory(geom=pathGeom1)

pathGeom2 = LineString([
[1.4447021, 43.5803909],
[1.4451303, 43.5270311],
], srid=settings.API_SRID)
pathGeom2.transform(settings.SRID)
PathFactory(geom=pathGeom2)
path2 = PathFactory(geom=pathGeom2)

response = self.get_route_geometry({
"steps": [
Expand All @@ -795,15 +795,15 @@ def test_route_geometry_not_fail_no_via_point_several_paths(self):
self.assertEqual(len(serialized[0].get('positions').items()), 2)
self.assertEqual(len(serialized[0].get('positions').get(0)), 2)
self.assertEqual(len(serialized[0].get('positions').get(1)), 2)
self.assertEqual(len(serialized[0].get('paths')), 2)
self.assertListEqual(serialized[0].get('paths'), [path1.pk, path2.pk])

def test_route_geometry_not_fail_with_via_point_one_path(self):
path_geom = LineString([
[1.3664246, 43.4569065],
[1.6108704, 43.4539158],
], srid=settings.API_SRID)
path_geom.transform(settings.SRID)
PathFactory(geom=path_geom)
path = PathFactory(geom=path_geom)

response = self.get_route_geometry({
"steps": [
Expand All @@ -825,9 +825,9 @@ def test_route_geometry_not_fail_with_via_point_one_path(self):
for ser in serialized:
self.assertEqual(len(ser.get('positions').items()), 1)
self.assertEqual(len(ser.get('positions').get(0)), 2)
self.assertEqual(len(ser.get('paths')), 1)
self.assertListEqual(ser.get('paths'), [path.pk])

# def test_route_geometry_not_fail_with_via_points_several_paths(self):
# def test_route_geometry_not_fail_with_via_points_several_paths_old(self):
# pathGeom1 = LineString([
# [1.4451303, 43.5270311],
# [1.5305685, 43.5267991],
Expand Down Expand Up @@ -880,21 +880,21 @@ def test_route_geometry_not_fail_with_via_points_several_paths(self):
[1.4451303, 43.5270311]
], srid=settings.API_SRID)
pathGeom1.transform(settings.SRID)
PathFactory(geom=pathGeom1)
path1 = PathFactory(geom=pathGeom1)

pathGeom2 = LineString([
[1.4451303, 43.5270311],
[1.5305685, 43.5267991],
], srid=settings.API_SRID)
pathGeom2.transform(settings.SRID)
PathFactory(geom=pathGeom2)
path2 = PathFactory(geom=pathGeom2)

pathGeom3 = LineString([
[1.5305685, 43.5267991],
[1.5277863, 43.6251412],
], srid=settings.API_SRID)
pathGeom3.transform(settings.SRID)
PathFactory(geom=pathGeom3)
path3 = PathFactory(geom=pathGeom3)

response = self.get_route_geometry({
"steps": [
Expand All @@ -906,6 +906,30 @@ def test_route_geometry_not_fail_with_via_points_several_paths(self):
})
self.assertEqual(response.status_code, 200)

geometries = response.data.get('geojson').get('geometries')
self.assertEqual(len(geometries), 3)
self.assertEqual(len(geometries[0].get('coordinates')), 4)
self.assertEqual(len(geometries[1].get('coordinates')), 2)
self.assertEqual(len(geometries[2].get('coordinates')), 2)
for geom in geometries:
for coords in geom.get('coordinates'):
self.assertEqual(len(coords), 2)

serialized = response.data.get('serialized')
self.assertEqual(len(serialized), 3)
self.assertEqual(len(serialized[0].get('positions').items()), 3)
for pos in list(serialized[0].get('positions').values()):
self.assertEqual(len(pos), 2)
self.assertListEqual(serialized[0].get('paths'), [path1.pk, path2.pk, path3.pk])
self.assertEqual(len(serialized[1].get('positions').items()), 1)
for pos in list(serialized[1].get('positions').values()):
self.assertEqual(len(pos), 2)
self.assertListEqual(serialized[1].get('paths'), [path3.pk])
self.assertEqual(len(serialized[1].get('positions').items()), 1)
for pos in list(serialized[1].get('positions').values()):
self.assertEqual(len(pos), 2)
self.assertListEqual(serialized[1].get('paths'), [path3.pk])


@skipIf(not settings.TREKKING_TOPOLOGY_ENABLED, 'Test with dynamic segmentation only')
class PathKmlGPXTest(TestCase):
Expand Down

0 comments on commit a4d732b

Please sign in to comment.