Back to index

plone3  3.1.7
test_plone_workflow.py
Go to the documentation of this file.
00001 #
00002 # Tests the default 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 TestDefaultWorkflow(WorkflowTestCase):
00020 
00021     def afterSetUp(self):
00022         self.catalog = self.portal.portal_catalog
00023         self.workflow = self.portal.portal_workflow
00024         
00025         self.workflow.setChainForPortalTypes(['Document','Event'], 'plone_workflow')
00026 
00027         self.portal.acl_users._doAddUser('member', 'secret', ['Member'], [])
00028         self.portal.acl_users._doAddUser('reviewer', 'secret', ['Reviewer'], [])
00029         self.portal.acl_users._doAddUser('manager', 'secret', ['Manager'], [])
00030 
00031         self.folder.invokeFactory('Document', id='doc')
00032         self.doc = self.folder.doc
00033 
00034         self.folder.invokeFactory('Event', id='ev')
00035         self.ev = self.folder.ev
00036 
00037     # Check allowed transitions
00038 
00039     def testOwnerHidesVisibleDocument(self):
00040         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'visible')
00041         self.workflow.doActionFor(self.doc, 'hide')
00042         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'private')
00043         self.failUnless(self.catalog(id='doc', review_state='private'))
00044 
00045     def testOwnerShowsPrivateDocument(self):
00046         self.workflow.doActionFor(self.doc, 'hide')
00047         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'private')
00048         self.workflow.doActionFor(self.doc, 'show')
00049         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'visible')
00050         self.failUnless(self.catalog(id='doc', review_state='visible'))
00051 
00052     def testOwnerSubmitsVisibleDocument(self):
00053         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'visible')
00054         self.workflow.doActionFor(self.doc, 'submit')
00055         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'pending')
00056         self.failUnless(self.catalog(id='doc', review_state='pending'))
00057 
00058     def testOwnerRetractsPendingDocument(self):
00059         self.workflow.doActionFor(self.doc, 'submit')
00060         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'pending')
00061         self.workflow.doActionFor(self.doc, 'retract')
00062         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'visible')
00063         self.failUnless(self.catalog(id='doc', review_state='visible'))
00064 
00065     def testOwnerRetractsPublishedDocument(self):
00066         self.login('reviewer')
00067         self.workflow.doActionFor(self.doc, 'publish')
00068         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'published')
00069         self.login(default_user)
00070         self.workflow.doActionFor(self.doc, 'retract')
00071         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'visible')
00072         self.failUnless(self.catalog(id='doc', review_state='visible'))
00073 
00074     def testReviewerPublishesPendingDocument(self):
00075         self.workflow.doActionFor(self.doc, 'submit')
00076         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'pending')
00077         self.login('reviewer')
00078         self.workflow.doActionFor(self.doc, 'publish')
00079         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'published')
00080         self.failUnless(self.catalog(id='doc', review_state='published'))
00081 
00082     def testReviewerRejectsPendingDocument(self):
00083         self.workflow.doActionFor(self.doc, 'submit')
00084         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'pending')
00085         self.login('reviewer')
00086         self.workflow.doActionFor(self.doc, 'reject')
00087         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'visible')
00088         self.failUnless(self.catalog(id='doc', review_state='visible'))
00089 
00090     def testReviewerPublishesVisibleDocument(self):
00091         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'visible')
00092         self.login('reviewer')
00093         self.workflow.doActionFor(self.doc, 'publish')
00094         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'published')
00095         self.failUnless(self.catalog(id='doc', review_state='published'))
00096 
00097     def testReviewerRejectsPublishedDocument(self):
00098         self.login('reviewer')
00099         self.workflow.doActionFor(self.doc, 'publish')
00100         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'published')
00101         self.workflow.doActionFor(self.doc, 'reject')
00102         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'visible')
00103         self.failUnless(self.catalog(id='doc', review_state='visible'))
00104 
00105     # Check some forbidden transitions
00106 
00107     def testOwnerPublishesVisibleDocument(self):
00108         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'visible')
00109         self.assertRaises(WorkflowException, self.workflow.doActionFor, self.doc, 'publish')
00110 
00111     def testOwnerSubmitsPrivateDocument(self):
00112         self.workflow.doActionFor(self.doc, 'hide')
00113         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'private')
00114         self.assertRaises(WorkflowException, self.workflow.doActionFor, self.doc, 'submit')
00115 
00116     def testManagerPublishesPrivateDocument(self):
00117         self.workflow.doActionFor(self.doc, 'hide')
00118         self.assertEqual(self.workflow.getInfoFor(self.doc, 'review_state'), 'private')
00119         self.login('manager')
00120         self.assertRaises(WorkflowException, self.workflow.doActionFor, self.doc, 'publish')
00121 
00122     # No way am I going to write tests for all impossible transitions ;-)
00123 
00124     # Check view permission
00125 
00126     def testViewVisibleDocument(self):
00127         # Owner is allowed
00128         self.failUnless(checkPerm(View, self.doc))
00129         # Member is allowed
00130         self.login('member')
00131         self.failUnless(checkPerm(View, self.doc))
00132         # Reviewer is allowed
00133         self.login('reviewer')
00134         self.failUnless(checkPerm(View, self.doc))
00135         # Anonymous is allowed
00136         self.logout()
00137         self.failUnless(checkPerm(View, self.doc))
00138 
00139     def testViewIsNotAcquiredInVisibleState(self):
00140         self.assertEqual(self.doc.acquiredRolesAreUsedBy(View), '')
00141 
00142     def testViewPrivateDocument(self):
00143         self.workflow.doActionFor(self.doc, 'hide')
00144         # Owner is allowed
00145         self.failUnless(checkPerm(View, self.doc))
00146         # Member is denied
00147         self.login('member')
00148         self.failIf(checkPerm(View, self.doc))
00149         # Reviewer is denied
00150         self.login('reviewer')
00151         self.failIf(checkPerm(View, self.doc))
00152         # Anonymous is denied
00153         self.logout()
00154         self.failIf(checkPerm(View, self.doc))
00155 
00156     def testViewIsNotAcquiredInPrivateState(self):
00157         self.workflow.doActionFor(self.doc, 'hide')
00158         self.assertEqual(self.doc.acquiredRolesAreUsedBy(View), '')
00159 
00160     def testViewPendingDocument(self):
00161         self.workflow.doActionFor(self.doc, 'submit')
00162         # Owner is allowed
00163         self.failUnless(checkPerm(View, self.doc))
00164         # Member is allowed (TODO:?)
00165         self.login('member')
00166         self.failUnless(checkPerm(View, self.doc))
00167         # Reviewer is allowed
00168         self.login('reviewer')
00169         self.failUnless(checkPerm(View, self.doc))
00170         # Anonymous is allowed (TODO:?)
00171         self.logout()
00172         self.failUnless(checkPerm(View, self.doc))
00173 
00174     def testViewIsNotAcquiredInPendingState(self):
00175         self.workflow.doActionFor(self.doc, 'submit')
00176         self.assertEqual(self.doc.acquiredRolesAreUsedBy(View), '')
00177 
00178     def testViewPublishedDocument(self):
00179         self.login('reviewer')
00180         self.workflow.doActionFor(self.doc, 'publish')
00181         # Owner is allowed
00182         self.login(default_user)
00183         self.failUnless(checkPerm(View, self.doc))
00184         # Member is allowed
00185         self.login('member')
00186         self.failUnless(checkPerm(View, self.doc))
00187         # Reviewer is allowed
00188         self.login('reviewer')
00189         self.failUnless(checkPerm(View, self.doc))
00190         # Anonymous is allowed
00191         self.logout()
00192         self.failUnless(checkPerm(View, self.doc))
00193 
00194     def testViewIsNotAcquiredInPublishedState(self):
00195         self.login('reviewer')
00196         self.workflow.doActionFor(self.doc, 'publish')
00197         self.assertEqual(self.doc.acquiredRolesAreUsedBy(View), '')
00198 
00199     # Check access contents info permission
00200 
00201     def testAccessVisibleDocument(self):
00202         # Owner is allowed
00203         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00204         # Member is allowed
00205         self.login('member')
00206         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00207         # Reviewer is allowed
00208         self.login('reviewer')
00209         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00210         # Anonymous is allowed
00211         self.logout()
00212         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00213 
00214     def testAccessContentsInformationIsNotAcquiredInVisibleState(self):
00215         self.assertEqual(self.doc.acquiredRolesAreUsedBy(AccessContentsInformation), '')
00216 
00217     def testAccessPrivateDocument(self):
00218         self.workflow.doActionFor(self.doc, 'hide')
00219         # Owner is allowed
00220         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00221         # Member is denied
00222         self.login('member')
00223         self.failIf(checkPerm(AccessContentsInformation, self.doc))
00224         # Reviewer is denied
00225         self.login('reviewer')
00226         self.failIf(checkPerm(AccessContentsInformation, self.doc))
00227         # Anonymous is denied
00228         self.logout()
00229         self.failIf(checkPerm(AccessContentsInformation, self.doc))
00230 
00231     def testAccessContentsInformationIsNotAcquiredInPrivateState(self):
00232         self.workflow.doActionFor(self.doc, 'hide')
00233         self.assertEqual(self.doc.acquiredRolesAreUsedBy(AccessContentsInformation), '')
00234 
00235     def testAccessPendingDocument(self):
00236         self.workflow.doActionFor(self.doc, 'submit')
00237         # Owner is allowed
00238         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00239         # Member is allowed (TODO:?)
00240         self.login('member')
00241         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00242         # Reviewer is allowed
00243         self.login('reviewer')
00244         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00245         # Anonymous is allowed (TODO:?)
00246         self.logout()
00247         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00248 
00249     def testAccessContentsInformationIsNotAcquiredInPendingState(self):
00250         self.workflow.doActionFor(self.doc, 'submit')
00251         self.assertEqual(self.doc.acquiredRolesAreUsedBy(AccessContentsInformation), '')
00252 
00253     def testAccessPublishedDocument(self):
00254         self.login('reviewer')
00255         self.workflow.doActionFor(self.doc, 'publish')
00256         # Owner is allowed
00257         self.login(default_user)
00258         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00259         # Member is allowed
00260         self.login('member')
00261         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00262         # Reviewer is allowed
00263         self.login('reviewer')
00264         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00265         # Anonymous is allowed
00266         self.logout()
00267         self.failUnless(checkPerm(AccessContentsInformation, self.doc))
00268 
00269     def testAccessContentsInformationIsNotAcquiredInPublishedState(self):
00270         self.login('reviewer')
00271         self.workflow.doActionFor(self.doc, 'publish')
00272         self.assertEqual(self.doc.acquiredRolesAreUsedBy(AccessContentsInformation), '')
00273 
00274     # Check modify content permissions
00275 
00276     def testModifyVisibleDocument(self):
00277         # Owner is allowed
00278         self.failUnless(checkPerm(ModifyPortalContent, self.doc))
00279         # Member is denied
00280         self.login('member')
00281         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00282         # Reviewer is denied
00283         self.login('reviewer')
00284         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00285         # Anonymous is denied
00286         self.logout()
00287         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00288 
00289     def testModifyPortalContentIsNotAcquiredInVisibleState(self):
00290         self.assertEqual(self.doc.acquiredRolesAreUsedBy(ModifyPortalContent), '')
00291 
00292     def testModifyPrivateDocument(self):
00293         self.workflow.doActionFor(self.doc, 'hide')
00294         # Owner is allowed
00295         self.failUnless(checkPerm(ModifyPortalContent, self.doc))
00296         # Member is denied
00297         self.login('member')
00298         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00299         # Reviewer is denied
00300         self.login('reviewer')
00301         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00302         # Anonymous is denied
00303         self.logout()
00304         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00305 
00306     def testModifyPortalContentIsNotAcquiredInPrivateState(self):
00307         self.workflow.doActionFor(self.doc, 'hide')
00308         self.assertEqual(self.doc.acquiredRolesAreUsedBy(ModifyPortalContent), '')
00309 
00310     def testModifyPendingDocument(self):
00311         self.workflow.doActionFor(self.doc, 'submit')
00312         # Owner is denied
00313         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00314         # Member is denied
00315         self.login('member')
00316         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00317         # Reviewer is allowed
00318         self.login('reviewer')
00319         self.failUnless(checkPerm(ModifyPortalContent, self.doc))
00320         # Anonymous is denied
00321         self.logout()
00322         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00323 
00324     def testModifyPortalContentIsNotAcquiredInPendingState(self):
00325         self.workflow.doActionFor(self.doc, 'submit')
00326         self.assertEqual(self.doc.acquiredRolesAreUsedBy(ModifyPortalContent), '')
00327 
00328     def testModifyPublishedDocument(self):
00329         self.login('reviewer')
00330         self.workflow.doActionFor(self.doc, 'publish')
00331         # Owner is denied
00332         self.login(default_user)
00333         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00334         # Member is denied
00335         self.login('member')
00336         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00337         # Reviewer is denied
00338         self.login('reviewer')
00339         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00340         # Anonymous is denied
00341         self.logout()
00342         self.failIf(checkPerm(ModifyPortalContent, self.doc))
00343 
00344     def testModifyPortalContentIsNotAcquiredInPublishedState(self):
00345         self.login('reviewer')
00346         self.workflow.doActionFor(self.doc, 'publish')
00347         self.assertEqual(self.doc.acquiredRolesAreUsedBy(ModifyPortalContent), '')
00348 
00349     # Check change events permission
00350 
00351     def testModifyVisibleEvent(self):
00352         # Owner is allowed
00353         self.failUnless(checkPerm(ChangeEvents, self.ev))
00354         # Member is denied
00355         self.login('member')
00356         self.failIf(checkPerm(ChangeEvents, self.ev))
00357         # Reviewer is denied
00358         self.login('reviewer')
00359         self.failIf(checkPerm(ChangeEvents, self.ev))
00360         # Anonymous is denied
00361         self.logout()
00362         self.failIf(checkPerm(ChangeEvents, self.ev))
00363 
00364     def testChangeEventsIsNotAcquiredInVisibleState(self):
00365         self.assertEqual(self.ev.acquiredRolesAreUsedBy(ChangeEvents), '')
00366 
00367     def testModifyPrivateEvent(self):
00368         self.workflow.doActionFor(self.ev, 'hide')
00369         # Owner is allowed
00370         self.failUnless(checkPerm(ChangeEvents, self.ev))
00371         # Member is denied
00372         self.login('member')
00373         self.failIf(checkPerm(ChangeEvents, self.ev))
00374         # Reviewer is denied
00375         self.login('reviewer')
00376         self.failIf(checkPerm(ChangeEvents, self.ev))
00377         # Anonymous is denied
00378         self.logout()
00379         self.failIf(checkPerm(ChangeEvents, self.ev))
00380 
00381     def testChangeEventsIsNotAcquiredInPrivateState(self):
00382         self.workflow.doActionFor(self.ev, 'hide')
00383         self.assertEqual(self.ev.acquiredRolesAreUsedBy(ChangeEvents), '')
00384 
00385     def testModifyPendingEvent(self):
00386         self.workflow.doActionFor(self.ev, 'submit')
00387         # Owner is denied
00388         self.failIf(checkPerm(ChangeEvents, self.ev))
00389         # Member is denied
00390         self.login('member')
00391         self.failIf(checkPerm(ChangeEvents, self.ev))
00392         # Reviewer is allowed
00393         self.login('reviewer')
00394         self.failUnless(checkPerm(ChangeEvents, self.ev))
00395         # Anonymous is denied
00396         self.logout()
00397         self.failIf(checkPerm(ChangeEvents, self.ev))
00398 
00399     def testChangeEventsIsNotAcquiredInPendingState(self):
00400         self.workflow.doActionFor(self.ev, 'submit')
00401         self.assertEqual(self.ev.acquiredRolesAreUsedBy(ChangeEvents), '')
00402 
00403     def testModifyPublishedEvent(self):
00404         self.login('reviewer')
00405         self.workflow.doActionFor(self.ev, 'publish')
00406         # Owner is denied
00407         self.login(default_user)
00408         self.failIf(checkPerm(ChangeEvents, self.ev))
00409         # Member is denied
00410         self.login('member')
00411         self.failIf(checkPerm(ChangeEvents, self.ev))
00412         # Reviewer is denied
00413         self.login('reviewer')
00414         self.failIf(checkPerm(ChangeEvents, self.ev))
00415         # Anonymous is denied
00416         self.logout()
00417         self.failIf(checkPerm(ChangeEvents, self.ev))
00418 
00419     def testChangeEventsIsNotAcquiredInPublishedState(self):
00420         self.login('reviewer')
00421         self.workflow.doActionFor(self.ev, 'publish')
00422         self.assertEqual(self.ev.acquiredRolesAreUsedBy(ChangeEvents), '')
00423 
00424     # Check catalog search
00425 
00426     def testFindVisibleDocument(self):
00427         # Owner is allowed
00428         self.failUnless(self.catalog(id='doc'))
00429         # Member is allowed
00430         self.login('member')
00431         self.failUnless(self.catalog(id='doc'))
00432         # Reviewer is allowed
00433         self.login('reviewer')
00434         self.failUnless(self.catalog(id='doc'))
00435         # Anonymous is allowed
00436         self.logout()
00437         self.failUnless(self.catalog(id='doc'))
00438 
00439     def testFindPrivateDocument(self):
00440         self.workflow.doActionFor(self.doc, 'hide')
00441         # Owner is allowed
00442         self.failUnless(self.catalog(id='doc'))
00443         # Member is denied
00444         self.login('member')
00445         self.failIf(self.catalog(id='doc'))
00446         # Reviewer is denied
00447         self.login('reviewer')
00448         self.failIf(self.catalog(id='doc'))
00449         # Anonymous is denied
00450         self.logout()
00451         self.failIf(self.catalog(id='doc'))
00452 
00453     def testFindPendingDocument(self):
00454         self.workflow.doActionFor(self.doc, 'submit')
00455         # Owner is allowed
00456         self.failUnless(self.catalog(id='doc'))
00457         # Member is allowed (TODO:?)
00458         self.login('member')
00459         self.failUnless(self.catalog(id='doc'))
00460         # Reviewer is allowed
00461         self.login('reviewer')
00462         self.failUnless(self.catalog(id='doc'))
00463         # Anonymous is allowed (TODO:?)
00464         self.logout()
00465         self.failUnless(self.catalog(id='doc'))
00466 
00467     def testFindPublishedDocument(self):
00468         self.login('reviewer')
00469         self.workflow.doActionFor(self.doc, 'publish')
00470         # Owner is allowed
00471         self.login(default_user)
00472         self.failUnless(self.catalog(id='doc'))
00473         # Member is allowed
00474         self.login('member')
00475         self.failUnless(self.catalog(id='doc'))
00476         # Reviewer is allowed
00477         self.login('reviewer')
00478         self.failUnless(self.catalog(id='doc'))
00479         # Anonymous is allowed
00480         self.logout()
00481         self.failUnless(self.catalog(id='doc'))
00482 
00483     def testMyWorklist(self):
00484         # When a member has the local Reviewer role, pending
00485         # docs should show up in his worklist.
00486         self.workflow.doActionFor(self.doc, 'submit')
00487         self.doc.manage_addLocalRoles('member', ['Reviewer'])
00488         self.login('reviewer')
00489         worklist = self.portal.my_worklist()
00490         self.failUnless(len(worklist) == 1)
00491         self.failUnless(worklist[0] == self.doc)
00492         self.login('member')
00493         worklist = self.portal.my_worklist()
00494         self.failUnless(len(worklist) == 1)
00495         self.failUnless(worklist[0] == self.doc)
00496 
00497     def testStateTitles(self):
00498         state_titles = { 'private': 'Private',
00499                         'visible': 'Public draft',
00500                         'pending': 'Pending review',
00501                         'published': 'Published'
00502                         }
00503 
00504         wf = self.workflow.plone_workflow
00505             
00506         for state_id, title in state_titles.items():
00507             state = getattr(wf.states, state_id, None)
00508             if state is not None:
00509                 self.assertEqual(state.title, title)
00510 
00511 
00512 def test_suite():
00513     from unittest import TestSuite, makeSuite
00514     suite = TestSuite()
00515     suite.addTest(makeSuite(TestDefaultWorkflow))
00516     return suite