Skip to content

Commit

Permalink
Add new postgres provider test
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed May 22, 2015
1 parent 8571ae7 commit 97de55d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
25 changes: 16 additions & 9 deletions tests/src/python/providertestutils.py
Expand Up @@ -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] )
7 changes: 5 additions & 2 deletions tests/src/python/test_provider_postgres.py
Expand Up @@ -22,7 +22,7 @@
TestCase,
unittest
)
from providertestutils import runGetFeatureTests
from providertestutils import * # testGetFeaturesUncompiled

QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
TEST_DATA_DIR = unitTestDataPath()
Expand All @@ -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
Expand All @@ -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.