Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere authored and m-kuhn committed Jul 7, 2017
1 parent 162063b commit e6de737
Show file tree
Hide file tree
Showing 2 changed files with 1,240 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/src/python/test_qgsrelation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
QgsRelation,
QgsGeometry,
QgsPointXY,
QgsAttributeEditorElement,
QgsProject
)
from utilities import unitTestDataPath
from qgis.testing import start_app, unittest
import os

start_app()

Expand Down Expand Up @@ -156,6 +159,36 @@ def test_fieldPairs(self):

assert (rel.fieldPairs() == {'foreignkey': 'y'})

def testValidRelationAfterChangingStyle(self):
# load project
myPath = os.path.join(unitTestDataPath(), 'relations.qgs')
QgsProject.instance().read(myPath)

# get referenced layer
relations = QgsProject.instance().relationManager().relations()
relation = relations[list(relations.keys())[0]]
referencedLayer = relation.referencedLayer()

# check that the relation is valid
valid = False
for tab in referencedLayer.editFormConfig().tabs():
for t in tab.children():
if (t.type() == QgsAttributeEditorElement.AeTypeRelation):
valid = t.relation().isValid()
self.assertTrue(valid)

# update style
referencedLayer.styleManager().setCurrentStyle("custom")

# check that the relation is still valid
referencedLayer = relation.referencedLayer()
valid = False
for tab in referencedLayer.editFormConfig().tabs():
for t in tab.children():
if (t.type() == QgsAttributeEditorElement.AeTypeRelation):
valid = t.relation().isValid()
self.assertTrue(valid)


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

0 comments on commit e6de737

Please sign in to comment.