[Erp5-report] r23566 - in /erp5/trunk/products/ERP5: Document/ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Sep 11 15:26:19 CEST 2008
Author: seb
Date: Thu Sep 11 15:26:15 2008
New Revision: 23566
URL: http://svn.erp5.org?rev=23566&view=rev
Log:
- allow to pass strict_membership parameter to the test method of predicate
- add a test in order to make sure that this parameter is working
Modified:
erp5/trunk/products/ERP5/Document/Predicate.py
erp5/trunk/products/ERP5/tests/testPredicate.py
Modified: erp5/trunk/products/ERP5/Document/Predicate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Predicate.py?rev=23566&r1=23565&r2=23566&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Predicate.py (original)
+++ erp5/trunk/products/ERP5/Document/Predicate.py Thu Sep 11 15:26:15 2008
@@ -83,7 +83,8 @@
__implements__ = ( Interface.Predicate )
security.declareProtected( Permissions.AccessContentsInformation, 'test' )
- def test(self, context, tested_base_category_list=None, **kw):
+ def test(self, context, tested_base_category_list=None,
+ strict_membership=0, **kw):
"""
A Predicate can be tested on a given context.
Parameters can passed in order to ignore some conditions.
@@ -91,6 +92,8 @@
- tested_base_category_list: this is the list of category that we do
want to test. For example, we might want to test only the
destination or the source of a predicate.
+ - if strict_membership is specified, we should make sure that we
+ are strictly a member of tested categories
"""
self = self.asPredicate()
result = 1
@@ -152,13 +155,15 @@
tested_base_category[bc] = 0
if (bc in multimembership_criterion_base_category_list):
tested_base_category[bc] = tested_base_category[bc] and \
- context.isMemberOf(c)
+ context.isMemberOf(c,
+ strict_membership=strict_membership)
# LOG('predicate test', 0,
# '%s after multi membership to %s' % \
# (tested_base_category[bc], c))
elif (bc in membership_criterion_base_category_list):
tested_base_category[bc] = tested_base_category[bc] or \
- context.isMemberOf(c)
+ context.isMemberOf(c,
+ strict_membership=strict_membership)
finally:
if not enabled:
disableReadOnlyTransactionCache(self)
Modified: erp5/trunk/products/ERP5/tests/testPredicate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testPredicate.py?rev=23566&r1=23565&r2=23566&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testPredicate.py (original)
+++ erp5/trunk/products/ERP5/tests/testPredicate.py Thu Sep 11 15:26:15 2008
@@ -300,6 +300,18 @@
membership_criterion_category_list=['region/europe'])
self.assertTrue(pred.test(doc))
+ def test_BasicCategoryMembershipStrict(self):
+ # Check that test method can take into account the strict_membership
+ # parameter
+ doc = self.createDocument(region='europe/western_europe/france',)
+ pred = self.createPredicate(
+ membership_criterion_base_category_list=['region'],
+ membership_criterion_category_list=['region/europe'])
+ self.assertFalse(pred.test(doc, strict_membership=1))
+ pred = self.createPredicate(
+ membership_criterion_base_category_list=['region'],
+ membership_criterion_category_list=['region/europe/western_europe/france'])
+ self.assertTrue(pred.test(doc, strict_membership=1))
def test_BasicCategoryNonMembership(self):
# if the document is not member of the category, the predicate returns
More information about the Erp5-report
mailing list