Back to index

plone3  3.1.7
test_remap.py
Go to the documentation of this file.
00001 #
00002 # Tests the remap-workflow functionality
00003 #
00004 
00005 from base import WorkflowTestCase
00006 from plone.app.workflow.remap import remap_workflow
00007 
00008 
00009 class TestRemapWorkflow(WorkflowTestCase):
00010 
00011     def afterSetUp(self):
00012         self.catalog = self.portal.portal_catalog
00013         self.workflow = self.portal.portal_workflow
00014     
00015         self.setRoles(('Manager',))
00016     
00017         self.workflow.setChainForPortalTypes(('Document','Event',), ('simple_publication_workflow',))
00018         self.workflow.setChainForPortalTypes(('News Item',), ('one_state_workflow',))
00019         self.workflow.setChainForPortalTypes(('Folder',), ())
00020         self.workflow.setChainForPortalTypes(('Image',), None)
00021         
00022         self.portal.invokeFactory('Document', 'd1')
00023         self.portal.invokeFactory('Document', 'd2')
00024         self.folder.invokeFactory('Event', 'e1')
00025         self.folder.invokeFactory('Document', 'e2')
00026         self.portal.invokeFactory('News Item', 'n1')
00027         self.portal.invokeFactory('Image', 'i1')
00028 
00029         self.workflow.doActionFor(self.portal.d1, 'publish')
00030 
00031     def _state(self, obj):
00032         return self.workflow.getInfoFor(obj, 'review_state')
00033 
00034     def _chain(self, obj):
00035         return self.workflow.getChainFor(obj)
00036 
00037     def test_remap_multiple_no_state_map(self):
00038         remap_workflow(self.portal, 
00039                        type_ids=('Document','News Item',), 
00040                        chain=('plone_workflow',))
00041                        
00042         self.assertEquals(self._chain(self.portal.d1), ('plone_workflow',))
00043         self.assertEquals(self._chain(self.portal.d2), ('plone_workflow',))
00044         self.assertEquals(self._chain(self.portal.n1), ('plone_workflow',))
00045                        
00046         self.assertEquals(self._state(self.portal.d1), 'visible')
00047         self.assertEquals(self._state(self.portal.d2), 'visible')
00048         self.assertEquals(self._state(self.portal.n1), 'visible')
00049         
00050     def test_remap_with_partial_state_map(self):
00051         remap_workflow(self.portal, 
00052                        type_ids=('Document','News Item',), 
00053                        chain=('plone_workflow',),
00054                        state_map={'published' : 'published'})
00055                        
00056         self.assertEquals(self._chain(self.portal.d1), ('plone_workflow',))
00057         self.assertEquals(self._chain(self.portal.d2), ('plone_workflow',))
00058         self.assertEquals(self._chain(self.portal.n1), ('plone_workflow',))
00059                        
00060         self.assertEquals(self._state(self.portal.d1), 'published')
00061         self.assertEquals(self._state(self.portal.d2), 'visible')
00062         self.assertEquals(self._state(self.portal.n1), 'published')
00063         
00064     def test_remap_to_no_workflow(self):
00065         
00066         view_at_d1 = [r['name'] for r in self.portal.d1.rolesOfPermission('View') if r['selected']]
00067         self.failUnless('Anonymous' in view_at_d1)
00068         
00069         remap_workflow(self.portal, 
00070                        type_ids=('Document','News Item',), 
00071                        chain=())
00072                        
00073         self.assertEquals(self._chain(self.portal.d1), ())
00074         self.assertEquals(self._chain(self.portal.d2), ())
00075         self.assertEquals(self._chain(self.portal.n1), ())
00076         
00077         view_at_d1 = [r['name'] for r in self.portal.d1.rolesOfPermission('View') if r['selected']]
00078         self.failIf('Anonymous' in view_at_d1)
00079         self.failUnless(self.portal.d1.acquiredRolesAreUsedBy('View'))
00080         
00081         
00082     def test_remap_from_no_workflow(self):
00083         remap_workflow(self.portal, 
00084                        type_ids=('Image',), 
00085                        chain=('plone_workflow',))
00086                        
00087         self.assertEquals(self._chain(self.portal.i1), ('plone_workflow',))
00088         self.assertEquals(self._state(self.portal.i1), 'visible')
00089         
00090     def test_remap_to_default(self):
00091         remap_workflow(self.portal, 
00092                        type_ids=('Folder',), 
00093                        chain='(Default)')
00094 
00095         self.assertEquals(self._chain(self.portal.i1), ('plone_workflow',))
00096 
00097 def test_suite():
00098     from unittest import TestSuite, makeSuite
00099     suite = TestSuite()
00100     suite.addTest(makeSuite(TestRemapWorkflow))
00101     return suite