# -*- coding: utf-8 -*- # # File: testTermWorkflow.py # # Copyright (c) 2007 by CommunesPlone # Generator: ArchGenXML Version 1.5.1-svn # http://plone.org/products/archgenxml # # GNU General Public License (GPL) # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. # __author__ = """Gauthier BASTIEN , Stephan GEULETTE """ __docformat__ = 'plaintext' import os, sys if __name__ == '__main__': execfile(os.path.join(sys.path[0], 'framework.py')) ##code-section module-header #fill in your manual code here from Products.CMFCore.utils import getToolByName from Products.TeleServices.config import * from Products.TeleServices.tests.BaseTeleServicesTestCase import BaseTeleServicesTestCase ##/code-section module-header # # Test-cases for class(es) # from Testing import ZopeTestCase # Import the tested classes ##code-section module-beforeclass #fill in your manual code here from Products.TeleServices.config import * from Products.TeleServices.tests.BaseTeleServicesTestCase import BaseTeleServicesTestCase from AccessControl import Unauthorized from AccessControl.SecurityManagement import getSecurityManager from Products.CMFCore.permissions import View, AccessContentsInformation, ModifyPortalContent from Products.TeleServices import TeleServicesReview, ManageTeleServices from Products.CMFCore.utils import getToolByName ##/code-section module-beforeclass class testTermWorkflow(BaseTeleServicesTestCase): """Test-cases for class(es) .""" ##code-section class-header_testTermWorkflow #fill in your manual code here ##/code-section class-header_testTermWorkflow def afterSetUp(self): """ """ BaseTeleServicesTestCase.afterSetup(self) # Manually created methods def testInitialState(self): """ On teste ici l'etat initial """ wft = self.wft self.login("admin") dtf = self.portal.portal_teleservices.populationteleservice_config.destinationterms term_id = dtf.invokeFactory('DestinationTerm', id='test_term') term_obj = getattr(dtf, term_id) self.login("member") self.assertEquals(wft.getInfoFor(term_obj, 'review_state'), 'enabled') def testPermissionsInStateEnabled(self): """ we test the permissions of differents roles when a term is in state enabled """ self.login("admin") dtf = self.portal.portal_teleservices.populationteleservice_config.destinationterms term_id = dtf.invokeFactory('DestinationTerm', id='test_term') term_obj = getattr(dtf, term_id) #the Owner have the 'View', 'Access contents information' but not 'Modify portal content' self.login("member") sm = getSecurityManager() self.failUnless(sm.checkPermission(View, term_obj)) self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) #Manager has every permissions self.login('admin') sm = getSecurityManager() self.failUnless(sm.checkPermission(View, term_obj)) self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) self.failUnless(sm.checkPermission(ModifyPortalContent, term_obj)) #PopulationTSManager self.login('ptsmanager') sm = getSecurityManager() self.failUnless(sm.checkPermission(View, term_obj)) self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) #WorkTSManager self.login('wtsmanager') sm = getSecurityManager() self.failUnless(sm.checkPermission(View, term_obj)) self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) #Anonymous self.login('anon') sm = getSecurityManager() self.failIf(sm.checkPermission(View, term_obj)) self.failIf(sm.checkPermission(AccessContentsInformation, term_obj)) self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) def testPermissionsInStateDisabled(self): """ we test the permissions of differents roles when a term is in state disabled """ self.login("admin") dtf = self.portal.portal_teleservices.populationteleservice_config.destinationterms term_id = dtf.invokeFactory('DestinationTerm', id='test_term') term_obj = getattr(dtf, term_id) #we set the term in disabled state self.wft.doActionFor(term_obj, 'disable') self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), "disabled") #the Owner have the 'View', 'Access contents information' but not 'Modify portal content' self.login("member") sm = getSecurityManager() self.failUnless(sm.checkPermission(View, term_obj)) self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) #Manager has every permissions self.login('admin') sm = getSecurityManager() self.failUnless(sm.checkPermission(View, term_obj)) self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) self.failUnless(sm.checkPermission(ModifyPortalContent, term_obj)) #PopulationTSManager self.login('ptsmanager') sm = getSecurityManager() self.failUnless(sm.checkPermission(View, term_obj)) self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) #WorkTSManager self.login('wtsmanager') sm = getSecurityManager() self.failUnless(sm.checkPermission(View, term_obj)) self.failUnless(sm.checkPermission(AccessContentsInformation, term_obj)) self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) #Anonymous self.login('anon') sm = getSecurityManager() self.failIf(sm.checkPermission(View, term_obj)) self.failIf(sm.checkPermission(AccessContentsInformation, term_obj)) self.failIf(sm.checkPermission(ModifyPortalContent, term_obj)) def testTransitionFromEnabled(self): """ we test the available transitions for differents roles when the term is in the enabled state """ self.login("admin") dtf = self.portal.portal_teleservices.populationteleservice_config.destinationterms term_id = dtf.invokeFactory('DestinationTerm', id='test_term') term_obj = getattr(dtf, term_id) #we check that we are in the enabled state self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), "enabled") #we log as PopulationTeleServicesManager self.login('ptsmanager') self.checkActionList(term_obj, []) #member self.login("member") self.checkActionList(term_obj, []) #Manager self.login('admin') self.checkActionList(term_obj, ['disable']) #WTSManager self.login('wtsmanager') self.checkActionList(term_obj, []) #Anonymous self.login('anon') self.checkActionList(term_obj, []) def testTransitionFromDisabled(self): """ we test the available transitions for differents roles when the term is in the disabled state """ self.login("admin") dtf = self.portal.portal_teleservices.populationteleservice_config.destinationterms term_id = dtf.invokeFactory('DestinationTerm', id='test_term') term_obj = getattr(dtf, term_id) #we check that we are in the enabled state self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), "enabled") #we set the term in disabled state self.wft.doActionFor(term_obj, 'disable') self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), "disabled") #we log as PopulationTeleServicesManager self.login('ptsmanager') self.checkActionList(term_obj, []) #member self.login("member") self.checkActionList(term_obj, []) #Manager self.login('admin') self.checkActionList(term_obj, ['enable']) #WTSManager self.login('wtsmanager') self.checkActionList(term_obj, []) #Anonymous self.login('anon') self.checkActionList(term_obj, []) def test_suite(): from unittest import TestSuite, makeSuite suite = TestSuite() suite.addTest(makeSuite(testTermWorkflow)) return suite ##code-section module-footer #fill in your manual code here ##/code-section module-footer if __name__ == '__main__': framework()