1
0
mirror of https://github.com/django/django.git synced 2025-01-05 07:55:47 +00:00

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.
This commit is contained in:
Mariusz Felisiak 2024-06-08 10:19:55 +02:00 committed by Sarah Boyce
parent 1b21feeb7b
commit a0c44d4e23

View File

@ -97,13 +97,12 @@ class OperationTestCase(TransactionTestCase):
migration_class, migration_class,
model_name, model_name,
field_name, field_name,
blank=False,
field_class=None, field_class=None,
field_class_kwargs=None, field_class_kwargs=None,
): ):
args = [model_name, field_name] args = [model_name, field_name]
if field_class: 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)) args.append(field_class(**field_class_kwargs))
operation = migration_class(*args) operation = migration_class(*args)
old_state = self.current_state.clone() old_state = self.current_state.clone()
@ -122,7 +121,7 @@ class OperationTests(OperationTestCase):
Test the AddField operation with a geometry-enabled column. Test the AddField operation with a geometry-enabled column.
""" """
self.alter_gis_model( self.alter_gis_model(
migrations.AddField, "Neighborhood", "path", False, fields.LineStringField migrations.AddField, "Neighborhood", "path", fields.LineStringField
) )
self.assertColumnExists("gis_neighborhood", "path") self.assertColumnExists("gis_neighborhood", "path")
@ -147,7 +146,7 @@ class OperationTests(OperationTestCase):
Test the AddField operation with a raster-enabled column. Test the AddField operation with a raster-enabled column.
""" """
self.alter_gis_model( self.alter_gis_model(
migrations.AddField, "Neighborhood", "heatmap", False, fields.RasterField migrations.AddField, "Neighborhood", "heatmap", fields.RasterField
) )
self.assertColumnExists("gis_neighborhood", "heatmap") self.assertColumnExists("gis_neighborhood", "heatmap")
@ -160,7 +159,11 @@ class OperationTests(OperationTestCase):
Should be able to add a GeometryField with blank=True. Should be able to add a GeometryField with blank=True.
""" """
self.alter_gis_model( 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") self.assertColumnExists("gis_neighborhood", "path")
@ -178,7 +181,11 @@ class OperationTests(OperationTestCase):
Should be able to add a RasterField with blank=True. Should be able to add a RasterField with blank=True.
""" """
self.alter_gis_model( 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") self.assertColumnExists("gis_neighborhood", "heatmap")
@ -247,9 +254,8 @@ class OperationTests(OperationTestCase):
migrations.AlterField, migrations.AlterField,
"Neighborhood", "Neighborhood",
"geom", "geom",
False,
fields.MultiPolygonField, fields.MultiPolygonField,
field_class_kwargs={"srid": 4326, "dim": 3}, field_class_kwargs={"dim": 3},
) )
self.assertTrue(Neighborhood.objects.first().geom.hasz) self.assertTrue(Neighborhood.objects.first().geom.hasz)
# Rewind to 2 dimensions. # Rewind to 2 dimensions.
@ -257,9 +263,8 @@ class OperationTests(OperationTestCase):
migrations.AlterField, migrations.AlterField,
"Neighborhood", "Neighborhood",
"geom", "geom",
False,
fields.MultiPolygonField, fields.MultiPolygonField,
field_class_kwargs={"srid": 4326, "dim": 2}, field_class_kwargs={"dim": 2},
) )
self.assertFalse(Neighborhood.objects.first().geom.hasz) self.assertFalse(Neighborhood.objects.first().geom.hasz)
@ -296,9 +301,5 @@ class NoRasterSupportTests(OperationTestCase):
with self.assertRaisesMessage(ImproperlyConfigured, msg): with self.assertRaisesMessage(ImproperlyConfigured, msg):
self.set_up_test_model() self.set_up_test_model()
self.alter_gis_model( self.alter_gis_model(
migrations.AddField, migrations.AddField, "Neighborhood", "heatmap", fields.RasterField
"Neighborhood",
"heatmap",
False,
fields.RasterField,
) )