Skip to content
Permalink
Browse files

Add provider test for postgres with compound key

  • Loading branch information
nyalldawson authored and 3nids committed Aug 15, 2016
1 parent 5d30b5f commit c2a232848c6b92f193d4f23174698e9b8eacda53
Showing with 52 additions and 0 deletions.
  1. +30 −0 tests/src/python/test_provider_postgres.py
  2. +22 −0 tests/testdata/provider/testdata_pg.sql
@@ -312,5 +312,35 @@ def testRenameAttributes(self):
self.assertEqual(fet.fields()[1].name(), 'newname2')
self.assertEqual(fet.fields()[2].name(), 'another')


class TestPyQgsPostgresProviderCompoundKey(unittest.TestCase, ProviderTestCase):

@classmethod
def setUpClass(cls):
"""Run before all tests"""
cls.dbconn = u'dbname=\'qgis_test\''
if 'QGIS_PGTEST_DB' in os.environ:
cls.dbconn = os.environ['QGIS_PGTEST_DB']
# Create test layers
cls.vl = QgsVectorLayer(cls.dbconn + ' sslmode=disable key=\'"key1","key2"\' srid=4326 type=POINT table="qgis_test"."someDataCompound" (geom) sql=', 'test', 'postgres')
assert cls.vl.isValid()
cls.provider = cls.vl.dataProvider()

@classmethod
def tearDownClass(cls):
"""Run after all tests"""

def enableCompiler(self):
QSettings().setValue(u'/qgis/compileExpressions', True)

def disableCompiler(self):
QSettings().setValue(u'/qgis/compileExpressions', False)

def uncompiledFilters(self):
return set(['intersects($geometry,geom_from_wkt( \'Polygon ((-72.2 66.1, -65.2 66.1, -65.2 72.0, -72.2 72.0, -72.2 66.1))\'))'])

def partiallyCompiledFilters(self):
return set([])

if __name__ == '__main__':
unittest.main()
@@ -68,6 +68,28 @@ INSERT INTO qgis_test."some_poly_data" (pk, geom) VALUES
(4, NULL)
;

-- Provider check with compound key

CREATE TABLE qgis_test."someDataCompound" (
key1 integer,
key2 integer,
pk integer NOT NULL,
cnt integer,
name text DEFAULT 'qgis',
name2 text DEFAULT 'qgis',
num_char text,
geom public.geometry(Point,4326),
PRIMARY KEY(key1, key2)
);

INSERT INTO qgis_test."someDataCompound" ( key1, key2, pk, cnt, name, name2, num_char, geom) VALUES
(1, 1, 5, -200, NULL, 'NuLl', '5', '0101000020E61000001D5A643BDFC751C01F85EB51B88E5340'),
(1, 2, 3, 300, 'Pear', 'PEaR', '3', NULL),
(2, 1, 1, 100, 'Orange', 'oranGe', '1', '0101000020E61000006891ED7C3F9551C085EB51B81E955040'),
(2, 2, 2, 200, 'Apple', 'Apple', '2', '0101000020E6100000CDCCCCCCCC0C51C03333333333B35140'),
(2, 3, 4, 400, 'Honey', 'Honey', '4', '0101000020E610000014AE47E17A5450C03333333333935340')
;

--
-- TOC entry 3953 (class 2606 OID 377768)
-- Name: someData_pkey; Type: CONSTRAINT; Schema: qgis_test; Owner: postgres; Tablespace:

0 comments on commit c2a2328

Please sign in to comment.
You can’t perform that action at this time.