Back to index

plone3  3.1.7
test_one_state_workflow.py
Go to the documentation of this file.
00001 #
00002 # Tests the one state workflow
00003 #
00004 
00005 from Products.CMFPlone.tests import PloneTestCase
00006 from base import WorkflowTestCase
00007 
00008 from Products.CMFCore.WorkflowCore import WorkflowException
00009 
00010 from Products.CMFCore.utils import _checkPermission as checkPerm
00011 from Products.CMFCore.permissions import AccessContentsInformation
00012 from Products.CMFCore.permissions import View
00013 from Products.CMFCore.permissions import ListFolderContents
00014 from Products.CMFCore.permissions import ModifyPortalContent
00015 from Products.CMFCalendar.permissions import ChangeEvents
00016 
00017 
00018 default_user = PloneTestCase.default_user
00019 
00020 
00021 class TestOneStateWorkflow(WorkflowTestCase):
00022 
00023 
00024     def afterSetUp(self):
00025         self.catalog = self.portal.portal_catalog
00026         self.workflow = self.portal.portal_workflow
00027         self.workflow.setChainForPortalTypes(['Document','Event'], 'one_state_workflow')
00028 
00029         self.portal.acl_users._doAddUser('member', 'secret', ['Member'], [])
00030         self.portal.acl_users._doAddUser('reviewer', 'secret', ['Reviewer'], [])
00031         self.portal.acl_users._doAddUser('manager', 'secret', ['Manager'], [])
00032         self.portal.acl_users._doAddUser('editor' , ' secret', ['Editor'],[])
00033         self.portal.acl_users._doAddUser('reader', 'secret', ['Reader'], [])
00034 
00035 
00036         self.folder.invokeFactory('Document', id='doc')
00037         self.doc = self.folder.doc
00038         self.folder.invokeFactory('Event', id='ev')
00039         self.ev = self.folder.ev
00040 
00041     # Check allowed transitions: none for one state workflow
00042 
00043     def testInitialState(self):
00044         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'published')
00045         self.assertEqual(self.workflow.getInfoFor(self.ev, 'review_state'), 'published')
00046 
00047     # Check view permission
00048 
00049     def testViewIsNotAcquiredInPublishedState(self):
00050         self.assertEqual(self.doc.acquiredRolesAreUsedBy(View), '')   # not checked
00051 
00052     def testViewPublishedDocument(self):
00053         # Owner is allowed
00054         self.login(default_user)
00055         self.failUnless(checkPerm(View, self.doc))
00056         # Member is allowed
00057         self.login('member')
00058         self.failUnless(checkPerm(View, self.doc))
00059         # Reviewer is allowed
00060         self.login('reviewer')
00061         self.failUnless(checkPerm(View, self.doc))
00062         # Anonymous is allowed
00063         self.logout()
00064         self.failUnless(checkPerm(View, self.doc))
00065         # Editor is allowed
00066         self.login('editor')
00067         self.failUnless(checkPerm(View, self.doc))
00068         # Reader is allowed
00069         self.login('reader')
00070         self.failUnless(checkPerm(View, self.doc))
00071 
00072     # Check access contents info permission
00073 
00074     def testAccessContentsInformationIsNotAcquiredInPublishedState(self):
00075         self.assertEqual(self.doc.acquiredRolesAreUsedBy(AccessContentsInformation), '')   # not checked
00076 
00077     def testAccessPublishedDocument(self):
00078         # Owner is allowed
00079         self.login(default_user)
00080         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00081         # Member is allowed
00082         self.login('member')
00083         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00084         # Reviewer is allowed
00085         self.login('reviewer')
00086         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00087         # Anonymous is allowed
00088         self.logout()
00089         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00090         # Editor is allowed
00091         self.login('editor')
00092         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00093         # Reader is allowed
00094         self.login('reader')
00095         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00096 
00097     def testModifyPortalContentIsNotAcquiredInPublishedState(self):
00098         self.assertEqual(self.doc.acquiredRolesAreUsedBy(ModifyPortalContent), '')
00099 
00100     def testModifyPublishedDocument(self):
00101         # Owner is allowed
00102         self.login(default_user)
00103         self.failUnless(checkPerm(ModifyPortalContent, self.doc))
00104         # Member is denied
00105         self.login('member')
00106         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00107         # Reviewer is denied
00108         self.login('reviewer')
00109         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00110         # Anonymous is denied
00111         self.logout()
00112         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00113         # Editor is allowed
00114         self.login('editor')
00115         self.failUnless(checkPerm(ModifyPortalContent, self.doc))
00116         # Reader is denied
00117         self.login('reader')
00118         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00119 
00120     # Check change events permission
00121 
00122     def testChangeEventsIsNotAcquiredInPublishedState(self):
00123         self.assertEqual(self.ev.acquiredRolesAreUsedBy(ChangeEvents), '')
00124 
00125     def testModifyPublishEvent(self):
00126         # Owner is allowed
00127         self.failUnless(checkPerm(ChangeEvents, self.ev))
00128         # Member is denied
00129         self.login('member')
00130         self.failIf(checkPerm(ChangeEvents, self.ev))
00131         # Reviewer is denied
00132         self.login('reviewer')
00133         self.failIf(checkPerm(ChangeEvents, self.ev))
00134         # Anonymous is denied
00135         self.logout()
00136         self.failIf(checkPerm(ChangeEvents, self.ev))
00137         # Editor is allowed
00138         self.login('editor')
00139         self.failUnless(checkPerm(ChangeEvents, self.ev))
00140         # Reader is denied
00141         self.login('reader')
00142         self.failIf(checkPerm(ChangeEvents, self.ev))
00143 
00144 
00145 def test_suite():
00146     from unittest import TestSuite, makeSuite
00147     suite = TestSuite()
00148     suite.addTest(makeSuite(TestOneStateWorkflow))
00149     return suite