Skip to content
Permalink
Browse files

Add test cases for aliased spatialite tables

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 a44b13ba676fabf10f50aa8d74150484e378409c
Showing with 15 additions and 3 deletions.
  1. +15 −3 tests/src/python/test_provider_spatialite.py
@@ -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")
@@ -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.
You can’t perform that action at this time.