[Erp5-report] r40830 arnaud.fontaine - in /erp5/trunk/products/ERP5Type: Core/ PropertyShee...
nobody at svn.erp5.org
nobody at svn.erp5.org
Mon Nov 29 08:56:46 CET 2010
Author: arnaud.fontaine
Date: Mon Nov 29 08:56:46 2010
New Revision: 40830
URL: http://svn.erp5.org?rev=40830&view=rev
Log:
Add Category Related Membership Arity Constraint for ZODB Property
Sheets and its test
Added:
erp5/trunk/products/ERP5Type/Core/CategoryRelatedMembershipArityConstraint.py
- copied, changed from r40818, erp5/trunk/products/ERP5Type/Constraint/CategoryRelatedMembershipArity.py
erp5/trunk/products/ERP5Type/PropertySheet/CategoryRelatedMembershipArityConstraint.py
Modified:
erp5/trunk/products/ERP5Type/PropertySheet/__init__.py
erp5/trunk/products/ERP5Type/tests/testDynamicClassGeneration.py
Copied: erp5/trunk/products/ERP5Type/Core/CategoryRelatedMembershipArityConstraint.py (from r40818, erp5/trunk/products/ERP5Type/Constraint/CategoryRelatedMembershipArity.py)
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Core/CategoryRelatedMembershipArityConstraint.py?p2=erp5/trunk/products/ERP5Type/Core/CategoryRelatedMembershipArityConstraint.py&p1=erp5/trunk/products/ERP5Type/Constraint/CategoryRelatedMembershipArity.py&r1=40818&r2=40830&rev=40830&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Constraint/CategoryRelatedMembershipArity.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Core/CategoryRelatedMembershipArityConstraint.py [utf8] Mon Nov 29 08:56:46 2010
@@ -4,6 +4,7 @@
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Sebastien Robin <seb at nexedi.com>
# Courteaud Romain <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
@@ -28,38 +29,47 @@
#
##############################################################################
-from Constraint import Constraint
-from Products.ERP5Type.Constraint.CategoryMembershipArity \
- import CategoryMembershipArity
+from Products.ERP5Type import PropertySheet
+from Products.ERP5Type.Core.CategoryMembershipArityConstraint \
+ import CategoryMembershipArityConstraint
-class CategoryRelatedMembershipArity(CategoryMembershipArity):
+class CategoryRelatedMembershipArityConstraint(CategoryMembershipArityConstraint):
"""
- This method checks if an object respects the arity from a category reverse
- membership point of view.
+ This constraint checks if an object respects the arity from a
+ category reverse membership point of view. 'filter_parameter' is an
+ additional parameters passed to catalog.
+
+ This is only relevant for ZODB Property Sheets (filesystem Property
+ Sheets rely on Products.ERP5Type.Constraint.CategoryRelatedMembershipArity
+ instead).
+
+ For example, if we would like to check whether the object respects a
+ minimum arity of '1', a maximum arity of '1', and with a filter
+ parameter 'simulation_state': ('planned',)' for the Portal Type
+ 'Organisation' and the Base Category 'source', then we would create
+ a 'Category Related Membership Arity Constraint' within that
+ Property Sheet and set 'Minimum arity' to '1', 'Maximum Arity' to
+ '1', 'Filter parameters' to 'python: {'simulation_state':
+ ('planned',)}' '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 Related Membership Arity Constraint'
+ portal_type = 'Category Related Membership Arity Constraint'
- For example we can check if every Order has at
- most one Order Applied Rule.
- Configuration example:
- { 'id' : 'applied_rule',
- 'description' : 'There must at most one Applied Rule using this order',
- 'type' : 'CategoryRelatedMembershipArity',
- 'min_arity' : '1',
- 'max_arity' : '1',
- 'portal_type' : ('Applied Rule', ),
- 'base_category' : ('causality',)
- 'condition' : 'python: object.getPortalType() == 'Foo',
- },
+ property_sheets = CategoryMembershipArityConstraint.property_sheets + \
+ (PropertySheet.CategoryRelatedMembershipArityConstraint,)
- additional parameters passed to catalog are accepted:
- 'filter_parameter': {'simulation_state': ('planned',)},
- """
+ def _calculateArity(self, obj, base_category_list, portal_type_list):
+ # XXX: Only supports one category, the code with filesystem
+ # Property Sheets assumes that 'base_category' is not a tuple but
+ # a string
+ assert len(base_category_list) != 0
+
+ sql_kw = {'portal_type': portal_type_list,
+ '%s_uid' % base_category_list[0]: obj.getUid()}
+
+ sql_kw.update(self._getExpressionValue(obj, self.getFilterParameter()))
- def _calculateArity(self, obj):
- base_category = self.constraint_definition['base_category']
- sql_kw = {'portal_type': self.constraint_definition['portal_type'],
- '%s_uid' % base_category: obj.getUid()}
- filter_parameter = self.constraint_definition.get('filter_parameter', {})
- sql_kw.update(filter_parameter)
portal = obj.getPortalObject()
return len(portal.portal_catalog.unrestrictedSearchResults(**sql_kw))
-
Added: erp5/trunk/products/ERP5Type/PropertySheet/CategoryRelatedMembershipArityConstraint.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/PropertySheet/CategoryRelatedMembershipArityConstraint.py?rev=40830&view=auto
==============================================================================
--- erp5/trunk/products/ERP5Type/PropertySheet/CategoryRelatedMembershipArityConstraint.py (added)
+++ erp5/trunk/products/ERP5Type/PropertySheet/CategoryRelatedMembershipArityConstraint.py [utf8] Mon Nov 29 08:56:46 2010
@@ -0,0 +1,42 @@
+##############################################################################
+#
+# Copyright (c) 2010 Nexedi SARL and Contributors. All Rights Reserved.
+# 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
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+##############################################################################
+
+class CategoryRelatedMembershipArityConstraint:
+ """
+ Define a Category Related Membership Arity Constraint for ZODB
+ Property Sheets
+
+ @see CategoryMembershipArityConstraint
+ """
+ # TALES Expression
+ _properties = (
+ { 'id': 'filter_parameter',
+ 'type': 'string',
+ 'description' : 'Addition parameters passed to catalog',
+ 'default': 'python: {}' },
+ )
Modified: erp5/trunk/products/ERP5Type/PropertySheet/__init__.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/PropertySheet/__init__.py?rev=40830&r1=40829&r2=40830&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/PropertySheet/__init__.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/PropertySheet/__init__.py [utf8] Mon Nov 29 08:56:46 2010
@@ -22,3 +22,5 @@ from PropertyExistenceConstraint import
from AttributeEqualityConstraint import AttributeEqualityConstraint
from ContentExistenceConstraint import ContentExistenceConstraint
from CategoryMembershipArityConstraint import CategoryMembershipArityConstraint
+from CategoryRelatedMembershipArityConstraint import \
+ CategoryRelatedMembershipArityConstraint
Modified: erp5/trunk/products/ERP5Type/tests/testDynamicClassGeneration.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/testDynamicClassGeneration.py?rev=40830&r1=40829&r2=40830&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/testDynamicClassGeneration.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/tests/testDynamicClassGeneration.py [utf8] Mon Nov 29 08:56:46 2010
@@ -436,6 +436,20 @@ class TestZodbPropertySheet(ERP5TypeTest
constraint_portal_type=('Test Migration',),
constraint_base_category=(reference,))
+ def _newCategoryRelatedMembershipArityConstraint(self):
+ """
+ Create a new Category Related Membership Arity Constraint within
+ test Property Sheet, using an existing Base Category because
+ creating a new Base Category would involve clearing up the cache
+ """
+ self.test_property_sheet.newContent(
+ reference='test_category_related_membership_arity_constraint',
+ portal_type='Category Related Membership Arity Constraint',
+ min_arity=1,
+ max_arity=1,
+ constraint_portal_type=('Test Migration',),
+ constraint_base_category=('gender',))
+
def afterSetUp(self):
"""
Create a test Property Sheet (and its properties)
@@ -482,6 +496,10 @@ class TestZodbPropertySheet(ERP5TypeTest
'test_category_acquired_membership_arity_constraint',
'Category Acquired Membership Arity Constraint')
+ # Create a Category Related Membership Arity Constraint in the
+ # test Property Sheet
+ self._newCategoryRelatedMembershipArityConstraint()
+
# Create all the test Properties
for operation_type in ('change', 'delete', 'assign'):
self._newStandardProperty(operation_type)
@@ -525,11 +543,6 @@ class TestZodbPropertySheet(ERP5TypeTest
# Ensure that erp5.acessor_holder is empty
synchronizeDynamicModules(portal, force=True)
- # Make sure there is no pending transaction which could interfere
- # with the tests
- transaction.commit()
- self.tic()
-
def _forceTestAccessorHolderGeneration(self):
"""
Force generation of TestMigration accessor holder by accessing any
@@ -931,12 +944,34 @@ class TestZodbPropertySheet(ERP5TypeTest
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
+
+ XXX: Test with acquisition?
"""
self._checkConstraint(
'test_category_acquired_membership_arity_constraint',
self.test_module.setCategoryList,
('test_category_acquired_membership_arity_constraint/Test Migration',))
+ def testCategoryRelatedMembershipArityConstraint(self):
+ """
+ Take the test module and check whether the Category Related
+ Membership Arity Constraint is there. Until a Base Category is set
+ on the Test Module, the constraint should fail
+
+ XXX: Test filter_parameter
+ """
+ constraint = self._getConstraintByReference(
+ 'test_category_related_membership_arity_constraint')
+
+ self.failIfEqual(None, constraint)
+ self.assertEquals(1, len(constraint.checkConsistency(self.test_module)))
+
+ self.test_module.setCategoryList(('gender/Test Migration',))
+ transaction.commit()
+ self.tic()
+
+ self.assertEquals([], constraint.checkConsistency(self.test_module))
+
TestZodbPropertySheet = skip("ZODB Property Sheets code is not enabled yet")(
TestZodbPropertySheet)
More information about the Erp5-report
mailing list