Skip to content

Commit 30b35bd

Browse files
committedJun 25, 2017
Add unit test
1 parent 5f22ba1 commit 30b35bd

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
 

‎tests/src/python/test_qgsattributetablemodel.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,35 @@ def testRemoveColumns(self):
9191

9292
self.assertEqual(self.am.columnCount(), 1)
9393

94+
def testEdit(self):
95+
fid = 2
96+
field_idx = 1
97+
new_value = 333
98+
99+
# get the same feature from model and layer
100+
feature = self.layer.getFeature(fid)
101+
model_index = self.am.idToIndex(fid)
102+
feature_model = self.am.feature(model_index)
103+
104+
# check that feature from layer and model are sync
105+
self.assertEqual(feature.attribute(field_idx), feature_model.attribute(field_idx))
106+
107+
# change attribute value for a feature and commit
108+
self.layer.startEditing()
109+
self.layer.changeAttributeValue(fid, field_idx, new_value)
110+
self.layer.commitChanges()
111+
112+
# check the feature in layer is good
113+
feature = self.layer.getFeature(fid)
114+
self.assertEqual(feature.attribute(field_idx), new_value)
115+
116+
# get the same feature from model and layer
117+
model_index = self.am.idToIndex(fid)
118+
feature_model = self.am.feature(model_index)
119+
120+
# check that index from layer and model are sync
121+
self.assertEqual(feature.attribute(field_idx), feature_model.attribute(field_idx))
122+
94123

95124
if __name__ == '__main__':
96125
unittest.main()

0 commit comments

Comments
 (0)