# -*- coding: utf-8 -*- # # File: testDemandTypeTermWorkflow.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.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-header # # Test-cases for class(es) # from Testing import ZopeTestCase # Import the tested classes ##code-section module-beforeclass #fill in your manual code here ##/code-section module-beforeclass class testDemandTypeTermWorkflow(BaseTeleServicesTestCase): """Test-cases for class(es) .""" ##code-section class-header_testDemandTypeTermWorkflow #fill in your manual code here ##/code-section class-header_testDemandTypeTermWorkflow 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.demandtypeterms term_id = dtf.invokeFactory('DemandTypeTerm', id='test_term') term_obj = getattr(dtf, term_id) self.login("member") self.assertEquals(wft.getInfoFor(term_obj, 'review_state'), 'on_line') def testPermissionsInStateOn_line(self): """ we test the permissions of differents roles when a term is in state on_line """ self.login("admin") dtf = self.portal.portal_teleservices.populationteleservice_config.demandtypeterms term_obj = getattr(dtf, 'ptsterm1') self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), 'on_line') #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 testPermissionsInStateInfo_only(self): """ we test the permissions of differents roles when a term is in state info_only """ self.login("admin") dtf = self.portal.portal_teleservices.populationteleservice_config.demandtypeterms term_obj = getattr(dtf, 'ptsterm1') self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), 'on_line') #we set the term in info_only state self.wft.doActionFor(term_obj, 'for_info_only') self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), "info_only") #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.demandtypeterms term_obj = getattr(dtf, 'ptsterm1') self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), 'on_line') #we set the term in disabled state self.wft.doActionFor(term_obj, 'for_info_only') self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), "info_only") self.wft.doActionFor(term_obj, 'disable') self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), "disabled") #the member 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 testTransitionFromOn_line(self): """ we test the available transitions for differents roles when the term is in the on_line state """ self.login("admin") dtf = self.portal.portal_teleservices.populationteleservice_config.demandtypeterms term_obj = getattr(dtf, 'ptsterm1') self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), 'on_line') #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, ['for_info_only']) #WTSManager self.login('wtsmanager') self.checkActionList(term_obj, []) #Anonymous self.login('anon') self.checkActionList(term_obj, []) def testTransitionFromInfo_only(self): """ we test the available transitions for differents roles when the term is in the info_only state """ self.login("admin") dtf = self.portal.portal_teleservices.populationteleservice_config.demandtypeterms term_obj = getattr(dtf, 'ptsterm1') self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), 'on_line') #we set the term in info_only state self.wft.doActionFor(term_obj, 'for_info_only') self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), "info_only") #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', 'put_on_line']) #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.demandtypeterms term_obj = getattr(dtf, 'ptsterm1') self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), 'on_line') #we set the term in disabled state self.wft.doActionFor(term_obj, 'for_info_only') self.assertEquals(self.wft.getInfoFor(term_obj, 'review_state'), "info_only") 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(testDemandTypeTermWorkflow)) return suite ##code-section module-footer #fill in your manual code here ##/code-section module-footer if __name__ == '__main__': framework()