Skip to content

Commit

Permalink
Add tests for deleteCascade option
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Aug 28, 2017
1 parent 293f0f4 commit 4be1cc0
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/src/python/test_qgsvectorlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
QgsDiagramLayerSettings,
QgsTextFormat,
QgsVectorLayerSelectedFeatureSource,
QgsExpression,
NULL)
from qgis.gui import (QgsAttributeTableModel,
QgsGui
Expand Down Expand Up @@ -453,6 +454,53 @@ def checkAfter2():

self.assertEqual(layer.dataProvider().featureCount(), 0)

def test_DeleteJoinedFeature(self):
joinLayer = createJoinLayer()
joinLayer2 = createJoinLayer()
QgsProject.instance().addMapLayers([joinLayer, joinLayer2])

layer = createLayerWithOnePoint()

join = QgsVectorLayerJoinInfo()
join.setTargetFieldName("fldint")
join.setJoinLayer(joinLayer)
join.setJoinFieldName("y")
join.setUsingMemoryCache(True)
join.setEditable(True)
join.setDeleteCascade(True)

layer.addJoin(join)

join2 = QgsVectorLayerJoinInfo()
join2.setTargetFieldName("fldint")
join2.setJoinLayer(joinLayer2)
join2.setJoinFieldName("y")
join2.setUsingMemoryCache(True)
join2.setPrefix("custom-prefix_")
join2.setEditable(True)
join2.setDeleteCascade(False)

layer.addJoin(join2)

# check number of features
self.assertEqual(layer.featureCount(), 1)
self.assertEqual(joinLayer.featureCount(), 4)
self.assertEqual(joinLayer2.featureCount(), 4)

# delete a feature which is also in joined layers
layer.startEditing()
joinLayer.startEditing()
joinLayer2.startEditing()

filter = QgsExpression.createFieldEqualityExpression('fldint', '123')
feature = next(layer.getFeatures(QgsFeatureRequest().setFilterExpression(filter)))
layer.deleteFeature(feature.id())

# check number of features
self.assertEqual(layer.featureCount(), 0)
self.assertEqual(joinLayer.featureCount(), 3) # deleteCascade activated
self.assertEqual(joinLayer2.featureCount(), 4) # deleteCascade deactivated

# CHANGE ATTRIBUTE

def test_ChangeAttribute(self):
Expand Down

0 comments on commit 4be1cc0

Please sign in to comment.