Back to index

plone3  3.1.7
test_action_workflow.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.workflow import WorkflowAction
00009 from plone.app.contentrules.actions.workflow import WorkflowEditForm
00010 
00011 from plone.app.contentrules.rule import Rule
00012 
00013 from plone.app.contentrules.tests.base import ContentRulesTestCase
00014 
00015 from zope.component.interfaces import IObjectEvent
00016 
00017 class DummyEvent(object):
00018     implements(IObjectEvent)
00019     
00020     def __init__(self, object):
00021         self.object = object
00022 
00023 class TestWorkflowAction(ContentRulesTestCase):
00024 
00025     def afterSetUp(self):
00026         self.setRoles(('Manager',))
00027         self.folder.invokeFactory('Document', 'd1')
00028 
00029     def testRegistered(self): 
00030         element = getUtility(IRuleAction, name='plone.actions.Workflow')
00031         self.assertEquals('plone.actions.Workflow', element.addview)
00032         self.assertEquals('edit', element.editview)
00033         self.assertEquals(None, element.for_)
00034         self.assertEquals(IObjectEvent, element.event)
00035     
00036     def testInvokeAddView(self): 
00037         element = getUtility(IRuleAction, name='plone.actions.Workflow')
00038         storage = getUtility(IRuleStorage)
00039         storage[u'foo'] = Rule()
00040         rule = self.portal.restrictedTraverse('++rule++foo')
00041         
00042         adding = getMultiAdapter((rule, self.portal.REQUEST), name='+action')
00043         addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview)
00044         
00045         addview.createAndAdd(data={'transition' : 'publish',})
00046         
00047         e = rule.actions[0]
00048         self.failUnless(isinstance(e, WorkflowAction))
00049         self.assertEquals('publish', e.transition)
00050     
00051     def testInvokeEditView(self): 
00052         element = getUtility(IRuleAction, name='plone.actions.Workflow')
00053         e = WorkflowAction()
00054         editview = getMultiAdapter((e, self.folder.REQUEST), name=element.editview)
00055         self.failUnless(isinstance(editview, WorkflowEditForm))
00056 
00057     def testExecute(self): 
00058         e = WorkflowAction()
00059         e.transition = 'publish'
00060         
00061         ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)), IExecutable)
00062         self.assertEquals(True, ex())
00063         
00064         self.assertEquals('published', self.portal.portal_workflow.getInfoFor(self.folder.d1, 'review_state'))
00065         
00066     def testExecuteWithError(self): 
00067         e = WorkflowAction()
00068         e.transition = 'foobar'
00069         
00070         old_state = self.portal.portal_workflow.getInfoFor(self.folder.d1, 'review_state')
00071         
00072         ex = getMultiAdapter((self.folder, e, DummyEvent(self.folder.d1)), IExecutable)
00073         self.assertEquals(False, ex())
00074         
00075         self.assertEquals(old_state, self.portal.portal_workflow.getInfoFor(self.folder.d1, 'review_state'))
00076         
00077 def test_suite():
00078     from unittest import TestSuite, makeSuite
00079     suite = TestSuite()
00080     suite.addTest(makeSuite(TestWorkflowAction))
00081     return suite