Skip to content

Commit a44b13b

Browse files
committedDec 9, 2018
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.
1 parent b5181f2 commit a44b13b

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed
 

‎tests/src/python/test_provider_spatialite.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,14 +654,14 @@ def testVectorLayerUtilsCreateFeatureWithProviderDefaultLiteral(self):
654654
f = QgsVectorLayerUtils.createFeature(vl)
655655
self.assertEqual(f.attributes(), [None, "qgis 'is good", 5, 5.7, None])
656656

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

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

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

851+
def testAliasedQueries(self):
852+
"""Test regression when sending queries with aliased tables from DB manager"""
853+
854+
def _test(sql):
855+
vl = QgsVectorLayer('dbname=\'{}/provider/spatialite.db\' table="{}" (geom) sql='.format(TEST_DATA_DIR, sql), 'test', 'spatialite')
856+
self.assertTrue(vl.isValid())
857+
858+
_test("(SELECT * FROM somedata as my_alias\n)")
859+
_test("(SELECT * FROM somedata as my_alias)")
860+
_test("(SELECT * FROM somedata AS my_alias)")
861+
_test('(SELECT * FROM \\"somedata\\" as my_alias\n)')
862+
851863

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

0 commit comments

Comments
 (0)
Please sign in to comment.