Skip to content

Commit

Permalink
feat(tests): add test for downloading submissions as GeoJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuj-Gupta4 committed Nov 26, 2024
1 parent be10187 commit 0b25603
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/backend/tests/test_submission_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#
"""Tests for submission routes."""

import json

import pytest


Expand Down Expand Up @@ -111,6 +113,43 @@ async def test_get_submission_count(client, submission):
assert submission_count > 0, "Submission count should be greater than zero"


async def test_download_submission_geojson(client, submission):
"""Test downloading submissions as a GeoJSON file."""
odk_project = submission["project"]

response = await client.get(
f"/submission/download-submission-geojson?project_id={odk_project.id}"
)

assert (
response.status_code == 200
), f"Failed to download GeoJSON submissions. Response: {response.text}"

assert (
"Content-Disposition" in response.headers
), "Missing Content-Disposition header"
expected_filename = f"{odk_project.slug}.geojson"
assert response.headers["Content-Disposition"].endswith(
expected_filename
), f"Expected file name to end with {expected_filename}"

submission_geojson = json.loads(response.content)
assert isinstance(
submission_geojson, dict
), "Expected GeoJSON content to be a dictionary"
assert "type" in submission_geojson, "Missing 'type' key in GeoJSON"
assert (
submission_geojson["type"] == "FeatureCollection"
), "GeoJSON type must be 'FeatureCollection'"
assert "features" in submission_geojson, "Missing 'features' key in GeoJSON"
assert isinstance(
submission_geojson["features"], list
), "Expected 'features' to be a list"
assert (
len(submission_geojson["features"]) > 0
), "Expected at least one feature in 'features'"


if __name__ == "__main__":
"""Main func if file invoked directly."""
pytest.main()

0 comments on commit 0b25603

Please sign in to comment.