Commit c34fbed4 authored by Tatuya Kamada's avatar Tatuya Kamada

Predicate: Should not create PersitentMappings first time we see Predicate_view.

parent 05b1457f
......@@ -599,6 +599,22 @@ class TestPredicates(TestPredicateMixIn):
test_tales_expression="python: 'france' in here.getRegion()")
self.assertTrue(pred_true.test(doc))
def testPredicateViewWithOutModification(self):
""" Make sure Predicate_view wihout modification does not change
the object."""
predicate = self.createPredicate()
# when init Predicate, they are nothing
self.assertTrue(getattr(predicate, '_identity_criterion', None) is None)
self.assertTrue(getattr(predicate, '_range_criterion', None) is None)
# just view it, does not create PersistentMapping
predicate.Predicate_view()
self.assertTrue(getattr(predicate, '_identity_criterion', None) is None)
self.assertTrue(getattr(predicate, '_range_criterion', None) is None)
# add property and view it, creates PersistentMapping
predicate.setCriterionPropertyList(['quantity'])
predicate.Predicate_view()
self.assertFalse(getattr(predicate, '_identity_criterion', None) is None)
self.assertFalse(getattr(predicate, '_range_criterion', None) is None)
# TODO :
# multi membership category
......
......@@ -381,6 +381,10 @@ class Predicate(XMLObject):
XXX - It would be better to return criteria in a Criterion class
instance
"""
# We do not create PersistentMappings first time we *see* Predicate_view.
# Instead, we create them first time we modify Predicate document.
if not self.getCriterionPropertyList():
return []
if getattr(aq_base(self), '_identity_criterion', None) is None:
self._identity_criterion = PersistentMapping()
self._range_criterion = PersistentMapping()
......
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