Back to index

plone3  3.1.7
test_action_delete.py
Go to the documentation of this file.
00001 from zope.interface import implements, Interface
00002 from zope.component import getUtility, getMultiAdapter
00003 
00004 from plone.contentrules.engine.interfaces import IRuleStorage
00005 from plone.contentrules.rule.interfaces import IRuleAction
00006 from plone.contentrules.rule.interfaces import IExecutable
00007 
00008 from plone.app.contentrules.actions.delete import DeleteAction
00009 
00010 from plone.app.contentrules.rule import Rule
00011 
00012 from plone.app.contentrules.tests.base import ContentRulesTestCase
00013 
00014 from zope.component.interfaces import IObjectEvent
00015 
00016 class DummyEvent(object):
00017     implements(IObjectEvent)
00018     
00019     def __init__(self, object):
00020         self.object = object
00021 
00022 class TestDeleteAction(ContentRulesTestCase):
00023 
00024     def afterSetUp(self):
00025         self.setRoles(('Manager',))
00026         self.folder.invokeFactory('Document', 'd1')
00027 
00028     def testRegistered(self): 
00029         element = getUtility(IRuleAction, name='plone.actions.Delete')
00030         self.assertEquals('plone.actions.Delete', element.addview)
00031         self.assertEquals(None, element.editview)
00032         self.assertEquals(None, element.for_)
00033         self.assertEquals(IObjectEvent, element.event)
00034     
00035     def testInvokeAddView(self): 
00036         element = getUtility(IRuleAction, name='plone.actions.Delete')
00037         storage = getUtility(IRuleStorage)
00038         storage[u'foo'] = Rule()
00039         rule = self.portal.restrictedTraverse('++rule++foo')
00040         
00041         adding = getMultiAdapter((rule.__of__(self.portal), self.portal.REQUEST), name='+action')
00042         addview = getMultiAdapter((adding.__of__(rule), self.portal.REQUEST), name=element.addview)
00043         addview()
00044         
00045         e = rule.actions[0]
00046         self.failUnless(isinstance(e, DeleteAction))
00047     
00048     def testExecute(self): 
00049         e = DeleteAction()
00050         
00051         ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)), IExecutable)
00052         self.assertEquals(True, ex())
00053         
00054         self.failIf('d1' in self.folder.objectIds())
00055         
00056         
00057 def test_suite():
00058     from unittest import TestSuite, makeSuite
00059     suite = TestSuite()
00060     suite.addTest(makeSuite(TestDeleteAction))
00061     return suite