예제 #1
0
    def test_add_gis_field(self):
        """
        Tests the AddField operation with a GIS-enabled column.
        """
        project_state = self.set_up_test_model()
        operation = migrations.AddField(
            "Neighborhood",
            "path",
            fields.LineStringField(srid=4326),
        )
        new_state = project_state.clone()
        operation.state_forwards("gis", new_state)
        with connection.schema_editor() as editor:
            operation.database_forwards("gis", editor, project_state, new_state)
        self.current_state = new_state
        self.assertColumnExists("gis_neighborhood", "path")

        # Test GeometryColumns when available
        if HAS_GEOMETRY_COLUMNS:
            self.assertGeometryColumnsCount(2)

        if self.has_spatial_indexes:
            with connection.cursor() as cursor:
                indexes = connection.introspection.get_indexes(cursor, "gis_neighborhood")
            self.assertIn('path', indexes)
예제 #2
0
    def test_add_gis_field(self):
        """
        Tests the AddField operation with a GIS-enabled column.
        """
        project_state = self.set_up_test_model()
        operation = migrations.AddField(
            "Neighborhood",
            "path",
            fields.LineStringField(srid=4326, null=True, blank=True),
        )
        new_state = project_state.clone()
        operation.state_forwards("gis", new_state)
        with connection.schema_editor() as editor:
            operation.database_forwards("gis", editor, project_state,
                                        new_state)
        self.assertColumnExists("gis_neighborhood", "path")

        # Test GeometryColumns when available
        if HAS_GEOMETRY_COLUMNS:
            self.assertEqual(
                GeometryColumns.objects.filter(
                    **{
                        GeometryColumns.table_name_col(): "gis_neighborhood"
                    }).count(), 2)
        self.current_state = new_state