Skip to content

Commit

Permalink
Add more applyOnUpdate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Sep 29, 2017
1 parent 1552b4e commit 366433e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/src/python/test_qgsvectorlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,7 @@ def testApplyOnUpdateDefaultExpressions(self):
feature.setFields(layer.fields())
feature.setValid(True)

# Both default values should be set on feature create
feature.setAttribute(1, layer.defaultValue(1, feature))
feature.setAttribute(0, layer.defaultValue(0, feature))

Expand All @@ -2111,10 +2112,23 @@ def testApplyOnUpdateDefaultExpressions(self):
self.assertEqual(layer.getFeature(fid)['fldtxt'], 'l: 4,f: 4')
self.assertEqual(layer.getFeature(fid)['fldint'], 4)

# ApplyOnUpdateDefaultValue should be set on changeAttributeValue
layer.changeAttributeValue(fid, 1, 20)
self.assertEqual(layer.getFeature(fid)['fldtxt'], 'l: 4,f: 20')
self.assertEqual(layer.getFeature(fid)['fldint'], 20)

# When changing the value of the "derived" attribute, only this one
# should be updated
QgsExpressionContextUtils.setLayerVariable(layer, 'number', 8)
layer.changeAttributeValue(fid, 0, 0)
self.assertEqual(layer.getFeature(fid)['fldtxt'], 'l: 8,f: 20')
self.assertEqual(layer.getFeature(fid)['fldint'], 20)

# Check update on geometry change
layer.setDefaultValueDefinition(1, QgsDefaultValue("x($geometry)", True))
layer.changeGeometry(fid, QgsGeometry.fromPoint(QgsPointXY(300, 200)))
self.assertEqual(layer.getFeature(fid)['fldint'], 300)

def testGetSetConstraints(self):
""" test getting and setting field constraints """
layer = createLayerWithOnePoint()
Expand Down

0 comments on commit 366433e

Please sign in to comment.