Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add unit test when auxiliary database is empty
  • Loading branch information
pblottiere committed Jun 15, 2021
1 parent 112fa38 commit a9dd897
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/src/python/test_qgsauxiliarystorage.py
Expand Up @@ -23,6 +23,7 @@
QgsPropertyDefinition,
QgsProperty,
QgsProject,
QgsProjectArchive,
QgsFeatureRequest,
QgsPalLayerSettings,
QgsSymbolLayer,
Expand Down Expand Up @@ -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.