Skip to content

Commit

Permalink
Flaky tests - string encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
ukanga committed Apr 5, 2024
1 parent 5a0e3a7 commit 8cd8c57
Showing 1 changed file with 42 additions and 39 deletions.
81 changes: 42 additions & 39 deletions onadata/libs/tests/utils/test_export_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ def _logger_fixture_path(*args):
)


def _str_if_bytes(val):
"""Returns val as string if it is of type bytes otherwise returns bytes"""
return str(val, "utf-8") if isinstance(val, bytes) else val


class TestExportBuilder(TestBase):
"""Test onadata.libs.utils.export_builder functions."""

Expand Down Expand Up @@ -2904,46 +2909,44 @@ def test_zipped_sav_has_submission_review_fields(self):
with SavReader(os.path.join(temp_dir, "osm.sav"), returnHeader=True) as reader:
rows = list(reader)
expected_column_headers = [
x.encode("utf-8")
for x in [
"photo",
"osm_road",
"osm_building",
"fav_color",
"form_completed",
"meta.instanceID",
"@_id",
"@_uuid",
"@_submission_time",
"@_index",
"@_parent_table_name",
"@_review_comment",
f"@{REVIEW_DATE}",
"@_review_status",
"@_parent_index",
"@_tags",
"@_notes",
"@_version",
"@_duration",
"@_submitted_by",
"osm_road_ctr_lat",
"osm_road_ctr_lon",
"osm_road_highway",
"osm_road_lanes",
"osm_road_name",
"osm_road_way_id",
"osm_building_building",
"osm_building_building_levels",
"osm_building_ctr_lat",
"osm_building_ctr_lon",
"osm_building_name",
"osm_building_way_id",
]
"photo",
"osm_road",
"osm_building",
"fav_color",
"form_completed",
"meta.instanceID",
"@_id",
"@_uuid",
"@_submission_time",
"@_index",
"@_parent_table_name",
"@_review_comment",
f"@{REVIEW_DATE}",
"@_review_status",
"@_parent_index",
"@_tags",
"@_notes",
"@_version",
"@_duration",
"@_submitted_by",
"osm_road_ctr_lat",
"osm_road_ctr_lon",
"osm_road_highway",
"osm_road_lanes",
"osm_road_name",
"osm_road_way_id",
"osm_building_building",
"osm_building_building_levels",
"osm_building_ctr_lat",
"osm_building_ctr_lon",
"osm_building_name",
"osm_building_way_id",
]
self.assertEqual(sorted(rows[0]), sorted(expected_column_headers))
self.assertEqual(rows[1][29], b"Rejected")
self.assertEqual(rows[1][30], b"Wrong Location")
self.assertEqual(rows[1][31], b"2021-05-25T02:27:19")
actual_headers = list(map(_str_if_bytes, rows[0]))
self.assertEqual(sorted(actual_headers), sorted(expected_column_headers))
self.assertEqual(_str_if_bytes(rows[1][29]), "Rejected")
self.assertEqual(_str_if_bytes(rows[1][30]), "Wrong Location")
self.assertEqual(_str_if_bytes(rows[1][31]), "2021-05-25T02:27:19")

# pylint: disable=invalid-name
def test_zipped_csv_export_with_osm_data(self):
Expand Down

0 comments on commit 8cd8c57

Please sign in to comment.