[Erp5-report] r20148 - in /erp5/trunk/products/ERP5Type: Constraint/ tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Mar 26 15:14:53 CET 2008


Author: jerome
Date: Wed Mar 26 15:14:52 2008
New Revision: 20148

URL: http://svn.erp5.org?rev=20148&view=rev
Log:
PropertyTypeValidity.fixConsistency should remove _local_properties when they
are later defined in a property sheet

Modified:
    erp5/trunk/products/ERP5Type/Constraint/PropertyTypeValidity.py
    erp5/trunk/products/ERP5Type/tests/testConstraint.py

Modified: erp5/trunk/products/ERP5Type/Constraint/PropertyTypeValidity.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Constraint/PropertyTypeValidity.py?rev=20148&r1=20147&r2=20148&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Constraint/PropertyTypeValidity.py (original)
+++ erp5/trunk/products/ERP5Type/Constraint/PropertyTypeValidity.py Wed Mar 26 15:14:52 2008
@@ -91,6 +91,15 @@
         property_type = 'lines'
       else:
         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:
         continue
       wrong_type = 0
@@ -134,4 +143,5 @@
         oldvalue = getattr(obj, property_id, value)
         if oldvalue != value:
           obj.setProperty(property_id, oldvalue)
+
     return error_list

Modified: erp5/trunk/products/ERP5Type/tests/testConstraint.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/testConstraint.py?rev=20148&r1=20147&r2=20148&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/testConstraint.py (original)
+++ erp5/trunk/products/ERP5Type/tests/testConstraint.py Wed Mar 26 15:14:52 2008
@@ -1184,23 +1184,45 @@
                    expression='error: " ')
     self.assertRaises(CompilerError, constraint.checkConsistency, obj)
   
-  def test_PropertyTypeValidityFixLocalProperties(self):
+  def test_PropertyTypeValidityFixLocalPropertiesString(self):
     """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(
                    klass_name='PropertyTypeValidity',
                    id='type_validity_constraint', )
     obj = self._makeOne()
     obj.edit(local_property='1')
+    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': 'int'}''')
+                  '''{'id': 'local_property', 'type': 'string'}''')
     constraint.fixConsistency(obj)
-    self.assertEquals(1, obj.getLocalProperty())
+    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)
+    self.assertEquals((), obj._local_properties)
+    self.assertEquals(1.234, obj.getLocalProperty())
     obj.edit(local_property=3)
-    self.assertEquals(3, obj.getLocalProperty())
+    self.assertEquals(3., obj.getLocalProperty())
   
   def test_PropertyTypeValidityFixLocalPropertiesContent(self):
     """Tests PropertyTypeValidity can repairs local property of type content




More information about the Erp5-report mailing list