Skip to content

Commit ec9e146

Browse files
committed
Provider test
1 parent a2ae8b4 commit ec9e146

File tree

5 files changed

+44
-29
lines changed

5 files changed

+44
-29
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ install:
4444
-DWITH_QWTPOLAR=OFF -DWITH_APIDOC=ON ..
4545

4646
before_script:
47-
- echo "localhost:*:*:postgres:postgres" > ~/.pgpass
48-
- printf "[qgis_test]\nuser=postgres\nhost=localhost\nuser=postgres" > ~/.pg_service.conf
47+
- printf "[qgis_test]\nhost=localhost\ndbname=qgis_test\nuser=postgres" > ~/.pg_service.conf
4948
- psql -c 'CREATE DATABASE qgis_test;' -U postgres
5049
- psql -c 'CREATE EXTENSION postgis;' -U postgres -d qgis_test
5150
- psql -f $TRAVIS_BUILD_DIR/tests/testdata/postgres/testdata.sql -U postgres -d qgis_test

tests/src/python/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ADD_PYTHON_TEST(PyQgsGraduatedSymbolRendererV2 test_qgsgraduatedsymbolrendererv2
4444
ADD_PYTHON_TEST(PyQgsNetworkContentFetcher test_qgsnetworkcontentfetcher.py)
4545
ADD_PYTHON_TEST(PyQgsEditWidgets test_qgseditwidgets.py)
4646
ADD_PYTHON_TEST(PyQgsRangeWidgets test_qgsrangewidgets.py)
47-
ADD_PYTHON_TEST(PyQgsPostgresProvider test_postgres_provider.py)
47+
ADD_PYTHON_TEST(PyQgsPostgresProvider test_provider_postgres.py)
4848
IF (WITH_APIDOC)
4949
ADD_PYTHON_TEST(PyQgsDocCoverage test_qgsdoccoverage.py)
5050
ENDIF (WITH_APIDOC)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
"""QGIS Unit test utils for provider tests.
3+
4+
.. note:: This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; either version 2 of the License, or
7+
(at your option) any later version.
8+
"""
9+
__author__ = 'Matthias Kuhn'
10+
__date__ = '2015-04-27'
11+
__copyright__ = 'Copyright 2015, The QGIS Project'
12+
# This will get replaced with a git SHA1 when you do a git archive
13+
__revision__ = '$Format:%H$'
14+
15+
def runGetFeatureTests( vl ):
16+
assert len( [f for f in vl.getFeatures()] ) == 5
17+
assert len( [f for f in vl.getFeatures( 'name IS NOT NULL' )] ) == 4
18+
assert len( [f for f in vl.getFeatures( 'name LIKE \'Apple\'' )] ) == 1
19+
assert len( [f for f in vl.getFeatures( 'name ILIKE \'aPple\'' )] ) == 1
20+
assert len( [f for f in vl.getFeatures( 'name ILIKE \'%pp%\'' )] ) == 1
21+
assert len( [f for f in vl.getFeatures( 'cnt > 0' )] ) == 4
22+
assert len( [f for f in vl.getFeatures( 'cnt < 0' )] ) == 1
23+
assert len( [f for f in vl.getFeatures( 'cnt >= 100' )] ) == 4
24+
assert len( [f for f in vl.getFeatures( 'cnt <= 100' )] ) == 2
25+
assert len( [f for f in vl.getFeatures( 'pk IN (1, 2, 4, 8)' )] ) == 3
26+

tests/src/python/test_postgres_provider.py renamed to tests/src/python/test_provider_postgres.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
TestCase,
2323
unittest
2424
)
25+
from providertestutils import runGetFeatureTests
26+
2527
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
2628
TEST_DATA_DIR = unitTestDataPath()
2729

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

4345
def testGetFeaturesUncompiled(self):
44-
QSettings().setValue( "providers/postgres/compileExpressions", False )
45-
self.runGetFeatureTests()
46+
QSettings().setValue( "/qgis/postgres/compileExpressions", False )
47+
runGetFeatureTests( self.vl )
4648

4749
def testGetFeaturesCompiled(self):
48-
QSettings().setValue( "providers/postgres/compileExpressions", True )
49-
self.runGetFeatureTests()
50-
51-
def runGetFeatureTests(self):
52-
assert len( [f for f in self.vl.getFeatures()] ) == 5
53-
assert len( [f for f in self.vl.getFeatures( 'name IS NOT NULL' )] ) == 4
54-
assert len( [f for f in self.vl.getFeatures( 'name LIKE \'Apple\'' )] ) == 1
55-
assert len( [f for f in self.vl.getFeatures( 'name ILIKE \'aPple\'' )] ) == 1
56-
assert len( [f for f in self.vl.getFeatures( 'name ILIKE \'%pp%\'' )] ) == 1
57-
assert len( [f for f in self.vl.getFeatures( 'cnt > 0' )] ) == 4
58-
assert len( [f for f in self.vl.getFeatures( 'cnt < 0' )] ) == 1
59-
assert len( [f for f in self.vl.getFeatures( 'cnt >= 100' )] ) == 4
60-
assert len( [f for f in self.vl.getFeatures( 'cnt <= 100' )] ) == 2
61-
assert len( [f for f in self.vl.getFeatures( 'pk IN (1, 2, 4, 8)' )] ) == 3
62-
50+
QSettings().setValue( "/qgis/postgres/compileExpressions", True )
51+
runGetFeatureTests( self.vl )
6352

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

tests/testdata/postgres/testdata.sql

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

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

99
SET statement_timeout = 0;
1010
SET lock_timeout = 0;
@@ -37,7 +37,8 @@ SET default_with_oids = false;
3737
CREATE TABLE "someData" (
3838
pk integer NOT NULL,
3939
cnt integer,
40-
name text
40+
name text,
41+
geom public.geometry(Point,4326)
4142
);
4243

4344

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

52-
COPY "someData" (pk, cnt, name) FROM stdin;
53-
1 100 Orange
54-
2 200 Apple
55-
3 300 Pear
56-
4 400 Honey
57-
5 -200 \N
53+
COPY "someData" (pk, cnt, name, geom) FROM stdin;
54+
5 -200 \N 0101000020E61000001D5A643BDFC751C01F85EB51B88E5340
55+
3 300 Pear \N
56+
1 100 Orange 0101000020E61000006891ED7C3F9551C085EB51B81E955040
57+
2 200 Apple 0101000020E6100000CDCCCCCCCC0C51C03333333333B35140
58+
4 400 Honey 0101000020E610000014AE47E17A5450C03333333333935340
5859
\.
5960

6061

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

6970

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

7273
--
7374
-- PostgreSQL database dump complete

0 commit comments

Comments
 (0)