-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for postgres provider
basically to get a framework to test the expression compiler
- Loading branch information
Showing
10 changed files
with
184 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# -*- coding: utf-8 -*- | ||
"""QGIS Unit tests for the postgres provider. | ||
.. 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-23' | ||
__copyright__ = 'Copyright 2015, The QGIS Project' | ||
# This will get replaced with a git SHA1 when you do a git archive | ||
__revision__ = '$Format:%H$' | ||
|
||
import qgis | ||
import os | ||
|
||
from qgis.core import QgsVectorLayer, QgsFeatureRequest, QgsFeature, QgsProviderRegistry | ||
from PyQt4.QtCore import QSettings | ||
from utilities import (unitTestDataPath, | ||
getQgisTestApp, | ||
TestCase, | ||
unittest | ||
) | ||
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp() | ||
TEST_DATA_DIR = unitTestDataPath() | ||
|
||
class TestPyQgsPostgresProvider(TestCase): | ||
@classmethod | ||
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' ) | ||
|
||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
"""Run after all tests""" | ||
|
||
# Delete test database | ||
|
||
def testGetFeaturesUncompiled(self): | ||
QSettings().setValue( "providers/postgres/compileExpressions", False ) | ||
self.runGetFeatureTests() | ||
|
||
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 | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
-- | ||
-- PostgreSQL database dump | ||
-- | ||
|
||
-- Dumped from database version 9.3.6 | ||
-- Dumped by pg_dump version 9.3.6 | ||
-- Started on 2015-04-23 18:42:07 CEST | ||
|
||
SET statement_timeout = 0; | ||
SET lock_timeout = 0; | ||
SET client_encoding = 'UTF8'; | ||
SET standard_conforming_strings = on; | ||
SET check_function_bodies = false; | ||
SET client_min_messages = warning; | ||
|
||
-- | ||
-- TOC entry 7 (class 2615 OID 377760) | ||
-- Name: qgis_test; Type: SCHEMA; Schema: -; Owner: postgres | ||
-- | ||
|
||
CREATE SCHEMA qgis_test; | ||
|
||
|
||
ALTER SCHEMA qgis_test OWNER TO postgres; | ||
|
||
SET search_path = qgis_test, pg_catalog; | ||
|
||
SET default_tablespace = ''; | ||
|
||
SET default_with_oids = false; | ||
|
||
-- | ||
-- TOC entry 171 (class 1259 OID 377761) | ||
-- Name: someData; Type: TABLE; Schema: qgis_test; Owner: postgres; Tablespace: | ||
-- | ||
|
||
CREATE TABLE "someData" ( | ||
pk integer NOT NULL, | ||
cnt integer, | ||
name text | ||
); | ||
|
||
|
||
ALTER TABLE qgis_test."someData" OWNER TO postgres; | ||
|
||
-- | ||
-- TOC entry 4068 (class 0 OID 377761) | ||
-- Dependencies: 171 | ||
-- 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 | ||
\. | ||
|
||
|
||
-- | ||
-- TOC entry 3953 (class 2606 OID 377768) | ||
-- Name: someData_pkey; Type: CONSTRAINT; Schema: qgis_test; Owner: postgres; Tablespace: | ||
-- | ||
|
||
ALTER TABLE ONLY "someData" | ||
ADD CONSTRAINT "someData_pkey" PRIMARY KEY (pk); | ||
|
||
|
||
-- Completed on 2015-04-23 18:42:07 CEST | ||
|
||
-- | ||
-- PostgreSQL database dump complete | ||
-- | ||
|