def testSetActive(self):
        """ Test setting the search as active - should set active flags to match search widget wrapper's defaults """

        layer = QgsVectorLayer(
            "Point?field=fldtext:string&field=fldint:integer", "test",
            "memory")
        parent = QWidget()
        w = QgsDefaultSearchWidgetWrapper(layer, 0, parent)
        af = QgsAttributeFormEditorWidget(None, None)
        af.setSearchWidgetWrapper(w)

        sb = af.searchWidgetToolButton()
        # start with inactive
        sb.setActiveFlags(QgsSearchWidgetWrapper.FilterFlags())
        # set to inactive
        sb.setActive()
        # check that correct default flag was taken from search widget wrapper
        self.assertTrue(sb.activeFlags() & QgsSearchWidgetWrapper.Contains)

        # try again with numeric field - default should be "EqualTo"
        w = QgsDefaultSearchWidgetWrapper(layer, 1, parent)
        af.setSearchWidgetWrapper(w)
        # start with inactive
        sb.setActiveFlags(QgsSearchWidgetWrapper.FilterFlags())
        # set to inactive
        sb.setActive()
        # check that correct default flag was taken from search widget wrapper
        self.assertTrue(sb.activeFlags() & QgsSearchWidgetWrapper.EqualTo)
 def testFlagToString(self):
     # test converting QgsSearchWidgetWrapper.FilterFlag to string
     tests = [
         QgsSearchWidgetWrapper.EqualTo, QgsSearchWidgetWrapper.NotEqualTo,
         QgsSearchWidgetWrapper.GreaterThan,
         QgsSearchWidgetWrapper.LessThan,
         QgsSearchWidgetWrapper.GreaterThanOrEqualTo,
         QgsSearchWidgetWrapper.LessThanOrEqualTo,
         QgsSearchWidgetWrapper.Between,
         QgsSearchWidgetWrapper.CaseInsensitive,
         QgsSearchWidgetWrapper.Contains,
         QgsSearchWidgetWrapper.DoesNotContain,
         QgsSearchWidgetWrapper.IsNull, QgsSearchWidgetWrapper.IsNotNull,
         QgsSearchWidgetWrapper.IsNotBetween
     ]
     for t in tests:
         self.assertTrue(len(QgsSearchWidgetWrapper.toString(t)) > 0)
 def testFlagToString(self):
     # test converting QgsSearchWidgetWrapper.FilterFlag to string
     tests = [QgsSearchWidgetWrapper.EqualTo,
              QgsSearchWidgetWrapper.NotEqualTo,
              QgsSearchWidgetWrapper.GreaterThan,
              QgsSearchWidgetWrapper.LessThan,
              QgsSearchWidgetWrapper.GreaterThanOrEqualTo,
              QgsSearchWidgetWrapper.LessThanOrEqualTo,
              QgsSearchWidgetWrapper.Between,
              QgsSearchWidgetWrapper.CaseInsensitive,
              QgsSearchWidgetWrapper.Contains,
              QgsSearchWidgetWrapper.DoesNotContain,
              QgsSearchWidgetWrapper.IsNull,
              QgsSearchWidgetWrapper.IsNotNull,
              QgsSearchWidgetWrapper.IsNotBetween
              ]
     for t in tests:
         self.assertTrue(len(QgsSearchWidgetWrapper.toString(t)) > 0)
 def testExclusiveFlags(self):
     # test flag exclusive/non exclusive
     exclusive = QgsSearchWidgetWrapper.exclusiveFilterFlags()
     non_exclusive = QgsSearchWidgetWrapper.nonExclusiveFilterFlags()
     for e in exclusive:
         self.assertFalse(e in non_exclusive)
 def testExclusiveFlags(self):
     # test flag exclusive/non exclusive
     exclusive = QgsSearchWidgetWrapper.exclusiveFilterFlags()
     non_exclusive = QgsSearchWidgetWrapper.nonExclusiveFilterFlags()
     for e in exclusive:
         self.assertFalse(e in non_exclusive)