mirror of
https://github.com/django/django.git
synced 2025-03-14 03:10:45 +00:00
[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.
This commit is contained in:
parent
adb72fa854
commit
4e04c99d18
@ -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
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user