[Erp5-report] r18215 - in /erp5/trunk/products/ERP5Type: Constraint/ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Mon Dec 10 18:26:15 CET 2007
Author: jerome
Date: Mon Dec 10 18:26:15 2007
New Revision: 18215
URL: http://svn.erp5.org?rev=18215&view=rev
Log:
Change max_arity to be optional in MembershipArity. Simplify tests
Modified:
erp5/trunk/products/ERP5Type/Constraint/CategoryMembershipArity.py
erp5/trunk/products/ERP5Type/Constraint/CategoryRelatedMembershipArity.py
erp5/trunk/products/ERP5Type/tests/testConstraint.py
Modified: erp5/trunk/products/ERP5Type/Constraint/CategoryMembershipArity.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Constraint/CategoryMembershipArity.py?rev=18215&r1=18214&r2=18215&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Constraint/CategoryMembershipArity.py (original)
+++ erp5/trunk/products/ERP5Type/Constraint/CategoryMembershipArity.py Mon Dec 10 18:26:15 2007
@@ -60,18 +60,26 @@
# Retrieve values inside de PropertySheet (_constraints)
base_category = self.constraint_definition['base_category']
min_arity = int(self.constraint_definition['min_arity'])
- max_arity = int(self.constraint_definition['max_arity'])
+ max_arity = None
+ if 'max_arity' in self.constraint_definition:
+ max_arity = int(self.constraint_definition['max_arity'])
portal_type = self.constraint_definition['portal_type']
# Check arity and compare it with the min and max
- arity = len(obj.getCategoryMembershipList(base_category,
- portal_type=portal_type))
- if (arity < min_arity) or (arity > max_arity):
+ arity = len(obj.getCategoryMembershipList(base_category,
+ portal_type=portal_type))
+ if not (max_arity is None and (min_arity <= arity)
+ or (min_arity <= arity <= max_arity)):
# Generate error message
error_message = "Arity error for relation '%s'" % \
base_category
if portal_type is not ():
error_message += " and portal_type: '%s'" % str(portal_type)
- error_message += \
+ if max_arity is None:
+ error_message += \
+ ", arity is equal to %i but should be at least %i" % \
+ (arity, min_arity)
+ else:
+ error_message += \
", arity is equal to %i but should be between %i and %i" % \
(arity, min_arity, max_arity)
# Add error
Modified: erp5/trunk/products/ERP5Type/Constraint/CategoryRelatedMembershipArity.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Constraint/CategoryRelatedMembershipArity.py?rev=18215&r1=18214&r2=18215&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Constraint/CategoryRelatedMembershipArity.py (original)
+++ erp5/trunk/products/ERP5Type/Constraint/CategoryRelatedMembershipArity.py Mon Dec 10 18:26:15 2007
@@ -61,18 +61,26 @@
# Retrieve values inside de PropertySheet (_constraints)
base_category = self.constraint_definition['base_category']
min_arity = int(self.constraint_definition['min_arity'])
- max_arity = int(self.constraint_definition['max_arity'])
+ max_arity = None
+ if 'max_arity' in self.constraint_definition:
+ max_arity = int(self.constraint_definition['max_arity'])
portal_type = self.constraint_definition['portal_type']
# Check arity and compare it with the min and max
arity = len(obj._getRelatedValueList(base_category,
portal_type=portal_type))
- if (arity < min_arity) or (arity > max_arity):
+ if not (max_arity is None and (min_arity <= arity)
+ or (min_arity <= arity <= max_arity)):
# Generate error message
error_message = "Arrity error for reverse relation '%s'" % \
base_category
if portal_type is not ():
error_message += " and portal_type: '%s'" % str(portal_type)
- error_message += \
+ if max_arity is None:
+ error_message += \
+ ", arity is equal to %i but should be at least %i" % \
+ (arity, min_arity)
+ else:
+ error_message += \
", arity is equal to %i but should be between %i and %i" % \
(arity, min_arity, max_arity)
# Add error
Modified: erp5/trunk/products/ERP5Type/tests/testConstraint.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/testConstraint.py?rev=18215&r1=18214&r2=18215&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/testConstraint.py (original)
+++ erp5/trunk/products/ERP5Type/tests/testConstraint.py Mon Dec 10 18:26:15 2007
@@ -62,6 +62,13 @@
self.category_tool = self.getCategoryTool()
self.createCategories()
+ def beforeTearDown(self):
+ get_transaction().abort()
+ module = self.portal.organisation_module
+ module.manage_delObjects(list(module.objectIds()))
+ get_transaction().commit()
+ self.tic()
+
def stepTic(self,**kw):
self.tic()
@@ -202,7 +209,7 @@
object = sequence.get('object')
object.edit(local_prop = 12345)
- def _createGenericConstraint(self, sequence, klass_name='Constraint',
+ def _createGenericConstraint(self, sequence=None, klass_name='Constraint',
**kw):
"""
Create a Constraint
@@ -215,9 +222,8 @@
klass = file
# klass = getattr(file, klass_name)
constraint = klass(**kw)
- sequence.edit(
- constraint=constraint,
- )
+ if sequence is not None:
+ sequence.edit(constraint=constraint,)
return constraint
def stepCallCheckConsistency(self, sequence=None,
@@ -950,6 +956,19 @@
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self, quiet=quiet)
+ def test_CategoryMembershipArityNoMax(self):
+ obj = self._makeOne()
+ constraint = self._createGenericConstraint(
+ id='dummy_constraint',
+ portal_type=('Category',),
+ base_category=('group',),
+ klass_name='CategoryMembershipArity',
+ min_arity=1)
+ self.assertEquals(1, len(constraint.checkConsistency(obj)))
+ obj.setGroup('testGroup1')
+ self.assertEquals(0, len(constraint.checkConsistency(obj)))
+
+
def stepCreateCategoryRelatedMembershipArity0(self, sequence=None,
sequence_list=None, **kw):
"""
@@ -1065,6 +1084,21 @@
'
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self, quiet=quiet)
+
+ def test_RelatedCategoryMembershipArityNoMax(self):
+ related_obj = self._makeOne()
+ obj = self.portal.portal_categories.group.testGroup1
+ constraint = self._createGenericConstraint(
+ id='dummy_constraint',
+ portal_type=('Organisation',),
+ base_category=('group',),
+ klass_name='CategoryRelatedMembershipArity',
+ min_arity=1)
+ self.assertEquals(1, len(constraint.checkConsistency(obj)))
+ related_obj.setGroupValue(obj)
+ get_transaction().commit()
+ self.tic()
+ self.assertEquals(0, len(constraint.checkConsistency(obj)))
def test_BooleanPropertiesPropertyTypeValidity(self):
"""Tests PropertyTypeValidity can handle boolean values.
@@ -1088,7 +1122,7 @@
def test_TALESConstraint(self):
"""Tests TALESConstraint
"""
- constraint = self._createGenericConstraint(Sequence(),
+ constraint = self._createGenericConstraint(
klass_name='TALESConstraint',
id='tales_constraint',
expression='python: object.getTitle() != "foo"')
@@ -1100,7 +1134,7 @@
def test_TALESConstraintInvalidExpression(self):
"""Tests TALESConstraint with an invalid expression
"""
- constraint = self._createGenericConstraint(Sequence(),
+ constraint = self._createGenericConstraint(
klass_name='TALESConstraint',
id='tales_constraint',
expression='python: None / 3') # ValueError
@@ -1109,14 +1143,14 @@
self.assertEquals(1, len(constraint.checkConsistency(obj)))
# an error during expression compilation is reraised to the programmer
- constraint = self._createGenericConstraint(Sequence(),
+ constraint = self._createGenericConstraint(
klass_name='TALESConstraint',
id='tales_constraint',
expression='python: None (" ')
from Products.PageTemplates.TALES import CompilerError
self.assertRaises(CompilerError, constraint.checkConsistency, obj)
- constraint = self._createGenericConstraint(Sequence(),
+ constraint = self._createGenericConstraint(
klass_name='TALESConstraint',
id='tales_constraint',
expression='error: " ')
@@ -1126,7 +1160,7 @@
"""Tests PropertyTypeValidity can repairs local property when this property
is added on the class later.
"""
- constraint = self._createGenericConstraint(Sequence(),
+ constraint = self._createGenericConstraint(
klass_name='PropertyTypeValidity',
id='type_validity_constraint', )
obj = self._makeOne()
@@ -1144,7 +1178,7 @@
"""Tests PropertyTypeValidity can repairs local property of type content
when this property is added on the class later.
"""
- constraint = self._createGenericConstraint(Sequence(),
+ constraint = self._createGenericConstraint(
klass_name='PropertyTypeValidity',
id='type_validity_constraint', )
obj = self._makeOne()
@@ -1177,7 +1211,7 @@
bc = self.getPortal().portal_categories.newContent(
portal_type='Base Category',
id='testing_category')
- constraint = self._createGenericConstraint(Sequence(),
+ constraint = self._createGenericConstraint(
klass_name='PropertyTypeValidity',
id='type_validity_constraint', )
obj = self._makeOne()
@@ -1307,6 +1341,7 @@
sequence_list.play(self, quiet=quiet)
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestConstraint))
More information about the Erp5-report
mailing list