Commit 8bdf0da3 authored by Sebastien Robin's avatar Sebastien Robin

- 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


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@23566 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 623c2a34
...@@ -83,7 +83,8 @@ class Predicate(XMLObject, Folder): ...@@ -83,7 +83,8 @@ class Predicate(XMLObject, Folder):
__implements__ = ( Interface.Predicate ) __implements__ = ( Interface.Predicate )
security.declareProtected( Permissions.AccessContentsInformation, 'test' ) 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. A Predicate can be tested on a given context.
Parameters can passed in order to ignore some conditions. Parameters can passed in order to ignore some conditions.
...@@ -91,6 +92,8 @@ class Predicate(XMLObject, Folder): ...@@ -91,6 +92,8 @@ class Predicate(XMLObject, Folder):
- tested_base_category_list: this is the list of category that we do - 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 want to test. For example, we might want to test only the
destination or the source of a predicate. 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() self = self.asPredicate()
result = 1 result = 1
...@@ -152,13 +155,15 @@ class Predicate(XMLObject, Folder): ...@@ -152,13 +155,15 @@ class Predicate(XMLObject, Folder):
tested_base_category[bc] = 0 tested_base_category[bc] = 0
if (bc in multimembership_criterion_base_category_list): if (bc in multimembership_criterion_base_category_list):
tested_base_category[bc] = tested_base_category[bc] and \ tested_base_category[bc] = tested_base_category[bc] and \
context.isMemberOf(c) context.isMemberOf(c,
strict_membership=strict_membership)
# LOG('predicate test', 0, # LOG('predicate test', 0,
# '%s after multi membership to %s' % \ # '%s after multi membership to %s' % \
# (tested_base_category[bc], c)) # (tested_base_category[bc], c))
elif (bc in membership_criterion_base_category_list): elif (bc in membership_criterion_base_category_list):
tested_base_category[bc] = tested_base_category[bc] or \ tested_base_category[bc] = tested_base_category[bc] or \
context.isMemberOf(c) context.isMemberOf(c,
strict_membership=strict_membership)
finally: finally:
if not enabled: if not enabled:
disableReadOnlyTransactionCache(self) disableReadOnlyTransactionCache(self)
......
...@@ -300,6 +300,18 @@ class TestPredicates(TestPredicateMixIn): ...@@ -300,6 +300,18 @@ class TestPredicates(TestPredicateMixIn):
membership_criterion_category_list=['region/europe']) membership_criterion_category_list=['region/europe'])
self.assertTrue(pred.test(doc)) 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): def test_BasicCategoryNonMembership(self):
# if the document is not member of the category, the predicate returns # if the document is not member of the category, the predicate returns
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment