Skip to content
Permalink
Browse files
Add test for live value update
  • Loading branch information
m-kuhn authored and github-actions committed Nov 24, 2021
1 parent f808b6c commit cf9d22e1f2207c5e043623fdaf783fd4a2882b36
Showing with 28 additions and 1 deletion.
  1. +1 −0 tests/Testing/Temporary/CTestCostData.txt
  2. +27 −1 tests/src/python/test_qgsattributeform.py
@@ -0,0 +1 @@
---
@@ -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()

@@ -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 cf9d22e

Please sign in to comment.