diff --git a/geotrek/trekking/parsers.py b/geotrek/trekking/parsers.py index e9b8b55a6d..7c16c201c9 100644 --- a/geotrek/trekking/parsers.py +++ b/geotrek/trekking/parsers.py @@ -939,6 +939,8 @@ def _get_geom_from_gpx(data): geos = ApidaeTrekParser._maybe_get_linestring_from_layer(layer) if geos: break + else: + raise RowImportError("No LineString feature found in GPX layers tracks or routes") geos.transform(settings.SRID) return geos diff --git a/geotrek/trekking/tests/data/apidae_trek_parser/trace_with_no_feature.gpx b/geotrek/trekking/tests/data/apidae_trek_parser/trace_with_no_feature.gpx new file mode 100644 index 0000000000..688a805168 --- /dev/null +++ b/geotrek/trekking/tests/data/apidae_trek_parser/trace_with_no_feature.gpx @@ -0,0 +1,5 @@ + + + diff --git a/geotrek/trekking/tests/test_parsers.py b/geotrek/trekking/tests/test_parsers.py index 8fd2656383..7037dc2e68 100644 --- a/geotrek/trekking/tests/test_parsers.py +++ b/geotrek/trekking/tests/test_parsers.py @@ -1480,6 +1480,12 @@ def test_it_handles_segment_with_single_point(self): self.assertEqual(geom.geom_type, 'LineString') self.assertEqual(len(geom.coords), 13) + def test_it_raises_an_error_when_no_linestring(self): + gpx = self._get_gpx_from('geotrek/trekking/tests/data/apidae_trek_parser/trace_with_no_feature.gpx') + + with self.assertRaises(RowImportError): + ApidaeTrekParser._get_geom_from_gpx(gpx) + class KmlToGeomTests(SimpleTestCase):