Skip to content
Permalink
Browse files

Add some tests

  • Loading branch information
pblottiere committed Jul 5, 2017
1 parent 15546d8 commit e306cb4b0982e459f6c5695904a9a3099bc63f05
Showing with 34 additions and 0 deletions.
  1. +34 −0 tests/src/python/test_qgsexpression.py
@@ -14,6 +14,7 @@

import qgis # NOQA

from qgis.PyQt.QtCore import QVariant
from qgis.testing import unittest
from qgis.utils import qgsfunction
from qgis.core import QgsExpression, QgsFeatureRequest
@@ -196,6 +197,39 @@ def testValid(self):
e.setExpression('1')
self.assertTrue(e.isValid())

def testCreateFieldEqualityExpression(self):
e = QgsExpression()

# test when value is null
field = "myfield"
value = QVariant()
res = '"myfield" IS NULL'
self.assertEqual(e.createFieldEqualityExpression(field, value), res)

# test when value is null and field name has a quote
field = "my'field"
value = QVariant()
res = '"my\'field" IS NULL'
self.assertEqual(e.createFieldEqualityExpression(field, value), res)

# test when field name has a quote and value is an int
field = "my'field"
value = 5
res = '"my\'field" = 5'
self.assertEqual(e.createFieldEqualityExpression(field, value), res)

# test when field name has a quote and value is a string
field = "my'field"
value = '5'
res = '"my\'field" = \'5\''
self.assertEqual(e.createFieldEqualityExpression(field, value), res)

# test when field name has a quote and value is a boolean
field = "my'field"
value = True
res = '"my\'field" = TRUE'
self.assertEqual(e.createFieldEqualityExpression(field, value), res)


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

0 comments on commit e306cb4

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