Skip to content

Commit

Permalink
Add test for live value update
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Nov 23, 2021
1 parent 6e74561 commit c1b8722
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/Testing/Temporary/CTestCostData.txt
@@ -0,0 +1 @@
---
28 changes: 27 additions & 1 deletion tests/src/python/test_qgsattributeform.py
Expand Up @@ -22,13 +22,17 @@
QgsEditorWidgetSetup,
QgsEditFormConfig,
QgsAttributeEditorElement,
QgsDefaultValue,
QgsField
)
from qgis.gui import (
QgsAttributeForm,
QgsGui,
QgsEditorWidgetWrapper,
QgsMapCanvas
QgsMapCanvas,
QgsAttributeEditorContext
)
from qgis.PyQt.QtCore import QVariant

QGISAPP = start_app()

Expand Down Expand Up @@ -115,6 +119,28 @@ def test_duplicated_widgets(self):
for field_type, value in field_types.items():
self.checkForm(field_type, value)

def test_on_update(self):
"""Test live update"""

layer = QgsVectorLayer("Point?field=age:int", "vl", "memory")
# set default value for numbers to [1, {age}], it will depend on the field age and should update
field = QgsField('numbers', QVariant.List, 'array')
field.setEditorWidgetSetup(QgsEditorWidgetSetup('List', {}))
layer.dataProvider().addAttributes([field])
layer.updateFields()
layer.setDefaultValueDefinition(1, QgsDefaultValue('array(1, age)', True))
layer.setEditorWidgetSetup(1, QgsEditorWidgetSetup('List', {}))
layer.startEditing()
form = QgsAttributeForm(layer)
feature = QgsFeature(layer.fields())
form.setFeature(feature)
form.setMode(QgsAttributeEditorContext.AddFeatureMode)
form.changeAttribute('numbers', [12])
form.changeAttribute('age', 1)
self.assertEqual(form.currentFormFeature()['numbers'], [1, 1])
form.changeAttribute('age', 7)
self.assertEqual(form.currentFormFeature()['numbers'], [1, 7])


if __name__ == '__main__':
unittest.main()

0 comments on commit c1b8722

Please sign in to comment.