Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Jun 7, 2021
1 parent 65a50af commit 155fd5c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/src/python/test_qgsauxiliarystorage.py
Expand Up @@ -27,6 +27,7 @@
QgsPalLayerSettings,
QgsSymbolLayer,
QgsVectorLayerSimpleLabeling,
QgsField,
QgsCallout,
QgsSimpleLineCallout,
NULL)
Expand Down Expand Up @@ -534,6 +535,27 @@ def testQgdCreation(self):
qgd = newpath + '.qgd'
self.assertTrue(os.path.exists(qgd))

def testInvalidPrimaryKey(self):
# create layer
vl = QgsVectorLayer(
'Point?crs=epsg:4326&field=pk:integer&key=pk',
'test', 'memory')
assert (vl.isValid())

# add a field with an invalid typename
field = QgsField(name="invalid_pk", type=QVariant.Int, typeName="xsd:int")
vl.startEditing()
vl.addAttribute(field)
vl.commitChanges()

# create auxiliary storage based on the invalid field
s = QgsAuxiliaryStorage()
pkf = vl.fields().field(vl.fields().indexOf('invalid_pk'))
al = s.createAuxiliaryLayer(pkf, vl)

self.assertEqual(al, None)
self.assertTrue("CREATE TABLE IF NOT EXISTS" in s.errorString())


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

0 comments on commit 155fd5c

Please sign in to comment.