Skip to content
Permalink
Browse files

Add test for enabled state of relation value widget

  • Loading branch information
m-kuhn committed Dec 12, 2017
1 parent 167fbf6 commit 46a74a090a9dd566ae9cd029cf19cbf15a99df43
Showing with 30 additions and 10 deletions.
  1. +30 −10 tests/src/python/test_qgseditwidgets.py
@@ -26,8 +26,6 @@

class TestQgsTextEditWidget(unittest.TestCase):

VALUEMAP_NULL_TEXT = "{2839923C-8B7D-419E-B84B-CA2FE9B80EC7}"

@classmethod
def setUpClass(cls):
QgsGui.editorWidgetRegistry().initEditors()
@@ -39,8 +37,8 @@ def createLayerWithOnePoint(self):
f = QgsFeature()
f.setAttributes(["test", 123])
f.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(100, 200)))
assert pr.addFeatures([f])
assert self.layer.pendingFeatureCount() == 1
self.assertTrue(pr.addFeatures([f]))
self.assertEqual(self.layer.pendingFeatureCount(), 1)
return self.layer

def doAttributeTest(self, idx, expected):
@@ -50,16 +48,16 @@ def doAttributeTest(self, idx, expected):
editwidget = reg.create('TextEdit', self.layer, idx, config, None, None)

editwidget.setValue('value')
assert editwidget.value() == expected[0]
self.assertEqual(editwidget.value(), expected[0])

editwidget.setValue(123)
assert editwidget.value() == expected[1]
self.assertEqual(editwidget.value(), expected[1])

editwidget.setValue(None)
assert editwidget.value() == expected[2]
self.assertEqual(editwidget.value(), expected[2])

editwidget.setValue(NULL)
assert editwidget.value() == expected[3]
self.assertEqual(editwidget.value(), expected[3])

def test_SetValue(self):
self.createLayerWithOnePoint()
@@ -70,7 +68,7 @@ def test_SetValue(self):
def testStringWithMaxLen(self):
""" tests that text edit wrappers correctly handle string fields with a maximum length """
layer = QgsVectorLayer("none?field=fldint:integer", "layer", "memory")
assert layer.isValid()
self.assertTrue(layer.isValid())
layer.dataProvider().addAttributes([QgsField('max', QVariant.String, 'string', 10),
QgsField('nomax', QVariant.String, 'string', 0)])
layer.updateFields()
@@ -94,9 +92,29 @@ def testStringWithMaxLen(self):

QgsProject.instance().removeAllMapLayers()


class TestQgsValueRelationWidget(unittest.TestCase):

def test_enableDisable(self):
reg = QgsGui.editorWidgetRegistry()
layer = QgsVectorLayer("none?field=number:integer", "layer", "memory")
wrapper = reg.create('ValueRelation', layer, 0, {}, None, None)

widget = wrapper.widget()

self.assertTrue(widget.isEnabled())
wrapper.setEnabled(False)
self.assertFalse(widget.isEnabled())
wrapper.setEnabled(True)
self.assertTrue(widget.isEnabled())


class TestQgsValueMapEditWidget(unittest.TestCase):
VALUEMAP_NULL_TEXT = "{2839923C-8B7D-419E-B84B-CA2FE9B80EC7}"

def test_ValueMap_set_get(self):
layer = QgsVectorLayer("none?field=number:integer", "layer", "memory")
assert layer.isValid()
self.assertTrue(layer.isValid())
QgsProject.instance().addMapLayer(layer)
reg = QgsGui.editorWidgetRegistry()
configWdg = reg.createConfigWidget('ValueMap', layer, 0, None)
@@ -110,4 +128,6 @@ def test_ValueMap_set_get(self):
self.assertEqual(configWdg.config(), config)

QgsProject.instance().removeAllMapLayers()

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

0 comments on commit 46a74a0

Please sign in to comment.
You can’t perform that action at this time.