Skip to content

Commit e6de737

Browse files
pblottierem-kuhn
authored andcommittedJul 7, 2017
Add unit tests
1 parent 162063b commit e6de737

File tree

2 files changed

+1240
-0
lines changed

2 files changed

+1240
-0
lines changed
 

‎tests/src/python/test_qgsrelation.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
QgsRelation,
2020
QgsGeometry,
2121
QgsPointXY,
22+
QgsAttributeEditorElement,
2223
QgsProject
2324
)
25+
from utilities import unitTestDataPath
2426
from qgis.testing import start_app, unittest
27+
import os
2528

2629
start_app()
2730

@@ -156,6 +159,36 @@ def test_fieldPairs(self):
156159

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

162+
def testValidRelationAfterChangingStyle(self):
163+
# load project
164+
myPath = os.path.join(unitTestDataPath(), 'relations.qgs')
165+
QgsProject.instance().read(myPath)
166+
167+
# get referenced layer
168+
relations = QgsProject.instance().relationManager().relations()
169+
relation = relations[list(relations.keys())[0]]
170+
referencedLayer = relation.referencedLayer()
171+
172+
# check that the relation is valid
173+
valid = False
174+
for tab in referencedLayer.editFormConfig().tabs():
175+
for t in tab.children():
176+
if (t.type() == QgsAttributeEditorElement.AeTypeRelation):
177+
valid = t.relation().isValid()
178+
self.assertTrue(valid)
179+
180+
# update style
181+
referencedLayer.styleManager().setCurrentStyle("custom")
182+
183+
# check that the relation is still valid
184+
referencedLayer = relation.referencedLayer()
185+
valid = False
186+
for tab in referencedLayer.editFormConfig().tabs():
187+
for t in tab.children():
188+
if (t.type() == QgsAttributeEditorElement.AeTypeRelation):
189+
valid = t.relation().isValid()
190+
self.assertTrue(valid)
191+
159192

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

‎tests/testdata/relations.qgs

Lines changed: 1207 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.