mirror of
				https://github.com/django/django.git
				synced 2025-10-30 17:16:10 +00:00 
			
		
		
		
	Refs #16455 -- Added test for using opclasses on indexes for multidimensional geometry fields on PostGIS.
This commit is contained in:
		| @@ -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') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user