From f5117906eace7f0829464defadfe4c4305171a9d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Mon, 20 Mar 2006 18:25:40 +0000
Subject: [PATCH] added tests for fix consistency of properties types

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6151 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/tests/testConstraint.py | 77 ++++++++++++++++++++++--
 1 file changed, 73 insertions(+), 4 deletions(-)

diff --git a/product/ERP5Type/tests/testConstraint.py b/product/ERP5Type/tests/testConstraint.py
index 28e2122a6a..581ebbf878 100755
--- a/product/ERP5Type/tests/testConstraint.py
+++ b/product/ERP5Type/tests/testConstraint.py
@@ -170,7 +170,7 @@ class TestConstraint(ERP5TypeTestCase):
     object_title = self.object_title
     object.edit(title=None)
 
-  def stepSetObjectEmptyTitle(self, sequence=None, 
+  def stepSetObjectEmptyTitle(self, sequence=None,
                               sequence_list=None, **kw):
     """
       Set a different title value
@@ -179,7 +179,7 @@ class TestConstraint(ERP5TypeTestCase):
     object_title = self.object_title
     object.edit(title='')
 
-  def stepSetObjectIntTitle(self, sequence=None, 
+  def stepSetObjectIntTitle(self, sequence=None,
                             sequence_list=None, **kw):
     """
       Set a different title value
@@ -187,6 +187,26 @@ class TestConstraint(ERP5TypeTestCase):
     object = sequence.get('object')
     object_title = self.object_title
     object.edit(title=12345)
+  
+  def stepSetObjectBadTypedProperty(self, sequence=None,
+                            sequence_list=None, **kw):
+    """
+      Set a property with a bad type
+    """
+    object = sequence.get('object')
+    property_name = 'ean13code'
+    # make sure the property is defined on the object
+    self.failUnless(not object.hasProperty(property_name))
+    self.failUnless(object.getPropertyType(property_name) != 'int')
+    object.setProperty(property_name, 12)
+  
+  def stepSetObjectIntLocalProperty(self, sequence=None,
+                            sequence_list=None, **kw):
+    """
+      Set a local property on the object, with an int type.
+    """
+    object = sequence.get('object')
+    object.edit(local_prop = 12345)
 
   def _createGenericConstraint(self, sequence, klass_name='Constraint',
                                **kw):
@@ -217,6 +237,19 @@ class TestConstraint(ERP5TypeTestCase):
     sequence.edit(
         error_list=error_list
     )
+  
+  def stepCallFixConsistency(self, sequence=None,
+                                      sequence_list=None, **kw):
+    """
+      Call checkConsistency of a Constraint, fixing the errors.
+    """
+    object = sequence.get('object')
+    constraint = sequence.get('constraint')
+    # Check
+    error_list = constraint.checkConsistency(object, fixit=1)
+    sequence.edit(
+        error_list=error_list
+    )
 
   def stepCallRelatedCheckConsistency(self, sequence=None, 
                                       sequence_list=None, **kw):
@@ -230,7 +263,7 @@ class TestConstraint(ERP5TypeTestCase):
     sequence.edit(
         error_list=error_list
     )
-
+  
   def stepCheckIfConstraintSucceeded(self, sequence=None, 
                                      sequence_list=None, **kw):
     """
@@ -341,7 +374,7 @@ class TestConstraint(ERP5TypeTestCase):
     sequence_list.addSequenceString(sequence_string)
     # Test Constraint with property defined on object
     # With '' value
-    # Has dissapointing it could be, empty string is a data,
+    # As disapointing as it could be, empty string is a data,
     # and test must succeed
     sequence_string = '\
               CreateObject \
@@ -417,6 +450,17 @@ class TestConstraint(ERP5TypeTestCase):
     sequence_list.addSequenceString(sequence_string)
     # Test Constraint with property defined on object
     # with a bad type
+    sequence_string = '\
+              CreateObject \
+              SetObjectBadTypedProperty \
+              CreatePropertyTypeValidity \
+              CallCheckConsistency \
+              CheckIfConstraintFailed \
+              '
+    sequence_list.addSequenceString(sequence_string)
+    # Test Constraint with property defined on object
+    # with a bad type (title is an exception, because it converts the
+    # value ...)
     sequence_string = '\
               CreateObject \
               SetObjectIntTitle \
@@ -425,6 +469,31 @@ class TestConstraint(ERP5TypeTestCase):
               CheckIfConstraintSucceeded \
               '
     sequence_list.addSequenceString(sequence_string)
+    # Test Fix consistency for property sheet properties
+    sequence_string = '\
+              CreateObject \
+              SetObjectBadTypedProperty \
+              CreatePropertyTypeValidity \
+              CallFixConsistency \
+              CheckIfConstraintFailed \
+              CallCheckConsistency \
+              CheckIfConstraintSucceeded \
+              '
+    sequence_list.addSequenceString(sequence_string)
+    # Test Fix consistency for local properties.
+    # By default, when calling 'edit' with keys not defined in property
+    # sheet, a local property is added on the object and this property
+    # has 'string' type. This sequence depends on this behaviour.
+    sequence_string = '\
+              CreateObject \
+              SetObjectIntLocalProperty \
+              CreatePropertyTypeValidity \
+              CallFixConsistency \
+              CheckIfConstraintFailed \
+              CallCheckConsistency \
+              CheckIfConstraintSucceeded \
+              '
+    sequence_list.addSequenceString(sequence_string)
     sequence_list.play(self)
 
   def stepCreateAttributeEquality0(self, sequence=None, 
-- 
2.30.9