Back to index

plone3  3.1.7
test_history.py
Go to the documentation of this file.
00001 import unittest
00002 from plone.app.layout.viewlets.tests.base import ViewletsTestCase
00003 from plone.app.layout.viewlets.content import WorkflowHistoryViewlet
00004 from DateTime import DateTime
00005 
00006 class TestWorkflowHistoryViewlet(ViewletsTestCase):
00007     """
00008     Test the workflow history viewlet
00009     """
00010     def afterSetUp(self):
00011         # add document, perform transition, set history for non-existent
00012         # member and also None (anonymous)
00013         self.folder.invokeFactory('Document', 'd1')
00014 
00015     def addMember(self, username, roles=('Member',)):
00016         self.portal.portal_membership.addMember(username, 'secret', roles, [])
00017 
00018     def delMember(self, username):
00019         self.portal.portal_membership.deleteMembers([username])
00020 
00021     def test_emptyHistory(self):
00022         request = self.app.REQUEST
00023         context = getattr(self.folder, 'd1')
00024         viewlet = WorkflowHistoryViewlet(context, request, None, None)
00025         viewlet.update()
00026         self.assertEqual(viewlet.workflowHistory(), [])
00027 
00028     def test_transitionHistory(self):
00029         wf_tool = self.portal.portal_workflow
00030         request = self.app.REQUEST
00031         context = getattr(self.folder, 'd1')
00032         self.loginAsPortalOwner()
00033         wf_tool.doActionFor(context, 'publish')
00034 
00035         viewlet = WorkflowHistoryViewlet(context, request, None, None)
00036         viewlet.update()
00037 
00038         history = viewlet.workflowHistory()
00039         self.assertEqual(len(history), 1)
00040         self.assertEqual(history[0]['action'], 'publish')
00041 
00042         # add a temporary user to perform a transition
00043         self.addMember('tempuser', roles=('Member', 'Manager'))
00044         self.login('tempuser')
00045         wf_tool.doActionFor(context, action='retract', actor=None)
00046         self.logout()
00047 
00048         self.loginAsPortalOwner()
00049 
00050         # remove the user
00051         self.delMember('tempuser')
00052 
00053         # if the user that performed the transition no longer exists, the link
00054         # shouldn't be included.
00055         viewlet = WorkflowHistoryViewlet(context, request, None, None)
00056         viewlet.update()
00057         history = viewlet.workflowHistory()
00058 
00059         self.assertEqual(len(history), 2)
00060         self.assertEqual(history[0]['actor_home'], '')
00061 
00062 
00063 def test_suite():
00064     suite = unittest.TestSuite()
00065     suite.addTest(unittest.makeSuite(TestWorkflowHistoryViewlet))
00066     return suite