Back to index

plone3  3.1.7
test_folder_workflow.py
Go to the documentation of this file.
00001 #
00002 # Tests the folder workflow
00003 #
00004 
00005 from base import WorkflowTestCase
00006 
00007 from Products.CMFCore.WorkflowCore import WorkflowException
00008 
00009 from Products.CMFCore.utils import _checkPermission as checkPerm
00010 from Products.CMFCore.permissions import AccessContentsInformation
00011 from Products.CMFCore.permissions import View
00012 from Products.CMFCore.permissions import ListFolderContents
00013 from Products.CMFCore.permissions import ModifyPortalContent
00014 
00015 
00016 class TestFolderWorkflow(WorkflowTestCase):
00017 
00018     def afterSetUp(self):
00019         self.catalog = self.portal.portal_catalog
00020         self.workflow = self.portal.portal_workflow
00021         
00022         self.workflow.setChainForPortalTypes(['Folder'], 'folder_workflow')
00023 
00024         self.portal.acl_users._doAddUser('member', 'secret', ['Member'], [])
00025         self.portal.acl_users._doAddUser('reviewer', 'secret', ['Reviewer'], [])
00026         self.portal.acl_users._doAddUser('manager', 'secret', ['Manager'], [])
00027 
00028         self.folder.invokeFactory('Folder', id='dir')
00029         self.dir = self.folder.dir
00030 
00031     # Check allowed transitions
00032 
00033     def testOwnerHidesVisibleFolder(self):
00034         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'visible')
00035         self.workflow.doActionFor(self.dir, 'hide')
00036         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'private')
00037         self.failUnless(self.catalog(id='dir', review_state='private'))
00038 
00039     def testOwnerShowsPrivateFolder(self):
00040         self.workflow.doActionFor(self.dir, 'hide')
00041         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'private')
00042         self.workflow.doActionFor(self.dir, 'show')
00043         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'visible')
00044         self.failUnless(self.catalog(id='dir', review_state='visible'))
00045 
00046     def testOwnerPublishesPrivateFolder(self):
00047         self.workflow.doActionFor(self.dir, 'hide')
00048         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'private')
00049         self.workflow.doActionFor(self.dir, 'publish')
00050         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'published')
00051         self.failUnless(self.catalog(id='dir', review_state='published'))
00052 
00053     def testOwnerPublishesVisibleFolder(self):
00054         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'visible')
00055         self.workflow.doActionFor(self.dir, 'publish')
00056         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'published')
00057         self.failUnless(self.catalog(id='dir', review_state='published'))
00058 
00059     def testOwnerHidesPublishedFolder(self):
00060         self.workflow.doActionFor(self.dir, 'publish')
00061         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'published')
00062         self.workflow.doActionFor(self.dir, 'hide')
00063         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'private')
00064         self.failUnless(self.catalog(id='dir', review_state='private'))
00065 
00066     def testOwnerRetractsPublishedFolder(self):
00067         self.workflow.doActionFor(self.dir, 'publish')
00068         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'published')
00069         self.workflow.doActionFor(self.dir, 'retract')
00070         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'visible')
00071         self.failUnless(self.catalog(id='dir', review_state='visible'))
00072 
00073     def testManagerPublishesVisibleFolder(self):
00074         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'visible')
00075         self.login('manager')
00076         self.workflow.doActionFor(self.dir, 'publish')
00077         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'published')
00078         self.failUnless(self.catalog(id='dir', review_state='published'))
00079 
00080     def testManagerPublishesPrivateFolder(self):
00081         self.workflow.doActionFor(self.dir, 'hide')
00082         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'private')
00083         self.login('manager')
00084         self.workflow.doActionFor(self.dir, 'publish')
00085         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'published')
00086         self.failUnless(self.catalog(id='dir', review_state='published'))
00087 
00088     def testManagerRetractsPublishedFolder(self):
00089         self.workflow.doActionFor(self.dir, 'publish')
00090         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'published')
00091         self.login('manager')
00092         self.workflow.doActionFor(self.dir, 'retract')
00093         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'visible')
00094         self.failUnless(self.catalog(id='dir', review_state='visible'))
00095 
00096     # Check forbidden transitions
00097 
00098     def testMemberHidesVisibleFolder(self):
00099         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'visible')
00100         self.login('member')
00101         self.assertRaises(WorkflowException, self.workflow.doActionFor, self.dir, 'hide')
00102 
00103     def testMemberShowsPrivateFolder(self):
00104         self.workflow.doActionFor(self.dir, 'hide')
00105         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'private')
00106         self.login('member')
00107         self.assertRaises(WorkflowException, self.workflow.doActionFor, self.dir, 'show')
00108 
00109     def testMemberPublishesVisibleFolder(self):
00110         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'visible')
00111         self.login('member')
00112         self.assertRaises(WorkflowException, self.workflow.doActionFor, self.dir, 'publish')
00113 
00114     def testMemberPublishesPrivateFolder(self):
00115         self.workflow.doActionFor(self.dir, 'hide')
00116         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'private')
00117         self.login('member')
00118         self.assertRaises(WorkflowException, self.workflow.doActionFor, self.dir, 'publish')
00119 
00120     def testMemberHidesPublishedFolder(self):
00121         self.workflow.doActionFor(self.dir, 'publish')
00122         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'published')
00123         self.login('member')
00124         self.assertRaises(WorkflowException, self.workflow.doActionFor, self.dir, 'hide')
00125 
00126     def testMemberRetractsPublishedFolder(self):
00127         self.workflow.doActionFor(self.dir, 'publish')
00128         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'published')
00129         self.login('member')
00130         self.assertRaises(WorkflowException, self.workflow.doActionFor, self.dir, 'retract')
00131 
00132     def testReviewerHidesVisibleFolder(self):
00133         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'visible')
00134         self.login('reviewer')
00135         self.assertRaises(WorkflowException, self.workflow.doActionFor, self.dir, 'hide')
00136 
00137     def testReviewerShowsPrivateFolder(self):
00138         self.workflow.doActionFor(self.dir, 'hide')
00139         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'private')
00140         self.login('reviewer')
00141         self.assertRaises(WorkflowException, self.workflow.doActionFor, self.dir, 'show')
00142 
00143     def testReviewerPublishesVisibleFolder(self):
00144         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'visible')
00145         self.login('reviewer')
00146         self.assertRaises(WorkflowException, self.workflow.doActionFor, self.dir, 'publish')
00147 
00148     def testReviewerPublishesPrivateFolder(self):
00149         self.workflow.doActionFor(self.dir, 'hide')
00150         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'private')
00151         self.login('reviewer')
00152         self.assertRaises(WorkflowException, self.workflow.doActionFor, self.dir, 'publish')
00153 
00154     def testReviewerHidesPublishedFolder(self):
00155         self.workflow.doActionFor(self.dir, 'publish')
00156         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'published')
00157         self.login('reviewer')
00158         self.assertRaises(WorkflowException, self.workflow.doActionFor, self.dir, 'hide')
00159 
00160     def testReviewerRetractsPublishedFolder(self):
00161         self.workflow.doActionFor(self.dir, 'publish')
00162         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'published')
00163         self.login('reviewer')
00164         self.assertRaises(WorkflowException, self.workflow.doActionFor, self.dir, 'retract')
00165 
00166     def testManagerHidesVisibleFolder(self):
00167         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'visible')
00168         self.login('manager')
00169         self.workflow.doActionFor(self.dir, 'hide')
00170 
00171     def testManagerShowsPrivateFolder(self):
00172         self.workflow.doActionFor(self.dir, 'hide')
00173         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'private')
00174         self.login('manager')
00175         self.workflow.doActionFor(self.dir, 'show')
00176 
00177     def testManagerHidesPublishedFolder(self):
00178         self.workflow.doActionFor(self.dir, 'publish')
00179         self.assertEqual(self.workflow.getInfoFor(self.dir, 'review_state'), 'published')
00180         self.login('manager')
00181         self.workflow.doActionFor(self.dir, 'hide')
00182 
00183     # Check view permissions
00184 
00185     def testViewVisibleFolder(self):
00186         # Owner is allowed
00187         self.failUnless(checkPerm(View, self.dir))
00188         # Member is allowed
00189         self.login('member')
00190         self.failUnless(checkPerm(View, self.dir))
00191         # Reviewer is allowed
00192         self.login('reviewer')
00193         self.failUnless(checkPerm(View, self.dir))
00194         # Anonymous is allowed
00195         self.logout()
00196         self.failUnless(checkPerm(View, self.dir))
00197 
00198     def testViewIsNotAcquiredInVisibleState(self):
00199         self.assertEqual(self.dir.acquiredRolesAreUsedBy(View), '')
00200 
00201     def testViewPrivateFolder(self):
00202         self.workflow.doActionFor(self.dir, 'hide')
00203         # Owner is allowed
00204         self.failUnless(checkPerm(View, self.dir))
00205         # Member is denied
00206         self.login('member')
00207         self.failIf(checkPerm(View, self.dir))
00208         # Reviewer is denied
00209         self.login('reviewer')
00210         self.failIf(checkPerm(View, self.dir))
00211         # Anonymous is denied
00212         self.logout()
00213         self.failIf(checkPerm(View, self.dir))
00214 
00215     def testViewIsNotAcquiredInPrivateState(self):
00216         self.workflow.doActionFor(self.dir, 'hide')
00217         self.assertEqual(self.dir.acquiredRolesAreUsedBy(View), '')
00218 
00219     def testViewPublishedFolder(self):
00220         self.workflow.doActionFor(self.dir, 'publish')
00221         # Owner is allowed
00222         self.failUnless(checkPerm(View, self.dir))
00223         # Member is allowed
00224         self.login('member')
00225         self.failUnless(checkPerm(View, self.dir))
00226         # Reviewer is allowed
00227         self.login('reviewer')
00228         self.failUnless(checkPerm(View, self.dir))
00229         # Anonymous is allowed
00230         self.logout()
00231         self.failUnless(checkPerm(View, self.dir))
00232 
00233     def testViewIsNotAcquiredInPublishedState(self):
00234         self.workflow.doActionFor(self.dir, 'publish')
00235         self.assertEqual(self.dir.acquiredRolesAreUsedBy(View), '')
00236 
00237     # Check access contents info permission
00238 
00239     def testAccessVisibleFolderContents(self):
00240         # Owner is allowed
00241         self.failUnless(checkPerm(AccessContentsInformation, self.dir))
00242         # Member is allowed
00243         self.login('member')
00244         self.failUnless(checkPerm(AccessContentsInformation, self.dir))
00245         # Reviewer is allowed
00246         self.login('reviewer')
00247         self.failUnless(checkPerm(AccessContentsInformation, self.dir))
00248         # Anonymous is allowed
00249         self.logout()
00250         self.failUnless(checkPerm(AccessContentsInformation, self.dir))
00251 
00252     def testAccessContentsInformationIsNotAcquiredInVisibleState(self):
00253         self.assertEqual(self.dir.acquiredRolesAreUsedBy(AccessContentsInformation), '')
00254 
00255     def testAccessPrivateFolderContents(self):
00256         self.workflow.doActionFor(self.dir, 'hide')
00257         # Owner is allowed
00258         self.failUnless(checkPerm(AccessContentsInformation, self.dir))
00259         # Member is denied
00260         self.login('member')
00261         self.failIf(checkPerm(AccessContentsInformation, self.dir))
00262         # Reviewer is denied
00263         self.login('reviewer')
00264         self.failIf(checkPerm(AccessContentsInformation, self.dir))
00265         # Anonymous is denied
00266         self.logout()
00267         self.failIf(checkPerm(AccessContentsInformation, self.dir))
00268 
00269     def testAccessContentsInformationIsNotAcquiredInPrivateState(self):
00270         self.workflow.doActionFor(self.dir, 'hide')
00271         self.assertEqual(self.dir.acquiredRolesAreUsedBy(AccessContentsInformation), '')
00272 
00273     def testAccessPublishedFolderContents(self):
00274         self.workflow.doActionFor(self.dir, 'publish')
00275         # Owner is allowed
00276         self.failUnless(checkPerm(AccessContentsInformation, self.dir))
00277         # Member is allowed
00278         self.login('member')
00279         self.failUnless(checkPerm(AccessContentsInformation, self.dir))
00280         # Reviewer is allowed
00281         self.login('reviewer')
00282         self.failUnless(checkPerm(AccessContentsInformation, self.dir))
00283         # Anonymous is allowed
00284         self.logout()
00285         self.failUnless(checkPerm(AccessContentsInformation, self.dir))
00286 
00287     def testAccessContentsInformationIsNotAcquiredInPublishedState(self):
00288         self.workflow.doActionFor(self.dir, 'publish')
00289         self.assertEqual(self.dir.acquiredRolesAreUsedBy(AccessContentsInformation), '')
00290 
00291     # Check modify contents permission
00292 
00293     def testModifyVisibleFolderContents(self):
00294         # Owner is allowed
00295         self.failUnless(checkPerm(ModifyPortalContent, self.dir))
00296         # Member is denied
00297         self.login('member')
00298         self.failIf(checkPerm(ModifyPortalContent, self.dir))
00299         # Reviewer is denied
00300         self.login('reviewer')
00301         self.failIf(checkPerm(ModifyPortalContent, self.dir))
00302         # Anonymous is denied
00303         self.logout()
00304         self.failIf(checkPerm(ModifyPortalContent, self.dir))
00305 
00306     def testModifyPortalContentIsNotAcquiredInVisibleState(self):
00307         self.assertEqual(self.dir.acquiredRolesAreUsedBy(ModifyPortalContent), '')
00308 
00309     def testModifyPrivateFolderContents(self):
00310         self.workflow.doActionFor(self.dir, 'hide')
00311         # Owner is allowed
00312         self.failUnless(checkPerm(ModifyPortalContent, self.dir))
00313         # Member is denied
00314         self.login('member')
00315         self.failIf(checkPerm(ModifyPortalContent, self.dir))
00316         # Reviewer is denied
00317         self.login('reviewer')
00318         self.failIf(checkPerm(ModifyPortalContent, self.dir))
00319         # Anonymous is denied
00320         self.logout()
00321         self.failIf(checkPerm(ModifyPortalContent, self.dir))
00322 
00323     def testModifyPortalContentIsNotAcquiredInPrivateState(self):
00324         self.workflow.doActionFor(self.dir, 'hide')
00325         self.assertEqual(self.dir.acquiredRolesAreUsedBy(ModifyPortalContent), '')
00326 
00327     def testModifyPublishedFolderContents(self):
00328         self.workflow.doActionFor(self.dir, 'publish')
00329         # Owner is allowed
00330         self.failUnless(checkPerm(ModifyPortalContent, self.dir))
00331         # Member is denied
00332         self.login('member')
00333         self.failIf(checkPerm(ModifyPortalContent, self.dir))
00334         # Reviewer is denied
00335         self.login('reviewer')
00336         self.failIf(checkPerm(ModifyPortalContent, self.dir))
00337         # Anonymous is denied
00338         self.logout()
00339         self.failIf(checkPerm(ModifyPortalContent, self.dir))
00340 
00341     def testModifyPortalContentIsNotAcquiredInPublishedState(self):
00342         self.workflow.doActionFor(self.dir, 'publish')
00343         self.assertEqual(self.dir.acquiredRolesAreUsedBy(ModifyPortalContent), '')
00344 
00345     # Check list contents permission
00346 
00347     def testListVisibleFolderContents(self):
00348         # Owner is allowed
00349         self.failUnless(checkPerm(ListFolderContents, self.dir))
00350         # Member is allowed
00351         self.login('member')
00352         self.failUnless(checkPerm(ListFolderContents, self.dir))
00353         # Reviewer is denied
00354         self.login('reviewer')
00355         self.failIf(checkPerm(ListFolderContents, self.dir))
00356         # Anonymous is denied
00357         self.logout()
00358         self.failIf(checkPerm(ListFolderContents, self.dir))
00359 
00360     def testListFolderContentsIsNotAcquiredInVisibleState(self):
00361         self.assertEqual(self.dir.acquiredRolesAreUsedBy(ListFolderContents), '')
00362 
00363     def testListPrivateFolderContents(self):
00364         self.workflow.doActionFor(self.dir, 'hide')
00365         # Owner is allowed
00366         self.failUnless(checkPerm(ListFolderContents, self.dir))
00367         # Member is denied
00368         self.login('member')
00369         self.failIf(checkPerm(ListFolderContents, self.dir))
00370         # Reviewer is denied
00371         self.login('reviewer')
00372         self.failIf(checkPerm(ListFolderContents, self.dir))
00373         # Anonymous is denied
00374         self.logout()
00375         self.failIf(checkPerm(ListFolderContents, self.dir))
00376 
00377     def testListFolderContentsIsNotAcquiredInPrivateState(self):
00378         self.workflow.doActionFor(self.dir, 'hide')
00379         self.assertEqual(self.dir.acquiredRolesAreUsedBy(ListFolderContents), '')
00380 
00381     def testListPublishedFolderContents(self):
00382         self.workflow.doActionFor(self.dir, 'publish')
00383         # Owner is allowed
00384         self.failUnless(checkPerm(ListFolderContents, self.dir))
00385         # Member is allowed
00386         self.login('member')
00387         self.failUnless(checkPerm(ListFolderContents, self.dir))
00388         # Reviewer is allowed
00389         self.login('reviewer')
00390         self.failUnless(checkPerm(ListFolderContents, self.dir))
00391         # Anonymous is allowed
00392         self.logout()
00393         self.failUnless(checkPerm(ListFolderContents, self.dir))
00394 
00395     def testListFolderContentsIsNotAcquiredInPublishedState(self):
00396         self.workflow.doActionFor(self.dir, 'publish')
00397         self.assertEqual(self.dir.acquiredRolesAreUsedBy(ListFolderContents), '')
00398 
00399     # Check catalog search
00400 
00401     def testFindVisibleFolder(self):
00402         # Owner is allowed
00403         self.failUnless(self.catalog(id='dir'))
00404         # Member is allowed
00405         self.login('member')
00406         self.failUnless(self.catalog(id='dir'))
00407         # Reviewer is allowed
00408         self.login('reviewer')
00409         self.failUnless(self.catalog(id='dir'))
00410         # Anonymous is allowed
00411         self.logout()
00412         self.failUnless(self.catalog(id='dir'))
00413 
00414     def testFindPrivateFolder(self):
00415         self.workflow.doActionFor(self.dir, 'hide')
00416         # Owner is allowed
00417         self.failUnless(self.catalog(id='dir'))
00418         # Member is denied
00419         self.login('member')
00420         self.failIf(self.catalog(id='dir'))
00421         # Reviewer is denied
00422         self.login('reviewer')
00423         self.failIf(self.catalog(id='dir'))
00424         # Anonymous is denied
00425         self.logout()
00426         self.failIf(self.catalog(id='dir'))
00427 
00428     def testFindPublishedFolder(self):
00429         self.workflow.doActionFor(self.dir, 'publish')
00430         # Owner is allowed
00431         self.failUnless(self.catalog(id='dir'))
00432         # Member is allowed
00433         self.login('member')
00434         self.failUnless(self.catalog(id='dir'))
00435         # Reviewer is allowed
00436         self.login('reviewer')
00437         self.failUnless(self.catalog(id='dir'))
00438         # Anonymous is allowed
00439         self.logout()
00440         self.failUnless(self.catalog(id='dir'))
00441 
00442 
00443 def test_suite():
00444     from unittest import TestSuite, makeSuite
00445     suite = TestSuite()
00446     suite.addTest(makeSuite(TestFolderWorkflow))
00447     return suite