Skip to content
Permalink
Browse files
Add unit test
  • Loading branch information
pblottiere committed Jun 7, 2021
1 parent 65a50af commit 155fd5c79bb724581b8e724b656c1ba58d393f82
Showing with 22 additions and 0 deletions.
  1. +22 −0 tests/src/python/test_qgsauxiliarystorage.py
@@ -27,6 +27,7 @@
QgsPalLayerSettings,
QgsSymbolLayer,
QgsVectorLayerSimpleLabeling,
QgsField,
QgsCallout,
QgsSimpleLineCallout,
NULL)
@@ -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.