diff --git a/terraso_backend/tests/core/gis/test_parsers.py b/terraso_backend/tests/core/gis/test_parsers.py index 1e54e1f83..1c86d2ebc 100644 --- a/terraso_backend/tests/core/gis/test_parsers.py +++ b/terraso_backend/tests/core/gis/test_parsers.py @@ -68,6 +68,36 @@ """ +GPX_CONTENT = """ + + + 0 + + + + + + 0 + + + + + + 0 + + + + + + 0 + + + + +""" + KML_GEOJSON = { "type": "FeatureCollection", "features": [ @@ -115,6 +145,132 @@ ], } +GPX_GEOJSON = { + "type": "FeatureCollection", + "features": [ + { + "id": "0", + "type": "Feature", + "properties": { + "ele": 0.0, + "time": None, + "magvar": None, + "geoidheight": None, + "name": "Portland", + "cmt": "Waypoint no: 1", + "desc": "This is waypoint no: 1", + "src": None, + "link1_href": None, + "link1_text": None, + "link1_type": None, + "link2_href": None, + "link2_text": None, + "link2_type": None, + "sym": None, + "type": None, + "fix": None, + "sat": None, + "hdop": None, + "vdop": None, + "pdop": None, + "ageofdgpsdata": None, + "dgpsid": None, + }, + "geometry": {"type": "Point", "coordinates": [-122.681944, 45.52]}, + }, + { + "id": "1", + "type": "Feature", + "properties": { + "ele": 0.0, + "time": None, + "magvar": None, + "geoidheight": None, + "name": "Rio de Janeiro", + "cmt": "Waypoint no: 2", + "desc": "This is waypoint no: 2", + "src": None, + "link1_href": None, + "link1_text": None, + "link1_type": None, + "link2_href": None, + "link2_text": None, + "link2_type": None, + "sym": None, + "type": None, + "fix": None, + "sat": None, + "hdop": None, + "vdop": None, + "pdop": None, + "ageofdgpsdata": None, + "dgpsid": None, + }, + "geometry": {"type": "Point", "coordinates": [-43.196389, -22.908333]}, + }, + { + "id": "2", + "type": "Feature", + "properties": { + "ele": 0.0, + "time": None, + "magvar": None, + "geoidheight": None, + "name": "Istanbul", + "cmt": "Waypoint no: 3", + "desc": "This is waypoint no: 3", + "src": None, + "link1_href": None, + "link1_text": None, + "link1_type": None, + "link2_href": None, + "link2_text": None, + "link2_type": None, + "sym": None, + "type": None, + "fix": None, + "sat": None, + "hdop": None, + "vdop": None, + "pdop": None, + "ageofdgpsdata": None, + "dgpsid": None, + }, + "geometry": {"type": "Point", "coordinates": [28.976018, 41.01224]}, + }, + { + "id": "3", + "type": "Feature", + "properties": { + "ele": 0.0, + "time": None, + "magvar": None, + "geoidheight": None, + "name": "Reykjavik", + "cmt": "Waypoint no: 4", + "desc": "This is waypoint no: 4", + "src": None, + "link1_href": None, + "link1_text": None, + "link1_type": None, + "link2_href": None, + "link2_text": None, + "link2_type": None, + "sym": None, + "type": None, + "fix": None, + "sat": None, + "hdop": None, + "vdop": None, + "pdop": None, + "ageofdgpsdata": None, + "dgpsid": None, + }, + "geometry": {"type": "Point", "coordinates": [-21.933333, 64.133333]}, + }, + ], +} + @pytest.fixture def shapefile_zip(request): @@ -181,3 +337,33 @@ def test_parse_kml_file(kml_file): # Assert that the output of the parse_kml_file function is as expected assert kml_json == KML_GEOJSON + + +@pytest.fixture +def gpx_file(request): + gpx_contents, file_extension = request.param + # Create a temporary file + with tempfile.NamedTemporaryFile(mode="w", suffix=f".{file_extension}", delete=False) as f: + # Write the GPX content to the file + f.write(gpx_contents) + + # Return the file path + yield f.name + + # Clean up: delete the temporary file + os.unlink(f.name) + + +@pytest.mark.parametrize( + "gpx_file", + [ + (GPX_CONTENT, "gpx"), + ], + indirect=True, +) +def test_parse_gpx_file(gpx_file): + with open(gpx_file, "rb") as file: + gpx_json = parse_file_to_geojson(file) + + # Assert that the output of the parse_gpx_file function is as expected + assert gpx_json == GPX_GEOJSON