[Erp5-report] r40819 arnaud.fontaine - in /erp5/trunk/products/ERP5Type: Core/ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Mon Nov 29 03:10:35 CET 2010
Author: arnaud.fontaine
Date: Mon Nov 29 03:10:34 2010
New Revision: 40819
URL: http://svn.erp5.org?rev=40819&view=rev
Log:
Add Category Acquired Membership Arity Constraint and its test for
ZODB Property Sheets
Added:
erp5/trunk/products/ERP5Type/Core/CategoryAcquiredMembershipArityConstraint.py
- copied, changed from r40596, erp5/trunk/products/ERP5Type/Constraint/CategoryAcquiredMembershipArity.py
Modified:
erp5/trunk/products/ERP5Type/tests/testDynamicClassGeneration.py
Copied: erp5/trunk/products/ERP5Type/Core/CategoryAcquiredMembershipArityConstraint.py (from r40596, erp5/trunk/products/ERP5Type/Constraint/CategoryAcquiredMembershipArity.py)
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Core/CategoryAcquiredMembershipArityConstraint.py?p2=erp5/trunk/products/ERP5Type/Core/CategoryAcquiredMembershipArityConstraint.py&p1=erp5/trunk/products/ERP5Type/Constraint/CategoryAcquiredMembershipArity.py&r1=40596&r2=40819&rev=40819&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Constraint/CategoryAcquiredMembershipArity.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Core/CategoryAcquiredMembershipArityConstraint.py [utf8] Mon Nov 29 03:10:34 2010
@@ -1,8 +1,9 @@
##############################################################################
#
-# Copyright (c) 2002, 2005 Nexedi SARL and Contributors. All Rights Reserved.
-# Sebastien Robin <seb at nexedi.com>
-# Romain Courteaud <romain at nexedi.com>
+# Copyright (c) 2002-2010 Nexedi SARL and Contributors. All Rights Reserved.
+# Sebastien Robin <seb at nexedi.com>
+# Romain Courteaud <romain at nexedi.com>
+# Arnaud Fontaine <arnaud.fontaine at nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
@@ -27,30 +28,30 @@
#
##############################################################################
-from Constraint import Constraint
-from Products.ERP5Type.Constraint.CategoryMembershipArity \
- import CategoryMembershipArity
+from Products.ERP5Type.Core.CategoryMembershipArityConstraint \
+ import CategoryMembershipArityConstraint
-class CategoryAcquiredMembershipArity(CategoryMembershipArity):
+class CategoryAcquiredMembershipArityConstraint(CategoryMembershipArityConstraint):
"""
- This method checks if an object respects the arity.
+ This constraint checks if an object respects the arity with
+ Acquisition.
- For example we can check if every Order has at least one source.
- Configuration example:
- { 'id' : 'source',
- 'description' : '',
- 'type' : 'CategoryAcquiredMembershipArity',
- 'min_arity' : '1',
- 'max_arity' : '1',
- 'portal_type' : ('Organisation', ),
- 'base_category' : ('source',)
- 'condition' : 'python: object.getPortalType() == 'Foo',
- },
- """
+ This is only relevant for ZODB Property Sheets (filesystem Property
+ Sheets rely on Products.ERP5Type.Constraint.CategoryAcquiredMembershipArity
+ instead).
- def _calculateArity(self, obj):
- base_category = self.constraint_definition['base_category']
- portal_type = self.constraint_definition['portal_type']
- return len(obj.getAcquiredCategoryMembershipList(base_category,
- portal_type=portal_type))
+ For example, if we would like to check whether the object respects a
+ minimum arity of '1' and a maximum arity of '1 for the Portal Type
+ 'Organisation' and the Base Category 'source', then we would create
+ a 'Category Acquired Membership Arity Constraint' within that
+ Property Sheet and set 'Minimum arity' to '1', 'Maximum Arity' to
+ '1', 'Portal Types' to 'Organisation', 'Base Categories' to
+ 'source', then set the 'Predicate' if necessary (known as
+ 'condition' for filesystem Property Sheets).
+ """
+ meta_type = 'ERP5 Category Acquired Membership Arity Constraint'
+ portal_type = 'Category Acquired Membership Arity Constraint'
+ def _calculateArity(self, obj, base_category_list, portal_type_list):
+ return len(obj.getAcquiredCategoryMembershipList(
+ base_category, portal_type=portal_type))
Modified: erp5/trunk/products/ERP5Type/tests/testDynamicClassGeneration.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/testDynamicClassGeneration.py?rev=40819&r1=40818&r2=40819&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/testDynamicClassGeneration.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/tests/testDynamicClassGeneration.py [utf8] Mon Nov 29 03:10:34 2010
@@ -375,19 +375,18 @@ class TestZodbPropertySheet(ERP5TypeTest
portal_type='Content Existence Constraint',
constraint_portal_type='python: ("Content Existence Constraint")')
- def _newCategoryMembershipArityConstraint(self):
+ def _newCategoryMembershipArityConstraint(self, reference, portal_type):
"""
Create a new Category Membership Arity Constraint within test
- Property Sheet
+ Property Sheet, allowing testing of Category Acquired Membership
+ Arity Constraint too
"""
- reference = 'test_category_membership_arity_constraint'
-
self.getPortal().portal_categories.newContent(
id=reference, portal_type='Base Category')
self.test_property_sheet.newContent(
reference=reference,
- portal_type='Category Membership Arity Constraint',
+ portal_type=portal_type,
min_arity=1,
max_arity=1,
constraint_portal_type=('Test Migration',),
@@ -429,7 +428,15 @@ class TestZodbPropertySheet(ERP5TypeTest
# Create a Category Membership Arity Constraint in the test
# Property Sheet
- self._newCategoryMembershipArityConstraint()
+ self._newCategoryMembershipArityConstraint(
+ 'test_category_membership_arity_constraint',
+ 'Category Membership Arity Constraint')
+
+ # Create a Category Acquired Membership Arity Constraint in the
+ # test Property Sheet
+ self._newCategoryMembershipArityConstraint(
+ 'test_category_acquired_membership_arity_constraint',
+ 'Category Acquired Membership Arity Constraint')
# Create all the test Properties
for operation_type in ('change', 'delete', 'assign'):
@@ -875,6 +882,17 @@ class TestZodbPropertySheet(ERP5TypeTest
('test_category_membership_arity_constraint/'\
'Test Migration',))
+ def testCategoryAcquiredMembershipArityConstraint(self):
+ """
+ Take the test module and check whether the Category Acquired
+ Membership Arity Constraint is there. Until a Base Category is set
+ on the Test Module, the constraint should fail
+ """
+ self._checkConstraint(
+ 'test_category_acquired_membership_arity_constraint',
+ self.test_module.setCategoryList,
+ ('test_category_acquired_membership_arity_constraint/Test Migration',))
+
TestZodbPropertySheet = skip("ZODB Property Sheets code is not enabled yet")(
TestZodbPropertySheet)
More information about the Erp5-report
mailing list