Skip to content

Commit

Permalink
Modify test_route_geometry_not_fail_with_via_points_several_paths to …
Browse files Browse the repository at this point in the history
…include more cases
  • Loading branch information
justinefricou committed Jul 11, 2024
1 parent 2d611ab commit 0e2f942
Showing 1 changed file with 61 additions and 29 deletions.
90 changes: 61 additions & 29 deletions geotrek/core/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,52 +827,84 @@ def test_route_geometry_not_fail_with_via_point_one_path(self):
self.assertEqual(len(ser.get('positions').get(0)), 2)
self.assertEqual(len(ser.get('paths')), 1)

# def test_route_geometry_not_fail_with_via_points_several_paths(self):
# pathGeom1 = LineString([
# [1.4451303, 43.5270311],
# [1.5305685, 43.5267991],
# ], srid=settings.API_SRID)
# pathGeom1.transform(settings.SRID)
# PathFactory(geom=pathGeom1)

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

# response = self.get_route_geometry({
# "steps": [
# {"lat": 43.55713801872145, "lng": 1.5297106650186976},
# {"lat": 43.5357564571998, "lng": 1.530315275025278},
# {"lat": 43.526894753922015, "lng": 1.49534225136577},
# {"lat": 43.526909669925175, "lng": 1.4898491643494793}
# ]
# })
# 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')), 2)
# self.assertEqual(len(geometries[1].get('coordinates')), 3)
# 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()), 1)
# self.assertEqual(len(serialized[0].get('positions').get(0)), 2)
# self.assertEqual(len(serialized[0].get('paths')), 1)

# self.assertEqual(len(serialized[1].get('positions').items()), 2)
# self.assertEqual(len(serialized[1].get('positions').get(0)), 2)
# self.assertEqual(len(serialized[1].get('positions').get(1)), 2)
# self.assertEqual(len(serialized[1].get('paths')), 2)

# self.assertEqual(len(serialized[2].get('positions').items()), 1)
# self.assertEqual(len(serialized[2].get('positions').get(0)), 2)
# self.assertEqual(len(serialized[2].get('paths')), 1)

def test_route_geometry_not_fail_with_via_points_several_paths(self):
pathGeom1 = LineString([
[1.4451303, 43.5270311],
[1.5305685, 43.5267991],
[1.4447021, 43.5803909],
[1.4451303, 43.5270311]
], srid=settings.API_SRID)
pathGeom1.transform(settings.SRID)
PathFactory(geom=pathGeom1)

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

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

response = self.get_route_geometry({
"steps": [
{"lat": 43.55713801872145, "lng": 1.5297106650186976},
{"lat": 43.5357564571998, "lng": 1.530315275025278},
{"lat": 43.526894753922015, "lng": 1.49534225136577},
{"lat": 43.526909669925175, "lng": 1.4898491643494793}
{"lat": 43.57192876776824, "lng": 1.4447700319492318},
{"lat": 43.546062327348785, "lng": 1.5300238809766273},
{"lat": 43.57342803491799, "lng": 1.5292498854902847},
{"lat": 43.60030465103801, "lng": 1.5284893807630917},
]
})
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')), 2)
self.assertEqual(len(geometries[1].get('coordinates')), 3)
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()), 1)
self.assertEqual(len(serialized[0].get('positions').get(0)), 2)
self.assertEqual(len(serialized[0].get('paths')), 1)

self.assertEqual(len(serialized[1].get('positions').items()), 2)
self.assertEqual(len(serialized[1].get('positions').get(0)), 2)
self.assertEqual(len(serialized[1].get('positions').get(1)), 2)
self.assertEqual(len(serialized[1].get('paths')), 2)

self.assertEqual(len(serialized[2].get('positions').items()), 1)
self.assertEqual(len(serialized[2].get('positions').get(0)), 2)
self.assertEqual(len(serialized[2].get('paths')), 1)


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

0 comments on commit 0e2f942

Please sign in to comment.