Skip to content
Permalink
Browse files
Add new postgres provider test
  • Loading branch information
m-kuhn committed May 22, 2015
1 parent 8571ae7 commit 97de55d117d8db2dba40daf2f161993084b79d33
Showing with 21 additions and 11 deletions.
  1. +16 −9 tests/src/python/providertestutils.py
  2. +5 −2 tests/src/python/test_provider_postgres.py
@@ -12,15 +12,22 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from qgis.core import QgsRectangle, QgsFeatureRequest

def runGetFeatureTests( vl ):
assert len( [f for f in vl.getFeatures()] ) == 5
assert len( [f for f in vl.getFeatures( 'name IS NOT NULL' )] ) == 4
assert len( [f for f in vl.getFeatures( 'name LIKE \'Apple\'' )] ) == 1
assert len( [f for f in vl.getFeatures( 'name ILIKE \'aPple\'' )] ) == 1
assert len( [f for f in vl.getFeatures( 'name ILIKE \'%pp%\'' )] ) == 1
assert len( [f for f in vl.getFeatures( 'cnt > 0' )] ) == 4
assert len( [f for f in vl.getFeatures( 'cnt < 0' )] ) == 1
assert len( [f for f in vl.getFeatures( 'cnt >= 100' )] ) == 4
assert len( [f for f in vl.getFeatures( 'cnt <= 100' )] ) == 2
assert len( [f for f in vl.getFeatures( 'pk IN (1, 2, 4, 8)' )] ) == 3
assert len( [f for f in vl.getFeatures( QgsFeatureRequest().setFilterExpression( 'name IS NOT NULL' ) )] ) == 4
assert len( [f for f in vl.getFeatures( QgsFeatureRequest().setFilterExpression('name LIKE \'Apple\'' ) )] ) == 1
assert len( [f for f in vl.getFeatures( QgsFeatureRequest().setFilterExpression('name ILIKE \'aPple\'' ) )] ) == 1
assert len( [f for f in vl.getFeatures( QgsFeatureRequest().setFilterExpression('name ILIKE \'%pp%\'' ) )] ) == 1
assert len( [f for f in vl.getFeatures( QgsFeatureRequest().setFilterExpression('cnt > 0' ) ) ] ) == 4
assert len( [f for f in vl.getFeatures( QgsFeatureRequest().setFilterExpression('cnt < 0' ) ) ] ) == 1
assert len( [f for f in vl.getFeatures( QgsFeatureRequest().setFilterExpression('cnt >= 100' ) ) ] ) == 4
assert len( [f for f in vl.getFeatures( QgsFeatureRequest().setFilterExpression('cnt <= 100' ) ) ] ) == 2
assert len( [f for f in vl.getFeatures( QgsFeatureRequest().setFilterExpression('pk IN (1, 2, 4, 8)' ) )] ) == 3

def runGetFilterRectTests( vl ):
extent = QgsRectangle(-70, 67, -60, 80)
features = [ f.id() for f in vl.getFeatures( QgsFeatureRequest().setFilterRect( extent ) ) ]
print (features)
assert set( features ) == set( [2L, 4L] )
@@ -22,7 +22,7 @@
TestCase,
unittest
)
from providertestutils import runGetFeatureTests
from providertestutils import * # testGetFeaturesUncompiled

QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
TEST_DATA_DIR = unitTestDataPath()
@@ -33,7 +33,7 @@ def setUpClass(cls):
"""Run before all tests"""

# Create test database
cls.vl = QgsVectorLayer( u'service=\'qgis_test\' key=\'pk\' table="qgis_test"."someData" sql=', 'test', 'postgres' )
cls.vl = QgsVectorLayer( u'dbname=\'qgis_test\' host=localhost port=5432 user=\'postgres\' password=\'postgres\' sslmode=disable key=\'pk\' srid=4326 type=POINT table="qgis_test"."someData" (geom) sql=', 'test', 'postgres' )


@classmethod
@@ -50,5 +50,8 @@ def testGetFeaturesCompiled(self):
QSettings().setValue( "/qgis/postgres/compileExpressions", True )
runGetFeatureTests( self.vl )

def testGetFeaturesFilterRectTests(self):
runGetFilterRectTests( self.vl )

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

0 comments on commit 97de55d

Please sign in to comment.