Skip to content

Commit

Permalink
Add provider test for adding feature with all null attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 11, 2025
1 parent fedd040 commit dd11d8a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/src/python/providertestbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,44 @@ def testAddFeatureExtraAttributes(self):
],
)

def testAddFeatureAllNull(self):
if not getattr(self, "getEditableLayer", None):
return

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

f1 = QgsFeature()
f1.setAttributes([NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL])
f1.setGeometry(QgsGeometry.fromWkt("Point (-72.345 71.987)"))

if (
l.dataProvider().capabilities()
& QgsVectorDataProvider.Capability.AddFeatures
):
# expect success
result, added = l.dataProvider().addFeatures([f1])
self.assertTrue(
result,
"Provider reported AddFeatures capability, but returned False to addFeatures",
)

# check result
f_new = next(
l.dataProvider().getFeatures(
QgsFeatureRequest().setFilterFid(added[0].id())
)
)
self.assertEqual(
f_new.attributes()[1:], [NULL, NULL, NULL, NULL, NULL, NULL, NULL]
)
else:
# expect fail
self.assertFalse(
l.dataProvider().addFeatures([f1]),
"Provider reported no AddFeatures capability, but returned true to addFeatures",
)

def testAddFeatureWrongGeomType(self):
if not getattr(self, "getEditableLayer", None):
return
Expand Down

0 comments on commit dd11d8a

Please sign in to comment.