Skip to content

Commit a9dd897

Browse files
committedJun 15, 2021
Add unit test when auxiliary database is empty
1 parent 112fa38 commit a9dd897

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
 

‎tests/src/python/test_qgsauxiliarystorage.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
QgsPropertyDefinition,
2424
QgsProperty,
2525
QgsProject,
26+
QgsProjectArchive,
2627
QgsFeatureRequest,
2728
QgsPalLayerSettings,
2829
QgsSymbolLayer,
@@ -556,6 +557,49 @@ def testInvalidPrimaryKey(self):
556557
self.assertEqual(al, None)
557558
self.assertTrue("CREATE TABLE IF NOT EXISTS" in s.errorString())
558559

560+
def testQgdCreationInQgz(self):
561+
# New project
562+
p = QgsProject()
563+
self.assertTrue(p.auxiliaryStorage().isValid())
564+
565+
# Save the project
566+
path = tmpPath()
567+
qgz = path + '.qgz'
568+
self.assertTrue(p.write(qgz))
569+
self.assertTrue(os.path.exists(qgz))
570+
571+
# Check the content of the archive: auxiliary database doesn't exist
572+
# because it's empty
573+
archive = QgsProjectArchive()
574+
archive.unzip(qgz)
575+
self.assertEqual(archive.auxiliaryStorageFile(), "")
576+
577+
# Add a vector layer and an auxiliary layer in the project
578+
vl = createLayer()
579+
self.assertTrue(vl.isValid())
580+
p.addMapLayers([vl])
581+
582+
pkf = vl.fields().field(vl.fields().indexOf('pk'))
583+
al = p.auxiliaryStorage().createAuxiliaryLayer(pkf, vl)
584+
self.assertTrue(al.isValid())
585+
vl.setAuxiliaryLayer(al)
586+
587+
# Add an auxiliary field to have a non empty auxiliary storage
588+
pdef = QgsPropertyDefinition('propname', QgsPropertyDefinition.DataTypeNumeric, '', '', 'ut')
589+
self.assertTrue(al.addAuxiliaryField(pdef))
590+
591+
# Save the project
592+
path = tmpPath()
593+
qgz = path + '.qgz'
594+
self.assertTrue(p.write(qgz))
595+
self.assertTrue(os.path.exists(qgz))
596+
597+
# Check the content of the archive: auxiliary database doesn't exist
598+
# because it's empty
599+
archive = QgsProjectArchive()
600+
archive.unzip(qgz)
601+
self.assertTrue(archive.auxiliaryStorageFile())
602+
559603

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

0 commit comments

Comments
 (0)
Please sign in to comment.