Back to index

plone3  3.1.7
test_simple_publication_workflow.py
Go to the documentation of this file.
00001 #
00002 # Tests about the Simple publication 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 ModifyPortalContent
00014 from Products.CMFCalendar.permissions import ChangeEvents
00015 
00016 default_user = PloneTestCase.default_user
00017 
00018 
00019 class TestSimplePublicationWorkflow(WorkflowTestCase):
00020 
00021     def afterSetUp(self):
00022         self.catalog = self.portal.portal_catalog
00023         self.workflow = self.portal.portal_workflow
00024         self.workflow.setChainForPortalTypes(['Document','Event'], 'simple_publication_workflow')
00025 
00026         self.portal.acl_users._doAddUser('member', 'secret', ['Member'], [])
00027         self.portal.acl_users._doAddUser('reviewer', 'secret', ['Reviewer'], [])
00028         self.portal.acl_users._doAddUser('manager', 'secret', ['Manager'], [])
00029         self.portal.acl_users._doAddUser('editor' , ' secret', ['Editor'],[])
00030         self.portal.acl_users._doAddUser('reader', 'secret', ['Reader'], [])
00031 
00032         self.folder.invokeFactory('Document', id='doc')
00033         self.doc = self.folder.doc
00034         self.folder.invokeFactory('Event', id='ev')
00035         self.ev = self.folder.ev
00036 
00037     # Check allowed transitions: two for simple publication workflow
00038 
00039     def testOwnerSubmitAPrivateDocumentAndRetract(self):
00040         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'private')
00041         self.workflow.doActionFor(self.doc, 'submit')
00042         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'pending')
00043         self.workflow.doActionFor(self.doc, 'retract')
00044         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'private')
00045 
00046     # Check some forbidden transitions
00047 
00048     def testOwnerCannotPublishDocument(self):
00049         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'private')
00050         self.assertRaises(WorkflowException, self.workflow.doActionFor, self.doc, 'publish')
00051 
00052     # Check view permission
00053 
00054     def testViewIsNotAcquiredInPrivateState(self):
00055         self.assertEqual(self.doc.acquiredRolesAreUsedBy(View), '')     # not checked
00056 
00057     def testViewPrivateDocument(self):
00058         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'private')
00059         # Owner is allowed
00060         self.login(default_user)
00061         self.failUnless(checkPerm(View, self.doc))
00062         # Member is denied
00063         self.login('member')
00064         self.failIf(checkPerm(View, self.doc))
00065         # Reviewer is denied
00066         self.login('reviewer')
00067         self.failIf(checkPerm(View, self.doc))
00068         # Anonymous is denied
00069         self.logout()
00070         self.failIf(checkPerm(View, self.doc))
00071         # Editor is allowed
00072         self.login('editor')
00073         self.failUnless(checkPerm(View, self.doc))
00074         # Reader is allowed
00075         self.login('reader')
00076         self.failUnless(checkPerm(View, self.doc))
00077 
00078     def testViewIsNotAcquiredInPublishedState(self):
00079         # transition requires Review portal content
00080         self.login('manager')
00081         self.workflow.doActionFor(self.doc, 'publish')
00082         self.assertEqual(self.doc.acquiredRolesAreUsedBy(View), '')   # not checked
00083 
00084     def testViewPublishedDocument(self):
00085         # transition requires Review portal content
00086         self.login('manager')
00087         self.workflow.doActionFor(self.doc, 'publish')
00088         # Owner is allowed
00089         self.login(default_user)
00090         self.failUnless(checkPerm(View, self.doc))
00091         # Member is allowed
00092         self.login('member')
00093         self.failUnless(checkPerm(View, self.doc))
00094         # Reviewer is denied  but he acquires through Anonymous Role
00095         self.login('reviewer')
00096         self.failUnless(checkPerm(View, self.doc))
00097         # Anonymous is allowed
00098         self.logout()
00099         self.failUnless(checkPerm(View, self.doc))
00100         # Editor is allowed
00101         self.login('editor')
00102         self.failUnless(checkPerm(View, self.doc))
00103         # Reader is allowed
00104         self.login('reader')
00105         self.failUnless(checkPerm(View, self.doc))
00106 
00107     # Check access contents info permission
00108 
00109     def testAccessContentsInformationIsNotAcquiredInPrivateState(self):
00110         self.assertEqual(self.doc.acquiredRolesAreUsedBy(AccessContentsInformation), '')     # not checked
00111 
00112     def testAccessContentsInformationPrivateDocument(self):
00113         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'private')
00114         # Owner is allowed
00115         self.login(default_user)
00116         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00117         # Member is denied
00118         self.login('member')
00119         self.failIf(checkPerm(AccessContentsInformation, self.doc))
00120         # Reviewer is denied
00121         self.login('reviewer')
00122         self.failIf(checkPerm(AccessContentsInformation, self.doc))
00123         # Anonymous is denied
00124         self.logout()
00125         self.failIf(checkPerm(AccessContentsInformation, self.doc))
00126         # Editor is allowed
00127         self.login('editor')
00128         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00129         # Reader is allowed
00130         self.login('reader')
00131         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00132 
00133     def testAccessContentsInformationIsNotAcquiredInPublishedState(self):
00134         # transition requires Review portal content
00135         self.login('manager')
00136         self.workflow.doActionFor(self.doc, 'publish')
00137         self.assertEqual(self.doc.acquiredRolesAreUsedBy(AccessContentsInformation), '') # not checked
00138 
00139     def testAccessContentsInformationPublishedDocument(self):
00140         # transition requires Review portal content
00141         self.login('manager')
00142         self.workflow.doActionFor(self.doc, 'publish')
00143         # Owner is allowed
00144         self.login(default_user)
00145         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00146         # Member is allowed
00147         self.login('member')
00148         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00149         # Reviewer is denied but he acquires through Anonymous Role
00150         self.login('reviewer')
00151         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00152         # Anonymous is allowed
00153         self.logout()
00154         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00155         # Editor is allowed
00156         self.login('editor')
00157         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00158         # Reader is allowed
00159         self.login('reader')
00160         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00161 
00162     # Check modify content permissions
00163 
00164     def testModifyPrivateDocumentIsNotAcquiredInPrivateState(self):
00165         self.assertEqual(self.doc.acquiredRolesAreUsedBy(ModifyPortalContent), '') # not checked
00166 
00167     def testModifyPrivateDocument(self):
00168         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'private')
00169         # Owner is allowed
00170         self.login(default_user)
00171         self.failUnless(checkPerm(ModifyPortalContent, self.doc))
00172         # Member is denied
00173         self.login('member')
00174         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00175         # Reviewer is denied
00176         self.login('reviewer')
00177         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00178         # Anonymous is denied
00179         self.logout()
00180         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00181         # Editor is allowed
00182         self.login('editor')
00183         self.failUnless(checkPerm(ModifyPortalContent, self.doc))
00184         # Reader is denied
00185         self.login('reader')
00186         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00187 
00188     def testModifyPortalContentIsNotAcquiredInPublishedState(self):
00189         # transition requires Review portal content
00190         self.login('manager')
00191         self.workflow.doActionFor(self.doc, 'publish')
00192         self.assertEqual(self.doc.acquiredRolesAreUsedBy(ModifyPortalContent), '')
00193 
00194     def testModifyPublishedDocument(self):
00195         # transition requires Review portal content
00196         self.login('manager')
00197         self.workflow.doActionFor(self.doc, 'publish')
00198         # Manager is allowed
00199         self.failUnless(checkPerm(ModifyPortalContent, self.doc))
00200         # Owner is allowed
00201         self.login(default_user)
00202         self.failUnless(checkPerm(ModifyPortalContent, self.doc))
00203         # Member is denied
00204         self.login('member')
00205         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00206         # Reviewer is denied
00207         self.login('reviewer')
00208         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00209         # Anonymous is denied
00210         self.logout()
00211         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00212         # Editor is allowed
00213         self.login('editor')
00214         self.failUnless(checkPerm(ModifyPortalContent, self.doc))
00215         # Reader is denied
00216         self.login('reader')
00217         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00218 
00219     # Check change events permission
00220 
00221     def testChangeEventsIsNotAcquiredInPrivateState(self):
00222         self.assertEqual(self.workflow.getInfoFor(self.ev, 'review_state'), 'private')
00223         self.assertEqual(self.ev.acquiredRolesAreUsedBy(ChangeEvents), '')
00224 
00225     def testModifyPrivateEvent(self):
00226         self.assertEqual(self.workflow.getInfoFor(self.ev, 'review_state'), 'private')
00227         # Owner is allowed
00228         self.login(default_user)
00229         self.failUnless(checkPerm(ChangeEvents, self.ev))
00230         # Member is denied
00231         self.login('member')
00232         self.failIf(checkPerm(ChangeEvents, self.ev))
00233         # Reviewer is denied
00234         self.login('reviewer')
00235         self.failIf(checkPerm(ChangeEvents, self.ev))
00236         # Anonymous is denied
00237         self.logout()
00238         self.failIf(checkPerm(ChangeEvents, self.ev))
00239         # Editor is allowed
00240         self.login('editor')
00241         self.failUnless(checkPerm(ChangeEvents, self.ev))
00242         # Reader is denied
00243         self.login('reader')
00244         self.failIf(checkPerm(ChangeEvents, self.ev))
00245 
00246     def testChangeEventsIsNotAcquiredInPublishedState(self):
00247         # transition requires Review portal content
00248         self.login('manager')
00249         self.workflow.doActionFor(self.ev, 'publish')
00250         self.assertEqual(self.ev.acquiredRolesAreUsedBy(ChangeEvents), '')
00251 
00252     def testModifyPublishEvent(self):
00253         # transition requires Review portal content
00254         self.login('manager')
00255         self.workflow.doActionFor(self.ev, 'publish')
00256         self.failUnless(checkPerm(ChangeEvents, self.ev))
00257         # Owner is allowed
00258         self.login(default_user)
00259         self.failUnless(checkPerm(ChangeEvents, self.ev))
00260         # Member is denied
00261         self.login('member')
00262         self.failIf(checkPerm(ChangeEvents, self.ev))
00263         # Reviewer is denied
00264         self.login('reviewer')
00265         self.failIf(checkPerm(ChangeEvents, self.ev))
00266         # Anonymous is denied
00267         self.logout()
00268         self.failIf(checkPerm(ChangeEvents, self.ev))
00269         # Editor is allowed
00270         self.login('editor')
00271         self.failUnless(checkPerm(ChangeEvents, self.ev))
00272         # Reader is denied
00273         self.login('reader')
00274         self.failIf(checkPerm(ChangeEvents, self.ev))
00275 
00276 
00277 def test_suite():
00278     from unittest import TestSuite, makeSuite
00279     suite = TestSuite()
00280     suite.addTest(makeSuite(TestSimplePublicationWorkflow))
00281     return suite