Skip to content
Permalink
Browse files

Add tests for editing filtered gpkg layer

  • Loading branch information
m-kuhn authored and rouault committed Oct 18, 2018
1 parent 391ec8a commit 6745eecd1d04874c5d42dd4dd7baf9c3929e58b3
Showing with 45 additions and 0 deletions.
  1. +45 −0 tests/src/python/test_provider_ogr_gpkg.py
@@ -318,6 +318,51 @@ def testSelectSubsetString(self):
got = [feat for feat in vl.getFeatures(QgsFeatureRequest(1))]
self.assertEqual(len(got), 1) # this is the current behavior, broken

def testEditSubsetString(self):

tmpfile = os.path.join(self.basetestpath, 'testEditSubsetString.gpkg')
ds = ogr.GetDriverByName('GPKG').CreateDataSource(tmpfile)
lyr = ds.CreateLayer('test', geom_type=ogr.wkbMultiPolygon)
lyr.CreateField(ogr.FieldDefn('foo', ogr.OFTString))
f = ogr.Feature(lyr.GetLayerDefn())
f['foo'] = 'bar'
lyr.CreateFeature(f)
f = None
f = ogr.Feature(lyr.GetLayerDefn())
f['foo'] = 'baz'
lyr.CreateFeature(f)
f = None
ds = None

vl = QgsVectorLayer('{}|layerid=0'.format(tmpfile), 'test', 'ogr')
self.assertEqual(vl.dataProvider().featureCount(), 2)

# Test adding features
vl.setSubsetString("foo = 'baz'")
self.assertTrue(vl.startEditing())
feature = QgsFeature(vl.fields())
feature['foo'] = 'abc'
vl.addFeature(feature)
vl.commitChanges()
vl.setSubsetString(None)
self.assertEqual(vl.dataProvider().featureCount(), 3)

# Test deleting a feature
vl.setSubsetString("foo = 'baz'")
self.assertTrue(vl.startEditing())
vl.deleteFeature(1)
vl.commitChanges()
vl.setSubsetString(None)
self.assertEqual(vl.dataProvider().featureCount(), 2)

# Test editing a feature
vl.setSubsetString("foo = 'baz'")
self.assertTrue(vl.startEditing())
vl.changeAttributeValue(2, 1, 'xx')
vl.commitChanges()
vl.setSubsetString(None)
self.assertEqual(set((feat['foo'] for feat in vl.getFeatures())), set(['xx', 'abc']))

def testStyle(self):

# First test with invalid URI

0 comments on commit 6745eec

Please sign in to comment.
You can’t perform that action at this time.