Skip to content

Commit

Permalink
Simplified OperationTestCase.alter_gis_model() test hook a bit.
Browse files Browse the repository at this point in the history
This avoids passing "blank=False" and "srid=4326" to field classes,
which are the default values, and removes special treatment for the
"blank" parameter.
  • Loading branch information
felixxm authored and sarahboyce committed Jun 18, 2024
1 parent 1b21fee commit a0c44d4
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions tests/gis_tests/gis_migrations/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,12 @@ def alter_gis_model(
migration_class,
model_name,
field_name,
blank=False,
field_class=None,
field_class_kwargs=None,
):
args = [model_name, field_name]
if field_class:
field_class_kwargs = field_class_kwargs or {"srid": 4326, "blank": blank}
field_class_kwargs = field_class_kwargs or {}
args.append(field_class(**field_class_kwargs))
operation = migration_class(*args)
old_state = self.current_state.clone()
Expand All @@ -122,7 +121,7 @@ def test_add_geom_field(self):
Test the AddField operation with a geometry-enabled column.
"""
self.alter_gis_model(
migrations.AddField, "Neighborhood", "path", False, fields.LineStringField
migrations.AddField, "Neighborhood", "path", fields.LineStringField
)
self.assertColumnExists("gis_neighborhood", "path")

Expand All @@ -147,7 +146,7 @@ def test_add_raster_field(self):
Test the AddField operation with a raster-enabled column.
"""
self.alter_gis_model(
migrations.AddField, "Neighborhood", "heatmap", False, fields.RasterField
migrations.AddField, "Neighborhood", "heatmap", fields.RasterField
)
self.assertColumnExists("gis_neighborhood", "heatmap")

Expand All @@ -160,7 +159,11 @@ def test_add_blank_geom_field(self):
Should be able to add a GeometryField with blank=True.
"""
self.alter_gis_model(
migrations.AddField, "Neighborhood", "path", True, fields.LineStringField
migrations.AddField,
"Neighborhood",
"path",
fields.LineStringField,
field_class_kwargs={"blank": True},
)
self.assertColumnExists("gis_neighborhood", "path")

Expand All @@ -178,7 +181,11 @@ def test_add_blank_raster_field(self):
Should be able to add a RasterField with blank=True.
"""
self.alter_gis_model(
migrations.AddField, "Neighborhood", "heatmap", True, fields.RasterField
migrations.AddField,
"Neighborhood",
"heatmap",
fields.RasterField,
field_class_kwargs={"blank": True},
)
self.assertColumnExists("gis_neighborhood", "heatmap")

Expand Down Expand Up @@ -247,19 +254,17 @@ def test_alter_geom_field_dim(self):
migrations.AlterField,
"Neighborhood",
"geom",
False,
fields.MultiPolygonField,
field_class_kwargs={"srid": 4326, "dim": 3},
field_class_kwargs={"dim": 3},
)
self.assertTrue(Neighborhood.objects.first().geom.hasz)
# Rewind to 2 dimensions.
self.alter_gis_model(
migrations.AlterField,
"Neighborhood",
"geom",
False,
fields.MultiPolygonField,
field_class_kwargs={"srid": 4326, "dim": 2},
field_class_kwargs={"dim": 2},
)
self.assertFalse(Neighborhood.objects.first().geom.hasz)

Expand Down Expand Up @@ -296,9 +301,5 @@ def test_add_raster_field_on_db_without_raster_support(self):
with self.assertRaisesMessage(ImproperlyConfigured, msg):
self.set_up_test_model()
self.alter_gis_model(
migrations.AddField,
"Neighborhood",
"heatmap",
False,
fields.RasterField,
migrations.AddField, "Neighborhood", "heatmap", fields.RasterField
)

0 comments on commit a0c44d4

Please sign in to comment.