Commit 5a903e14 authored by Jérome Perrin's avatar Jérome Perrin

PropertyTypeValidity.fixConsistency should remove _local_properties when they

are later defined in a property sheet


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20148 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4339fccf
...@@ -91,6 +91,15 @@ class PropertyTypeValidity(Constraint): ...@@ -91,6 +91,15 @@ class PropertyTypeValidity(Constraint):
property_type = 'lines' property_type = 'lines'
else: else:
property_type = prop['type'] property_type = prop['type']
# if this property was a local property and has been later added in a
# property sheet, we want to remove it from _local_properties
if fixit and \
property_id in [x['id'] for x in obj._local_properties] and \
len([x for x in obj._propertyMap() if x['id'] == property_id]) > 1:
obj._local_properties = tuple([x for x in obj._local_properties
if x['id'] != property_id])
if property_type in self._permissive_type_list: if property_type in self._permissive_type_list:
continue continue
wrong_type = 0 wrong_type = 0
...@@ -134,4 +143,5 @@ class PropertyTypeValidity(Constraint): ...@@ -134,4 +143,5 @@ class PropertyTypeValidity(Constraint):
oldvalue = getattr(obj, property_id, value) oldvalue = getattr(obj, property_id, value)
if oldvalue != value: if oldvalue != value:
obj.setProperty(property_id, oldvalue) obj.setProperty(property_id, oldvalue)
return error_list return error_list
...@@ -1184,23 +1184,45 @@ class TestConstraint(PropertySheetTestCase): ...@@ -1184,23 +1184,45 @@ class TestConstraint(PropertySheetTestCase):
expression='error: " ') expression='error: " ')
self.assertRaises(CompilerError, constraint.checkConsistency, obj) self.assertRaises(CompilerError, constraint.checkConsistency, obj)
def test_PropertyTypeValidityFixLocalProperties(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. is added on the class later, and this property is already in the good type.
""" """
constraint = self._createGenericConstraint( constraint = self._createGenericConstraint(
klass_name='PropertyTypeValidity', klass_name='PropertyTypeValidity',
id='type_validity_constraint', ) id='type_validity_constraint', )
obj = self._makeOne() obj = self._makeOne()
obj.edit(local_property='1') obj.edit(local_property='1')
self.assertEquals(1, len(obj._local_properties))
self.assertEquals([], constraint.checkConsistency(obj)) self.assertEquals([], constraint.checkConsistency(obj))
# now add a 'local_property' property defined on a property sheet # now add a 'local_property' property defined on a property sheet
self._addProperty(obj.getPortalType(), self._addProperty(obj.getPortalType(),
'''{'id': 'local_property', 'type': 'int'}''') '''{'id': 'local_property', 'type': 'string'}''')
constraint.fixConsistency(obj)
self.assertEquals((), obj._local_properties)
self.assertEquals('1', obj.getLocalProperty())
obj.edit(local_property='something else')
self.assertEquals('something else', obj.getLocalProperty())
def test_PropertyTypeValidityFixLocalPropertiesFloat(self):
"""Tests PropertyTypeValidity can repairs local property when this property
is added on the class later, and this property type changed.
"""
constraint = self._createGenericConstraint(
klass_name='PropertyTypeValidity',
id='type_validity_constraint', )
obj = self._makeOne()
obj.edit(local_property=1.234)
self.assertEquals(1, len(obj._local_properties))
#self.assertEquals([], constraint.checkConsistency(obj))
# now add a 'local_property' property defined on a property sheet
self._addProperty(obj.getPortalType(),
'''{'id': 'local_property', 'type': 'float'}''')
constraint.fixConsistency(obj) constraint.fixConsistency(obj)
self.assertEquals(1, obj.getLocalProperty()) self.assertEquals((), obj._local_properties)
self.assertEquals(1.234, obj.getLocalProperty())
obj.edit(local_property=3) obj.edit(local_property=3)
self.assertEquals(3, obj.getLocalProperty()) self.assertEquals(3., obj.getLocalProperty())
def test_PropertyTypeValidityFixLocalPropertiesContent(self): def test_PropertyTypeValidityFixLocalPropertiesContent(self):
"""Tests PropertyTypeValidity can repairs local property of type content """Tests PropertyTypeValidity can repairs local property of type content
......
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