|
23 | 23 | QgsPropertyDefinition,
|
24 | 24 | QgsProperty,
|
25 | 25 | QgsProject,
|
| 26 | + QgsProjectArchive, |
26 | 27 | QgsFeatureRequest,
|
27 | 28 | QgsPalLayerSettings,
|
28 | 29 | QgsSymbolLayer,
|
@@ -556,6 +557,49 @@ def testInvalidPrimaryKey(self):
|
556 | 557 | self.assertEqual(al, None)
|
557 | 558 | self.assertTrue("CREATE TABLE IF NOT EXISTS" in s.errorString())
|
558 | 559 |
|
| 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 | + |
559 | 603 |
|
560 | 604 | if __name__ == '__main__':
|
561 | 605 | unittest.main()
|
0 commit comments