Commit 3dab2e92 authored by Łukasz Nowak's avatar Łukasz Nowak

Ignore no local properties while fixing.

parent 89f275b4
...@@ -81,6 +81,7 @@ class PropertyTypeValidity(Constraint): ...@@ -81,6 +81,7 @@ class PropertyTypeValidity(Constraint):
error_list = [] error_list = []
# For each attribute name, we check type # For each attribute name, we check type
for prop in obj.propertyMap(): for prop in obj.propertyMap():
property_was_local = False
property_id = prop['id'] property_id = prop['id']
if prop.get('multivalued', 0): if prop.get('multivalued', 0):
property_type = 'lines' property_type = 'lines'
...@@ -95,6 +96,7 @@ class PropertyTypeValidity(Constraint): ...@@ -95,6 +96,7 @@ class PropertyTypeValidity(Constraint):
len([x for x in obj._propertyMap() if x['id'] == property_id]) > 1: len([x for x in obj._propertyMap() if x['id'] == property_id]) > 1:
obj._local_properties = tuple([x for x in obj._local_properties obj._local_properties = tuple([x for x in obj._local_properties
if x['id'] != property_id]) if x['id'] != property_id])
property_was_local = True
if property_type in self._permissive_type_list: if property_type in self._permissive_type_list:
continue continue
...@@ -135,7 +137,7 @@ class PropertyTypeValidity(Constraint): ...@@ -135,7 +137,7 @@ class PropertyTypeValidity(Constraint):
error_list.append(self._generateError(obj, error_list.append(self._generateError(obj,
self._getMessage(error_message), mapping)) self._getMessage(error_message), mapping))
elif fixit: elif fixit and property_was_local:
oldvalue = getattr(obj, property_id, value) oldvalue = getattr(obj, property_id, value)
if oldvalue != value: if oldvalue != value:
error_list.append(self._generateError(obj, error_list.append(self._generateError(obj,
......
...@@ -1178,6 +1178,27 @@ class TestConstraint(PropertySheetTestCase): ...@@ -1178,6 +1178,27 @@ class TestConstraint(PropertySheetTestCase):
expression='error: " ') expression='error: " ')
self.assertRaises(CompilerError, constraint.checkConsistency, obj) self.assertRaises(CompilerError, constraint.checkConsistency, obj)
def test_PropertyTypeValidityFixLocalPropertiesIgnoresNoLocal(self):
"""Tests PropertyTypeValidity can repairs local property when this property
is added on the class later, and this property is already in the good type.
"""
constraint = self._createGenericConstraint(
klass_name='PropertyTypeValidity',
id='type_validity_constraint', )
obj = self._makeOne()
self._addProperty(obj.getPortalType(), "FixLocalPropertiesString",
portal_type="Standard Property",
property_id="local_property",
elementary_type="string")
obj.edit(local_property='1')
self.assertFalse('_local_properties' in obj.__dict__)
self.assertEquals([], constraint.checkConsistency(obj))
self.assertEqual([], constraint.fixConsistency(obj))
self.assertFalse('_local_properties' in obj.__dict__)
self.assertEquals('1', obj.getLocalProperty())
obj.edit(local_property='something else')
self.assertEquals('something else', obj.getLocalProperty())
def test_PropertyTypeValidityFixLocalPropertiesString(self): def test_PropertyTypeValidityFixLocalPropertiesString(self):
"""Tests PropertyTypeValidity can repairs local property when this property """Tests PropertyTypeValidity can repairs local property when this property
is added on the class later, and this property is already in the good type. is added on the class later, and this property is already in the good type.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment