Skip to content

Commit

Permalink
Refactor using assertLayerData method to perform layer data checks
Browse files Browse the repository at this point in the history
  • Loading branch information
gounux committed Jan 7, 2025
1 parent cf15480 commit 2e187bc
Showing 1 changed file with 51 additions and 43 deletions.
94 changes: 51 additions & 43 deletions docker-app/qfieldcloud/core/tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,28 @@ def test_bad_layer_handler_values_for_process_projectfile_job(self):
)["returns"]["project_details"]["layers_by_id"]

# "valid" localized layer -> QFC considers it as invalid
valid_localized_layer = processfile_layers["valid_localized_point_layer_id"]

self.assertFalse(valid_localized_layer["is_valid"])
self.assertTrue(valid_localized_layer["is_localized"])
self.assertLayerData(
processfile_layers["valid_localized_point_layer_id"],
is_valid=False,
is_localized=True,
error_code="localized_dataprovider",
)

# invalid localized layer
invalid_localized_layer = processfile_layers[
"invalid_localized_polygon_layer_id"
]

self.assertFalse(invalid_localized_layer["is_valid"])
self.assertTrue(invalid_localized_layer["is_localized"])
self.assertEquals(
invalid_localized_layer["error_code"], "localized_dataprovider"
self.assertLayerData(
processfile_layers["invalid_localized_polygon_layer_id"],
is_valid=False,
is_localized=True,
error_code="localized_dataprovider",
)

# invalid layer (datasource does not exist)
invalid_layer = processfile_layers["invalid_point_layer_id"]

self.assertFalse(invalid_layer["is_valid"])
self.assertFalse(invalid_layer["is_localized"])
self.assertEquals(invalid_layer["error_code"], "invalid_dataprovider")
self.assertLayerData(
processfile_layers["invalid_point_layer_id"],
is_valid=False,
is_localized=False,
error_code="invalid_dataprovider",
)

def test_bad_layer_handler_values_for_package_job(self):
# Test that BadLayerHandler is parsing data properly during package jobs
Expand Down Expand Up @@ -161,43 +161,51 @@ def test_bad_layer_handler_values_for_package_job(self):
]["layers_by_id"]

# "valid" localized layer -> QFC considers it as invalid (QGIS)
valid_localized_qgis_layer = qgis_layers["valid_localized_point_layer_id"]

self.assertFalse(valid_localized_qgis_layer["is_valid"])
self.assertTrue(valid_localized_qgis_layer["is_localized"])
self.assertLayerData(
qgis_layers["valid_localized_point_layer_id"],
is_valid=False,
is_localized=True,
error_code="localized_dataprovider",
)

# invalid localized layer (QGIS)
invalid_localized_qgis_layer = qgis_layers["invalid_localized_polygon_layer_id"]

self.assertFalse(invalid_localized_qgis_layer["is_valid"])
self.assertTrue(invalid_localized_qgis_layer["is_localized"])
self.assertEquals(
invalid_localized_qgis_layer["error_code"], "localized_dataprovider"
self.assertLayerData(
qgis_layers["invalid_localized_polygon_layer_id"],
is_valid=False,
is_localized=True,
error_code="localized_dataprovider",
)

# "valid" localized layer -> QFC considers it as invalid (QField)
valid_localized_qfield_layer = qfield_layers["valid_localized_point_layer_id"]

self.assertFalse(valid_localized_qfield_layer["is_valid"])
self.assertTrue(valid_localized_qfield_layer["is_localized"])
self.assertLayerData(
qfield_layers["valid_localized_point_layer_id"],
is_valid=False,
is_localized=True,
error_code="localized_dataprovider",
)

# invalid localized layer (QField)
invalid_localized_qfield_layer = qfield_layers[
"invalid_localized_polygon_layer_id"
]

self.assertFalse(invalid_localized_qfield_layer["is_valid"])
self.assertTrue(invalid_localized_qfield_layer["is_localized"])
self.assertEquals(
invalid_localized_qfield_layer["error_code"], "localized_dataprovider"
self.assertLayerData(
qfield_layers["invalid_localized_polygon_layer_id"],
is_valid=False,
is_localized=True,
error_code="localized_dataprovider",
)

# invalid layer is not present in qfield layers
self.assertNotIn("invalid_point_layer_id", qfield_layers)

# invalid layer (datasource does not exist) (QGIS)
invalid_layer = qgis_layers["invalid_point_layer_id"]
self.assertLayerData(
qgis_layers["invalid_point_layer_id"],
is_valid=False,
is_localized=False,
error_code="invalid_dataprovider",
)

self.assertFalse(invalid_layer["is_valid"])
self.assertFalse(invalid_layer["is_localized"])
self.assertEquals(invalid_layer["error_code"], "invalid_dataprovider")
def assertLayerData(
self, layer_data: dict, is_valid: bool, is_localized: bool, error_code: str
) -> None:
self.assertEquals(layer_data["is_valid"], is_valid)
self.assertEquals(layer_data["is_localized"], is_localized)
self.assertEquals(layer_data["error_code"], error_code)

0 comments on commit 2e187bc

Please sign in to comment.