Skip to content

Commit

Permalink
Update tests to use xlsforms as markdown
Browse files Browse the repository at this point in the history
Signed-off-by: Kipchirchir Sigei <[email protected]>
  • Loading branch information
KipSigei committed Sep 24, 2023
1 parent 1e4f165 commit ae05995
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 49 deletions.
26 changes: 24 additions & 2 deletions onadata/apps/api/tests/viewsets/test_data_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2330,7 +2330,18 @@ def test_geojson_format(self):

def test_geotraces_in_repeats(self):
# publish sample geotrace submissions
self._publish_submit_geotraces_in_repeats()
md = """
| survey |
| | type | name | label | required | calculation |
| | begin repeat | segment | Waterway trace | | |
| | calculate | point_position | | | position(..)|
| | geotrace | blueline | GPS Coordinates | yes | |
| | end repeat |
"""
self.xform = self._publish_markdown(
md, self.user, self.project, id_string="geotraces")
# publish submissions
self._publish_submit_geoms_in_repeats("Geotraces")
view = DataViewSet.as_view({"get": "list"})
request = self.factory.get("/", **self.extra)
response = view(request, pk=self.xform.pk, format="geojson")
Expand Down Expand Up @@ -2380,7 +2391,18 @@ def test_geotraces_in_repeats(self):

def test_geoshapes_in_repeats(self):
# publish sample geoshape submissions
self._publish_submit_geoshapes_in_repeats()
md = """
| survey |
| | type | name | label | required | calculation |
| | begin repeat | segment | Waterway trace | | |
| | calculate | point_position | | | position(..)|
| | geoshape | blueline | GPS Coordinates | yes | |
| | end repeat |
"""
self.xform = self._publish_markdown(
md, self.user, self.project, id_string="geoshapes")
# publish submissions
self._publish_submit_geoms_in_repeats("Geoshapes")
view = DataViewSet.as_view({"get": "list"})
request = self.factory.get("/", **self.extra)
response = view(request, pk=self.xform.pk, format="geojson")
Expand Down
Binary file not shown.
Binary file not shown.
49 changes: 2 additions & 47 deletions onadata/apps/main/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,52 +427,7 @@ def _publish_submit_geojson(self, has_empty_geoms=False, only_geopoints=False):
response = view(request, pk=self.xform.id)
self.assertEqual(response.status_code, 200)

def _publish_submit_geotraces_in_repeats(self):
path = os.path.join(
settings.PROJECT_ROOT,
"apps",
"main",
"tests",
"fixtures",
"geolocation",
"Geotraces.xlsx",
)

self._publish_xls_file_and_set_xform(path)


view = XFormViewSet.as_view({"post": "csv_import"})
with open(
os.path.join(
settings.PROJECT_ROOT,
"apps",
"main",
"tests",
"fixtures",
"geolocation",
"Geotraces.csv",
),
encoding="utf-8",
) as csv_import:
post_data = {"csv_file": csv_import}
request = self.factory.post("/", data=post_data, **self.extra)
response = view(request, pk=self.xform.id)
self.assertEqual(response.status_code, 200)

def _publish_submit_geoshapes_in_repeats(self):
path = os.path.join(
settings.PROJECT_ROOT,
"apps",
"main",
"tests",
"fixtures",
"geolocation",
"Geoshapes.xlsx",
)

self._publish_xls_file_and_set_xform(path)


def _publish_submit_geoms_in_repeats(self, geom_type):
view = XFormViewSet.as_view({"post": "csv_import"})
with open(
os.path.join(
Expand All @@ -482,7 +437,7 @@ def _publish_submit_geoshapes_in_repeats(self):
"tests",
"fixtures",
"geolocation",
"Geoshapes.csv",
f"{geom_type}.csv",
),
encoding="utf-8",
) as csv_import:
Expand Down

0 comments on commit ae05995

Please sign in to comment.