# -*- coding: utf-8 -*- # # File: BaseTeleServicesTestCase.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' # # Base TestCase for TeleServices # import os, sys, code 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.Archetypes.tests.utils import DummySessionDataManager from sets import Set EID_PRESENT = False try: from Products.BelgianEidAuthPlugin.BelgianEidAuthPlugin import BelgianEidAuthPlugin EID_PRESENT = True except ImportError: EID_PRESENT = False ##/code-section module-header from Testing import ZopeTestCase from Products.PloneTestCase import PloneTestCase # Add common dependencies if not HAS_PLONE21: DEPENDENCIES.append('Archetypes') PRODUCT_DEPENDENCIES.append('MimetypesRegistry') PRODUCT_DEPENDENCIES.append('PortalTransforms') PRODUCT_DEPENDENCIES.append('TeleServices') if EID_PRESENT: PRODUCT_DEPENDENCIES.append('BelgianEidAuthPlugin') # Install all (product-) dependencies, install them too for dependency in PRODUCT_DEPENDENCIES + DEPENDENCIES: ZopeTestCase.installProduct(dependency) #ZopeTestCase.installProduct('TeleServices') PRODUCTS = list() PRODUCTS += DEPENDENCIES PRODUCTS.append('TeleServices') if EID_PRESENT: PRODUCTS.append('BelgianEidAuthPlugin') testcase = PloneTestCase.PloneTestCase ##code-section module-before-plone-site-setup #fill in your manual code here #PloneTestCase.setupPloneSite(extension_profiles=('Products.TeleServices:newsite',)) EXTENSION_PROFILES=('Products.TeleServices:test',) ##/code-section module-before-plone-site-setup #Extension profile doesn't work because appinstall of ts appears to be not run #PloneTestCase.setupPloneSite(products=PRODUCTS, extension_profiles=EXTENSION_PROFILES) PloneTestCase.setupPloneSite(products=PRODUCTS) class BaseTeleServicesTestCase(testcase): """Base TestCase for TeleServices.""" ##code-section class-header_BaseTeleServicesTestCase #fill in your manual code here def afterSetup(self): """ Manage users and permissions """ self.wft = self.portal.portal_workflow uf = self.portal.acl_users #we add the role TeleServicesManager #uf.portal_role_manager.addRole("TeleServicesManager", "TeleServicesManager", "A manager for TeleServices") self.createUser('member', ('Member',)) self.createUser('member2', ('Member',)) self.createUser('ptsmanager', ('Member','PopulationTSManager')) self.createUser('wtsmanager', ('Member','WorkTSManager')) self.createUser('admin', ('Member','Manager')) self.createUser('anon', ('Anonymous',)) # prg.addMember('anon', 'anon', roles=('Anonymous',)) #we create the memberarea for member, tsmanager and admin self.createMemberarea("member") self.createMemberarea("member2") self.createMemberarea("ptsmanager") self.createMemberarea("wtsmanager") self.createMemberarea("admin") #we create the myteleservices folder for 'member', 'tsmanager' and 'admin' #with have to be logged as a Manager to run methods from exportimport self.login('admin') #we run every steps self.portal.portal_setup.setImportContext("profile-Products.TeleServices:test") self.portal.portal_setup.runImportStep(step_id="test-teleservices") #we create the myteleservices folder for 'member', 'tsmanager' and 'admin' self.login('member') self.portal.portal_teleservices.getDemandFolder() self.login('member2') self.portal.portal_teleservices.getDemandFolder() self.login('ptsmanager') self.portal.portal_teleservices.getDemandFolder() self.login('wtsmanager') self.portal.portal_teleservices.getDemandFolder() self.login('admin') self.portal.portal_teleservices.getDemandFolder() request=self.app.REQUEST self.app._setObject('session_data_manager', DummySessionDataManager()) sdm = self.app.session_data_manager request.set('SESSION', sdm.getSessionData()) self.logout() def createUser(self, username, roles): """ create a user with the good roles """ pms = self.portal.portal_membership pms.addMember(username, 'password', [], []) self.setRoles(roles, name=username) def checkActionList(self, object, actions): """ Compare un set d'action de sorte que ['corriger', 'attendre'] soit egal a ['attendre', 'corriger'] """ obj_actions = self.getActionList(object) self.assertEquals(Set(obj_actions), Set(actions)) def getActionList(self, object): return [action_dict['name'] for action_dict in self.wft.getTransitionsFor(object)] def invokeFactoryTS(self, type_name, id, path, demand_type="", **dict): #we manage the REQUEST/SESSION ourself... self.portal.REQUEST.SESSION.set('demand_type', demand_type) if demand_type: path.invokeFactory(type_name=type_name, id=id, demandType=demand_type, followDemand=False, **dict) else: path.invokeFactory(type_name=type_name, id=id, followDemand=False, **dict) return getattr(path, id) ##/code-section class-header_BaseTeleServicesTestCase # Commented out for now, it gets blasted at the moment anyway. # Place it in the protected section if you need it. #def afterSetup(self): # """ # """ # pass def interact(self, locals=None): """Provides an interactive shell aka console inside your testcase. It looks exact like in a doctestcase and you can copy and paste code from the shell into your doctest. The locals in the testcase are available, becasue you are in the testcase. In your testcase or doctest you can invoke the shell at any point by calling:: >>> self.interact( locals() ) locals -- passed to InteractiveInterpreter.__init__() """ savestdout = sys.stdout sys.stdout = sys.stderr sys.stderr.write('='*70) console = code.InteractiveConsole(locals) console.interact(""" ZopeTestCase Interactive Console (c) BlueDynamics Alliance, Austria - 2005 Note: You have the same locals available as in your test-case. """) sys.stdout.write('\nend of ZopeTestCase Interactive Console session\n') sys.stdout.write('='*70+'\n') sys.stdout = savestdout def test_suite(): from unittest import TestSuite, makeSuite suite = TestSuite() suite.addTest(makeSuite(BaseTeleServicesTestCase)) return suite ##code-section module-footer #fill in your manual code here ##/code-section module-footer if __name__ == '__main__': framework()