Back to index

plone3  3.1.7
test_traversal.py
Go to the documentation of this file.
00001 from zope.component import getMultiAdapter, getUtility
00002 from zope.publisher.interfaces.browser import IBrowserPublisher
00003 
00004 from Acquisition import aq_base, aq_parent, Explicit
00005 
00006 from plone.contentrules.engine.interfaces import IRuleStorage
00007 
00008 from plone.app.contentrules.rule import Rule
00009 from plone.app.contentrules.tests.base import ContentRulesTestCase
00010 
00011 from dummy import DummyCondition, DummyAction
00012 
00013 class TestTraversal(ContentRulesTestCase):
00014 
00015     def afterSetUp(self):
00016         self.setRoles(('Manager',))
00017 
00018     def testTraverseToRule(self):
00019         r = Rule()
00020         storage = getUtility(IRuleStorage)
00021         storage[u'r1'] = r
00022         traversed = self.portal.restrictedTraverse('++rule++r1')
00023         self.failUnless(aq_parent(traversed) is self.portal)
00024         self.failUnless(aq_base(traversed) is r)
00025     
00026     def testTraverseToRuleCondition(self): 
00027         r = Rule()
00028         e1 = DummyCondition()
00029         e1.x = "x"
00030         
00031         e2 = DummyCondition()
00032         e2.x = "y"
00033         
00034         r.conditions.append(e1)
00035         r.conditions.append(e2)
00036         storage = getUtility(IRuleStorage)
00037         storage[u'r1'] = r
00038         
00039         tr = self.portal.restrictedTraverse('++rule++r1')
00040         te1 = tr.restrictedTraverse('++condition++0')
00041         te2 = tr.restrictedTraverse('++condition++1')
00042         
00043         self.failUnless(aq_parent(te1) is tr)
00044         self.assertEquals("x", te1.x)
00045         
00046         self.failUnless(aq_parent(te2) is tr)
00047         self.assertEquals("y", te2.x)
00048 
00049     def testTraverseToRuleAction(self): 
00050         r = Rule()
00051         e1 = DummyAction()
00052         e1.x = "x"
00053         
00054         e2 = DummyAction()
00055         e2.x = "y"
00056         
00057         r.actions.append(e1)
00058         r.actions.append(e2)
00059         storage = getUtility(IRuleStorage)
00060         storage[u'r1'] = r
00061         
00062         tr = self.portal.restrictedTraverse('++rule++r1')
00063         te1 = tr.restrictedTraverse('++action++0')
00064         te2 = tr.restrictedTraverse('++action++1')
00065         
00066         self.failUnless(aq_parent(te1) is tr)
00067         self.assertEquals("x", te1.x)
00068         
00069         self.failUnless(aq_parent(te2) is tr)
00070         self.assertEquals("y", te2.x)        
00071         
00072 def test_suite():
00073     from unittest import TestSuite, makeSuite
00074     suite = TestSuite()
00075     suite.addTest(makeSuite(TestTraversal))
00076     return suite