Skip to content

Commit a3f3187

Browse files
committed
tests
1 parent d62eb6e commit a3f3187

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

tests/src/python/test_qgsvectorlayerutils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,25 +272,25 @@ def testCreateFeature(self):
272272
# test with violated unique constraints
273273
layer.setFieldConstraint(1, QgsFieldConstraints.ConstraintUnique)
274274
f = QgsVectorLayerUtils.createFeature(layer, attributes={0: 'test_1', 1: 123})
275-
# since field 1 has Unique Constraint, it ignores value 123 that already has been set
276-
self.assertEqual(f.attributes(), ['test_1', NULL, NULL])
275+
# since field 1 has Unique Constraint, it ignores value 123 that already has been set and sets to 128
276+
self.assertEqual(f.attributes(), ['test_1', 128, NULL])
277277
layer.setFieldConstraint(0, QgsFieldConstraints.ConstraintUnique)
278278
# since field 0 and 1 already have values test_1 and 123, the output must be null
279279
f = QgsVectorLayerUtils.createFeature(layer, attributes={0: 'test_1', 1: 123})
280-
self.assertEqual(f.attributes(), [NULL, NULL, NULL])
280+
self.assertEqual(f.attributes(), ['test_4', 128, NULL])
281281

282282
# test with violated unique constraints and default value expression providing unique value
283283
layer.setDefaultValueDefinition(1, QgsDefaultValue('130'))
284284
f = QgsVectorLayerUtils.createFeature(layer, attributes={0: 'test_1', 1: 123})
285285
# since field 1 has Unique Constraint, it ignores value 123 that already has been set and adds the default value
286-
self.assertEqual(f.attributes(), [NULL, 130, NULL])
286+
self.assertEqual(f.attributes(), ['test_4', 130, NULL])
287287
# fallback: test with violated unique constraints and default value expression providing already existing value
288288
# add the feature with the default value:
289289
self.assertTrue(layer.dataProvider().addFeatures([f]))
290-
f = QgsVectorLayerUtils.createFeature(layer, attributes={0: 'test_2', 1: 123})
290+
f = QgsVectorLayerUtils.createFeature(layer, attributes={0: 'test_1', 1: 123})
291291
# since field 1 has Unique Constraint, it ignores value 123 that already has been set and adds the default value
292292
# and since the default value providing an already existing value (130) it generates a unique value (next int: 131)
293-
self.assertEqual(f.attributes(), [NULL, 131, NULL])
293+
self.assertEqual(f.attributes(), ['test_5', 131, NULL])
294294
layer.setDefaultValueDefinition(1, QgsDefaultValue(None))
295295

296296
def testDuplicateFeature(self):

0 commit comments

Comments
 (0)