Skip to content
Permalink
Browse files
Provider test
  • Loading branch information
m-kuhn committed May 22, 2015
1 parent a2ae8b4 commit ec9e1464c18443010f880c5c2ac6ec5bedb9d4f0
@@ -44,8 +44,7 @@ install:
-DWITH_QWTPOLAR=OFF -DWITH_APIDOC=ON ..

before_script:
- echo "localhost:*:*:postgres:postgres" > ~/.pgpass
- printf "[qgis_test]\nuser=postgres\nhost=localhost\nuser=postgres" > ~/.pg_service.conf
- printf "[qgis_test]\nhost=localhost\ndbname=qgis_test\nuser=postgres" > ~/.pg_service.conf
- psql -c 'CREATE DATABASE qgis_test;' -U postgres
- psql -c 'CREATE EXTENSION postgis;' -U postgres -d qgis_test
- psql -f $TRAVIS_BUILD_DIR/tests/testdata/postgres/testdata.sql -U postgres -d qgis_test
@@ -44,7 +44,7 @@ ADD_PYTHON_TEST(PyQgsGraduatedSymbolRendererV2 test_qgsgraduatedsymbolrendererv2
ADD_PYTHON_TEST(PyQgsNetworkContentFetcher test_qgsnetworkcontentfetcher.py)
ADD_PYTHON_TEST(PyQgsEditWidgets test_qgseditwidgets.py)
ADD_PYTHON_TEST(PyQgsRangeWidgets test_qgsrangewidgets.py)
ADD_PYTHON_TEST(PyQgsPostgresProvider test_postgres_provider.py)
ADD_PYTHON_TEST(PyQgsPostgresProvider test_provider_postgres.py)
IF (WITH_APIDOC)
ADD_PYTHON_TEST(PyQgsDocCoverage test_qgsdoccoverage.py)
ENDIF (WITH_APIDOC)
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
"""QGIS Unit test utils for provider tests.
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = 'Matthias Kuhn'
__date__ = '2015-04-27'
__copyright__ = 'Copyright 2015, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

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

@@ -22,6 +22,8 @@
TestCase,
unittest
)
from providertestutils import runGetFeatureTests

QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
TEST_DATA_DIR = unitTestDataPath()

@@ -41,25 +43,12 @@ def tearDownClass(cls):
# Delete test database

def testGetFeaturesUncompiled(self):
QSettings().setValue( "providers/postgres/compileExpressions", False )
self.runGetFeatureTests()
QSettings().setValue( "/qgis/postgres/compileExpressions", False )
runGetFeatureTests( self.vl )

def testGetFeaturesCompiled(self):
QSettings().setValue( "providers/postgres/compileExpressions", True )
self.runGetFeatureTests()

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

QSettings().setValue( "/qgis/postgres/compileExpressions", True )
runGetFeatureTests( self.vl )

if __name__ == '__main__':
unittest.main()
@@ -4,7 +4,7 @@

-- Dumped from database version 9.3.6
-- Dumped by pg_dump version 9.3.6
-- Started on 2015-04-23 18:42:07 CEST
-- Started on 2015-05-21 09:37:33 CEST

SET statement_timeout = 0;
SET lock_timeout = 0;
@@ -37,7 +37,8 @@ SET default_with_oids = false;
CREATE TABLE "someData" (
pk integer NOT NULL,
cnt integer,
name text
name text,
geom public.geometry(Point,4326)
);


@@ -49,12 +50,12 @@ ALTER TABLE qgis_test."someData" OWNER TO postgres;
-- Data for Name: someData; Type: TABLE DATA; Schema: qgis_test; Owner: postgres
--

COPY "someData" (pk, cnt, name) FROM stdin;
1 100 Orange
2 200 Apple
3 300 Pear
4 400 Honey
5 -200 \N
COPY "someData" (pk, cnt, name, geom) FROM stdin;
5 -200 \N 0101000020E61000001D5A643BDFC751C01F85EB51B88E5340
3 300 Pear \N
1 100 Orange 0101000020E61000006891ED7C3F9551C085EB51B81E955040
2 200 Apple 0101000020E6100000CDCCCCCCCC0C51C03333333333B35140
4 400 Honey 0101000020E610000014AE47E17A5450C03333333333935340
\.


@@ -67,7 +68,7 @@ ALTER TABLE ONLY "someData"
ADD CONSTRAINT "someData_pkey" PRIMARY KEY (pk);


-- Completed on 2015-04-23 18:42:07 CEST
-- Completed on 2015-05-21 09:37:33 CEST

--
-- PostgreSQL database dump complete

0 comments on commit ec9e146

Please sign in to comment.