Back to index

plone3  3.1.7
test_rule_management_views.py
Go to the documentation of this file.
00001 from zope.component import getMultiAdapter, getUtility
00002 
00003 from zope.publisher.interfaces.browser import IBrowserPublisher
00004 
00005 from plone.contentrules.engine.interfaces import IRuleStorage
00006 
00007 from plone.app.contentrules.rule import Rule
00008 from plone.app.contentrules.browser.rule import RuleEditForm
00009 
00010 from plone.app.contentrules.tests.base import ContentRulesTestCase
00011 
00012 from dummy import DummyCondition, DummyAction
00013 
00014 
00015 class TestRuleManagementViews(ContentRulesTestCase):
00016 
00017     def afterSetUp(self):
00018         self.setRoles(('Manager',))
00019 
00020     def testRuleAdding(self): 
00021         adding = getMultiAdapter((self.portal, self.portal.REQUEST), name='+rule')
00022         storage = getUtility(IRuleStorage)
00023         self.assertEquals(0, len(storage))
00024         r = Rule()
00025         adding.add(r)
00026         self.assertEquals(1, len(storage))
00027         self.failUnless(storage.values()[0] is r)
00028 
00029     def testRuleAddView(self): 
00030         adding = getMultiAdapter((self.portal, self.portal.REQUEST), name='+rule')
00031         addview = getMultiAdapter((adding, self.portal.REQUEST), name='plone.ContentRule')
00032         storage = getUtility(IRuleStorage)
00033         self.assertEquals(0, len(storage))
00034         addview.createAndAdd({'title' : 'foo', 'description' : 'bar', 'event' : None})
00035         self.assertEquals(1, len(storage))
00036         self.assertEquals('foo', storage.values()[0].title)
00037         
00038     def testRuleEditView(self): 
00039         r = Rule()
00040         editview = getMultiAdapter((r, self.portal.REQUEST), name='edit')
00041         self.failUnless(isinstance(editview, RuleEditForm))
00042 
00043 class TestRuleElementManagementViews(ContentRulesTestCase):
00044 
00045     def afterSetUp(self):
00046         self.setRoles(('Manager',))
00047 
00048     def testRuleConditionAdding(self): 
00049         storage = getUtility(IRuleStorage)
00050         storage[u'foo'] = Rule()
00051         rule = self.portal.restrictedTraverse('++rule++foo')
00052         adding = getMultiAdapter((rule, self.portal.REQUEST), name='+condition')
00053         d = DummyCondition()
00054         self.assertEquals(0, len(rule.conditions))
00055         adding.add(d)
00056         self.assertEquals(1, len(rule.conditions))
00057         self.failUnless(rule.conditions[0] is d)
00058         
00059     def testRuleActionAdding(self): 
00060         storage = getUtility(IRuleStorage)
00061         storage[u'foo'] = Rule()
00062         rule = self.portal.restrictedTraverse('++rule++foo')
00063         adding = getMultiAdapter((rule, self.portal.REQUEST), name='+action')
00064         d = DummyAction()
00065         self.assertEquals(0, len(rule.actions))
00066         adding.add(d)
00067         self.assertEquals(1, len(rule.actions))
00068         self.failUnless(rule.actions[0] is d)
00069         
00070 def test_suite():
00071     from unittest import TestSuite, makeSuite
00072     suite = TestSuite()
00073     suite.addTest(makeSuite(TestRuleManagementViews))
00074     suite.addTest(makeSuite(TestRuleElementManagementViews))
00075     return suite