diff --git a/tests/src/python/test_provider_postgres.py b/tests/src/python/test_provider_postgres.py index 832c3a466f8..7f482ae1603 100644 --- a/tests/src/python/test_provider_postgres.py +++ b/tests/src/python/test_provider_postgres.py @@ -158,8 +158,7 @@ class TestPyQgsPostgresProvider(unittest.TestCase, ProviderTestCase): # See http://hub.qgis.org/issues/14262 def testSignedIdentifiers(self): - def test_query_attribute(dbconn, query, att, val, fidval): - ql = QgsVectorLayer('%s table="%s" (g) key=\'%s\' sql=' % (dbconn, query.replace('"', '\\"'), att), "testgeom", "postgres") + def test_layer(ql, att, val, fidval): self.assertTrue(ql.isValid()) features = ql.getFeatures() att_idx = ql.fieldNameIndex(att) @@ -169,9 +168,18 @@ class TestPyQgsPostgresProvider(unittest.TestCase, ProviderTestCase): self.assertEqual(f.attributes()[att_idx], val) self.assertEqual(f.id(), fidval) self.assertEqual(count, 1) - test_query_attribute(self.dbconn, '(SELECT -1::int4 i, NULL::geometry(Point) g)', 'i', -1, 4294967295) - test_query_attribute(self.dbconn, '(SELECT -2::int2 i, NULL::geometry(Point) g)', 'i', -2, 4294967294) - test_query_attribute(self.dbconn, '(SELECT -3::int8 i, NULL::geometry(Point) g)', 'i', -3, 1) + + def test(dbconn, query, att, val, fidval): + table = query.replace('"', '\\"') + uri = '%s table="%s" (g) key=\'%s\'' % (dbconn, table, att) + ql = QgsVectorLayer(uri, "t", "postgres") + test_layer(ql, att, val, fidval) + # now with estimated metadata + uri += ' estimatedmetadata="true"' + test_layer(ql, att, val, fidval) + test(self.dbconn, '(SELECT -1::int4 i, NULL::geometry(Point) g)', 'i', -1, 4294967295) + test(self.dbconn, '(SELECT -2::int2 i, NULL::geometry(Point) g)', 'i', -2, 4294967294) + test(self.dbconn, '(SELECT -3::int8 i, NULL::geometry(Point) g)', 'i', -3, 1) def testPktIntInsert(self): vl = QgsVectorLayer('{} table="qgis_test"."{}" key="pk" sql='.format(self.dbconn, 'bikes_view'), "bikes_view", "postgres")