Skip to content
Permalink
Browse files
Add unit test when auxiliary database is empty
  • Loading branch information
pblottiere committed Jun 15, 2021
1 parent 112fa38 commit a9dd8979efa78040815602cdd843529e609ec2d5
Showing with 44 additions and 0 deletions.
  1. +44 −0 tests/src/python/test_qgsauxiliarystorage.py
@@ -23,6 +23,7 @@
QgsPropertyDefinition,
QgsProperty,
QgsProject,
QgsProjectArchive,
QgsFeatureRequest,
QgsPalLayerSettings,
QgsSymbolLayer,
@@ -556,6 +557,49 @@ def testInvalidPrimaryKey(self):
self.assertEqual(al, None)
self.assertTrue("CREATE TABLE IF NOT EXISTS" in s.errorString())

def testQgdCreationInQgz(self):
# New project
p = QgsProject()
self.assertTrue(p.auxiliaryStorage().isValid())

# Save the project
path = tmpPath()
qgz = path + '.qgz'
self.assertTrue(p.write(qgz))
self.assertTrue(os.path.exists(qgz))

# Check the content of the archive: auxiliary database doesn't exist
# because it's empty
archive = QgsProjectArchive()
archive.unzip(qgz)
self.assertEqual(archive.auxiliaryStorageFile(), "")

# Add a vector layer and an auxiliary layer in the project
vl = createLayer()
self.assertTrue(vl.isValid())
p.addMapLayers([vl])

pkf = vl.fields().field(vl.fields().indexOf('pk'))
al = p.auxiliaryStorage().createAuxiliaryLayer(pkf, vl)
self.assertTrue(al.isValid())
vl.setAuxiliaryLayer(al)

# Add an auxiliary field to have a non empty auxiliary storage
pdef = QgsPropertyDefinition('propname', QgsPropertyDefinition.DataTypeNumeric, '', '', 'ut')
self.assertTrue(al.addAuxiliaryField(pdef))

# Save the project
path = tmpPath()
qgz = path + '.qgz'
self.assertTrue(p.write(qgz))
self.assertTrue(os.path.exists(qgz))

# Check the content of the archive: auxiliary database doesn't exist
# because it's empty
archive = QgsProjectArchive()
archive.unzip(qgz)
self.assertTrue(archive.auxiliaryStorageFile())


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

0 comments on commit a9dd897

Please sign in to comment.