summaryrefslogtreecommitdiff
path: root/tests/gis_tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2021-05-13 12:13:37 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-05-13 13:13:12 +0200
commitc6d88a18726118c694b6ac4c308642efbe84c151 (patch)
treeebe2d8489a56b6c7066d32022524d1005f5bc785 /tests/gis_tests
parent820408d842a07202a80e6ef7f7a57ec6258d88e6 (diff)
downloaddjango-c6d88a18726118c694b6ac4c308642efbe84c151.tar.gz
Refs #16455 -- Added test for using opclasses on indexes for multidimensional geometry fields on PostGIS.
Diffstat (limited to 'tests/gis_tests')
-rw-r--r--tests/gis_tests/gis_migrations/test_operations.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/gis_tests/gis_migrations/test_operations.py b/tests/gis_tests/gis_migrations/test_operations.py
index eb8640191a..25d55619ed 100644
--- a/tests/gis_tests/gis_migrations/test_operations.py
+++ b/tests/gis_tests/gis_migrations/test_operations.py
@@ -19,6 +19,12 @@ except NotImplementedError:
class OperationTestCase(TransactionTestCase):
available_apps = ['gis_tests.gis_migrations']
+ get_opclass_query = '''
+ SELECT opcname, c.relname FROM pg_opclass AS oc
+ JOIN pg_index as i on oc.oid = ANY(i.indclass)
+ JOIN pg_class as c on c.oid = i.indexrelid
+ WHERE c.relname = %s
+ '''
def tearDown(self):
# Delete table after testing
@@ -188,6 +194,29 @@ class OperationTests(OperationTestCase):
if connection.features.supports_raster:
self.assertSpatialIndexExists('gis_neighborhood', 'rast', raster=True)
+ @skipUnlessDBFeature('supports_3d_storage')
+ def test_add_3d_field_opclass(self):
+ if not connection.ops.postgis:
+ self.skipTest('PostGIS-specific test.')
+
+ self.alter_gis_model(
+ migrations.AddField,
+ 'Neighborhood',
+ 'point3d',
+ field_class=fields.PointField,
+ field_class_kwargs={'dim': 3},
+ )
+ self.assertColumnExists('gis_neighborhood', 'point3d')
+ self.assertSpatialIndexExists('gis_neighborhood', 'point3d')
+
+ with connection.cursor() as cursor:
+ index_name = 'gis_neighborhood_point3d_id'
+ cursor.execute(self.get_opclass_query, [index_name])
+ self.assertEqual(
+ cursor.fetchall(),
+ [('gist_geometry_ops_nd', index_name)],
+ )
+
@skipUnlessDBFeature('can_alter_geometry_field', 'supports_3d_storage')
def test_alter_geom_field_dim(self):
Neighborhood = self.current_state.apps.get_model('gis', 'Neighborhood')