Back to index

plone3  3.1.7
test_condition_wftransition.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 zope.component.interfaces import IObjectEvent
00005 
00006 from plone.contentrules.engine.interfaces import IRuleStorage
00007 from plone.contentrules.rule.interfaces import IRuleCondition
00008 from plone.contentrules.rule.interfaces import IExecutable
00009 
00010 from plone.app.contentrules.conditions.wftransition import WorkflowTransitionCondition
00011 from plone.app.contentrules.conditions.wftransition import WorkflowTransitionEditForm
00012 
00013 from plone.app.contentrules.rule import Rule
00014 
00015 from plone.app.contentrules.tests.base import ContentRulesTestCase
00016 
00017 from Products.CMFCore.interfaces import IActionSucceededEvent
00018 from Products.CMFCore.WorkflowCore import ActionSucceededEvent
00019 
00020 class TestWorkflowTransitionCondition(ContentRulesTestCase):
00021 
00022     def afterSetUp(self):
00023         self.setRoles(('Manager',))
00024 
00025     def testRegistered(self): 
00026         element = getUtility(IRuleCondition, name='plone.conditions.WorkflowTransition')
00027         self.assertEquals('plone.conditions.WorkflowTransition', element.addview)
00028         self.assertEquals('edit', element.editview)
00029         self.assertEquals(None, element.for_)
00030         self.assertEquals(IActionSucceededEvent, element.event)
00031     
00032     def testInvokeAddView(self): 
00033         element = getUtility(IRuleCondition, name='plone.conditions.WorkflowTransition')
00034         storage = getUtility(IRuleStorage)
00035         storage[u'foo'] = Rule()
00036         rule = self.portal.restrictedTraverse('++rule++foo')
00037         
00038         adding = getMultiAdapter((rule, self.portal.REQUEST), name='+condition')
00039         addview = getMultiAdapter((adding, self.portal.REQUEST), name=element.addview)
00040         
00041         addview.createAndAdd(data={'wf_transitions' : ['publish', 'hide']})
00042         
00043         e = rule.conditions[0]
00044         self.failUnless(isinstance(e, WorkflowTransitionCondition))
00045         self.assertEquals(['publish', 'hide'], e.wf_transitions)
00046     
00047     def testInvokeEditView(self): 
00048         element = getUtility(IRuleCondition, name='plone.conditions.WorkflowTransition')
00049         e = WorkflowTransitionCondition()
00050         editview = getMultiAdapter((e, self.folder.REQUEST), name=element.editview)
00051         self.failUnless(isinstance(editview, WorkflowTransitionEditForm))
00052 
00053     def testExecute(self): 
00054         e = WorkflowTransitionCondition()
00055         e.wf_transitions = ['publish', 'hide']
00056         
00057         ex = getMultiAdapter((self.portal, e, ActionSucceededEvent(self.folder, 'dummy_workflow', 'publish', None)), IExecutable)
00058         self.assertEquals(True, ex())
00059         
00060         ex = getMultiAdapter((self.portal, e, ActionSucceededEvent(self.folder, 'dummy_workflow', 'retract', None)), IExecutable)
00061         self.assertEquals(False, ex())
00062         
00063         ex = getMultiAdapter((self.portal, e, ActionSucceededEvent(self.folder, 'dummy_workflow', 'hide', None)), IExecutable)
00064         self.assertEquals(True, ex())
00065         
00066 def test_suite():
00067     from unittest import TestSuite, makeSuite
00068     suite = TestSuite()
00069     suite.addTest(makeSuite(TestWorkflowTransitionCondition))
00070     return suite