Skip to content

Commit

Permalink
Flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed May 21, 2020
1 parent 25d3052 commit 34ec263
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions tests/src/python/providertestbase.py
Expand Up @@ -879,36 +879,35 @@ def testChangeAttributes(self):
self.assertFalse(l.dataProvider().changeAttributeValues(changes),
'Provider reported no ChangeAttributeValues capability, but returned true to changeAttributeValues')


def testChangeAttributesConstraintViolation(self):
"""Checks that changing attributes violating a DB-level CHECK constraint returns false
the provider test case must provide an editable layer with a text field
"i_will_fail_on_no_name" having a CHECK constraint that will fail when value is "no name".
The layer must contain at least 2 features, that will be used to test the attibute change.
"""
"""Checks that changing attributes violating a DB-level CHECK constraint returns false
the provider test case must provide an editable layer with a text field
"i_will_fail_on_no_name" having a CHECK constraint that will fail when value is "no name".
The layer must contain at least 2 features, that will be used to test the attibute change.
"""

if not getattr(self, 'getEditableLayerWithCheckConstraint', None):
return
if not getattr(self, 'getEditableLayerWithCheckConstraint', None):
return

l = self.getEditableLayerWithCheckConstraint()
self.assertTrue(l.isValid())
l = self.getEditableLayerWithCheckConstraint()
self.assertTrue(l.isValid())

assert l.dataProvider().capabilities() & QgsVectorDataProvider.ChangeAttributeValues

# find the featurea to change
feature0 = [f for f in l.dataProvider().getFeatures()][0]
feature1 = [f for f in l.dataProvider().getFeatures()][1]
field_idx = l.fields().indexFromName('i_will_fail_on_no_name')
self.assertTrue(field_idx >= 0)
# changes by feature id, for changeAttributeValues call
changes = {
feature0.id(): {field_idx: 'no name'},
feature1.id(): {field_idx: 'I have a valid name'}
}
# expect failure
result = l.dataProvider().changeAttributeValues(changes)
self.assertFalse(
result, 'Provider reported success when changing an attribute value that violates a DB level CHECK constraint')
assert l.dataProvider().capabilities() & QgsVectorDataProvider.ChangeAttributeValues

# find the featurea to change
feature0 = [f for f in l.dataProvider().getFeatures()][0]
feature1 = [f for f in l.dataProvider().getFeatures()][1]
field_idx = l.fields().indexFromName('i_will_fail_on_no_name')
self.assertTrue(field_idx >= 0)
# changes by feature id, for changeAttributeValues call
changes = {
feature0.id(): {field_idx: 'no name'},
feature1.id(): {field_idx: 'I have a valid name'}
}
# expect failure
result = l.dataProvider().changeAttributeValues(changes)
self.assertFalse(
result, 'Provider reported success when changing an attribute value that violates a DB level CHECK constraint')

def testChangeGeometries(self):
if not getattr(self, 'getEditableLayer', None):
Expand Down

0 comments on commit 34ec263

Please sign in to comment.