Skip to content
Permalink
Browse files

Add a provider unit test checking extent after adding/deleting features

  • Loading branch information
nyalldawson authored and m-kuhn committed Jun 11, 2017
1 parent 6a87889 commit 10341310c2f435db9cc28e28bc601db1cc00e482
Showing with 35 additions and 0 deletions.
  1. +35 −0 tests/src/python/providertestbase.py
@@ -361,6 +361,24 @@ def testAddFeature(self):
# expect fail
self.assertFalse(l.dataProvider().addFeatures([f1, f2]), 'Provider reported no AddFeatures capability, but returned true to addFeatures')

def testAddFeaturesUpdateExtent(self):
if not getattr(self, 'getEditableLayer', None):
return

l = self.getEditableLayer()
self.assertTrue(l.isValid())

self.assertEqual(l.dataProvider().extent().toString(1), '-71.1,66.3 : -65.3,78.3')

if l.dataProvider().capabilities() & QgsVectorDataProvider.AddFeatures:
f1 = QgsFeature()
f1.setAttributes([6, -220, NULL, 'String', '15'])
f1.setGeometry(QgsGeometry.fromWkt('Point (-50 90)'))
l.dataProvider().addFeatures([f1])

l.dataProvider().updateExtents()
self.assertEqual(l.dataProvider().extent().toString(1), '-71.1,66.3 : -50.0,90.0')

def testDeleteFeatures(self):
if not getattr(self, 'getEditableLayer', None):
return
@@ -388,6 +406,23 @@ def testDeleteFeatures(self):
self.assertFalse(l.dataProvider().deleteFeatures(to_delete),
'Provider reported no DeleteFeatures capability, but returned true to deleteFeatures')

def testDeleteFeaturesUpdateExtent(self):
if not getattr(self, 'getEditableLayer', None):
return

l = self.getEditableLayer()
self.assertTrue(l.isValid())

self.assertEqual(l.dataProvider().extent().toString(1), '-71.1,66.3 : -65.3,78.3')

to_delete = [f.id() for f in l.dataProvider().getFeatures() if f.attributes()[0] in [5, 4]]

if l.dataProvider().capabilities() & QgsVectorDataProvider.DeleteFeatures:
l.dataProvider().deleteFeatures(to_delete)

l.dataProvider().updateExtents()
self.assertEqual(l.dataProvider().extent().toString(1), '-70.3,66.3 : -68.2,70.8')

def testTruncate(self):
if not getattr(self, 'getEditableLayer', None):
return

0 comments on commit 1034131

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