Skip to content

Commit

Permalink
Add test cases for aliased spatialite tables
Browse files Browse the repository at this point in the history
Also update a failing test case since when
we changed the priority in  QgsVectorLayerUtils
CreateFeature.

Test was blacklisted on travis in nov 2017
but here they are anyway.
  • Loading branch information
elpaso committed Dec 9, 2018
1 parent b5181f2 commit a44b13b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions tests/src/python/test_provider_spatialite.py
Expand Up @@ -654,14 +654,14 @@ def testVectorLayerUtilsCreateFeatureWithProviderDefaultLiteral(self):
f = QgsVectorLayerUtils.createFeature(vl)
self.assertEqual(f.attributes(), [None, "qgis 'is good", 5, 5.7, None])

# check that provider default literals take precedence over passed attribute values
# check that provider default literals do not take precedence over passed attribute values
f = QgsVectorLayerUtils.createFeature(vl, attributes={1: 'qgis is great', 0: 3})
self.assertEqual(f.attributes(), [3, "qgis 'is good", 5, 5.7, None])
self.assertEqual(f.attributes(), [3, "qgis is great", 5, 5.7, None])

# test that vector layer default value expression overrides provider default literal
vl.setDefaultValueDefinition(3, QgsDefaultValue("4*3"))
f = QgsVectorLayerUtils.createFeature(vl, attributes={1: 'qgis is great', 0: 3})
self.assertEqual(f.attributes(), [3, "qgis 'is good", 5, 12, None])
self.assertEqual(f.attributes(), [3, "qgis is great", 5, 12, None])

def testCreateAttributeIndex(self):
vl = QgsVectorLayer("dbname=%s table='test_defaults' key='id'" % self.dbname, "test_defaults", "spatialite")
Expand Down Expand Up @@ -848,6 +848,18 @@ def _check_features(vl, offset):
self.assertTrue(vl_no_pk.isValid())
_check_features(vl_no_pk, 10)

def testAliasedQueries(self):
"""Test regression when sending queries with aliased tables from DB manager"""

def _test(sql):
vl = QgsVectorLayer('dbname=\'{}/provider/spatialite.db\' table="{}" (geom) sql='.format(TEST_DATA_DIR, sql), 'test', 'spatialite')
self.assertTrue(vl.isValid())

_test("(SELECT * FROM somedata as my_alias\n)")
_test("(SELECT * FROM somedata as my_alias)")
_test("(SELECT * FROM somedata AS my_alias)")
_test('(SELECT * FROM \\"somedata\\" as my_alias\n)')


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

0 comments on commit a44b13b

Please sign in to comment.