summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2024-06-08 10:19:55 +0200
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-06-20 11:53:25 +0200
commit4e04c99d1803826f416c302e7938ae169ff847ea (patch)
tree90d85cad7049757e7baff3efa51d207279876941
parentadb72fa85423eba238d472a8abfbb65bbc2132d5 (diff)
[5.1.x] Simplified OperationTestCase.alter_gis_model() test hook a bit.
This avoids passing "blank=False" and "srid=4326" to field classes, which are the default values, and removes special treatment for the "blank" parameter. Backport of a0c44d4e23f8f509757f97f28fbbb1ced3382361 from main.
-rw-r--r--tests/gis_tests/gis_migrations/test_operations.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/tests/gis_tests/gis_migrations/test_operations.py b/tests/gis_tests/gis_migrations/test_operations.py
index 92d542dbb2..3ecde2025e 100644
--- a/tests/gis_tests/gis_migrations/test_operations.py
+++ b/tests/gis_tests/gis_migrations/test_operations.py
@@ -97,13 +97,12 @@ class OperationTestCase(TransactionTestCase):
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()
@@ -122,7 +121,7 @@ class OperationTests(OperationTestCase):
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")
@@ -165,7 +164,7 @@ class OperationTests(OperationTestCase):
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")
@@ -178,7 +177,11 @@ class OperationTests(OperationTestCase):
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")
@@ -196,7 +199,11 @@ class OperationTests(OperationTestCase):
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")
@@ -265,9 +272,8 @@ class OperationTests(OperationTestCase):
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.
@@ -275,9 +281,8 @@ class OperationTests(OperationTestCase):
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)
@@ -314,9 +319,5 @@ class NoRasterSupportTests(OperationTestCase):
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
)