# -*- coding: utf-8 -*- # # File: testWorkTeleService.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 sets import Set ##/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 testWorkTeleService(BaseTeleServicesTestCase): """Test-cases for class(es) .""" ##code-section class-header_testWorkTeleService #fill in your manual code here ##/code-section class-header_testWorkTeleService def afterSetUp(self): BaseTeleServicesTestCase.afterSetup(self) # Manually created methods def testGetFormattedTitle(self): """ Retourne le titre : demandtype """ self.login('member') member_home = self.portal.Members.member.myteleservices wts = self.invokeFactoryTS(type_name='WorkTeleService', demand_type='wtsterm1', id='wts', path=member_home) self.assertEquals(wts.getFormattedTitle(), 'WorkTeleService1') def testGetUserDemandType(self): """ Get first the demandType property on the object. If not exists, call the getDemandTypeFromRequest from portal_teleservices to try to populate the DemandType selection box. """ self.login('member') member_home = self.portal.Members.member.myteleservices wts = self.invokeFactoryTS(type_name='WorkTeleService', demand_type='wtsterm1', id='wts', path=member_home) self.assertEquals(wts.getUserDemandType(), 'wtsterm1') #we create a pts WITHOUT demand_type #demandType is required, it MUST raises a AttributeError... self.assertRaises(AttributeError, self.invokeFactoryTS, type_name='WorkTeleService', id='wts2', path=member_home) def testListWorkDemandTypes(self): """ return a list of enabled workteleservice """ self.login('member') member_home = self.portal.Members.member.myteleservices wts = self.invokeFactoryTS(type_name='WorkTeleService', demand_type='wtsterm1', id='wts', path=member_home) res = ['wtsterm1', 'wtsterm2'] self.assertEquals(Set(wts.listWorkDemandTypes()), Set(res)) #Set on a DisplayList does a list with the first value of each tuple def testCheckIfOfficialCommentInOptionalFields(self): """ check if the officialComment field is enabled for the current DemandType """ self.login('member') member_home = self.portal.Members.member.myteleservices wts = self.invokeFactoryTS(type_name='WorkTeleService', demand_type='wtsterm1', id='wts', path=member_home) self.assertEquals(wts.checkIfOfficialCommentInOptionalFields(), '') wts = self.invokeFactoryTS(type_name='WorkTeleService', demand_type='wtsterm2', id='wts1', path=member_home) self.assertEquals(wts.checkIfOfficialCommentInOptionalFields(), DEFAULT_NO_VALUE) def testCheckIfCommentInOptionalFields(self): """ check if the Comment field is enabled for the current DemandType """ self.login('member') member_home = self.portal.Members.member.myteleservices wts = self.invokeFactoryTS(type_name='WorkTeleService', demand_type='wtsterm1', id='wts', path=member_home) self.assertEquals(wts.checkIfCommentInOptionalFields(), '') wts = self.invokeFactoryTS(type_name='WorkTeleService', demand_type='wtsterm2', id='wts1', path=member_home) self.assertEquals(wts.checkIfCommentInOptionalFields(), DEFAULT_NO_VALUE) def testCheckIfElementsNumberInOptionalFields(self): """ check if the ElementsNumber field is enabled for the current DemandType """ self.login('member') member_home = self.portal.Members.member.myteleservices wts = self.invokeFactoryTS(type_name='WorkTeleService', demand_type='wtsterm1', id='wts', path=member_home) self.assertEquals(wts.checkIfElementsNumberInOptionalFields(), '') wts = self.invokeFactoryTS(type_name='WorkTeleService', demand_type='wtsterm2', id='wts1', path=member_home) self.assertEquals(wts.checkIfElementsNumberInOptionalFields(), DEFAULT_NO_VALUE) def testCheckIfPylonNumberInOptionalFields(self): """ check if the PylonNumber field is enabled for the current DemandType """ self.login('member') member_home = self.portal.Members.member.myteleservices wts = self.invokeFactoryTS(type_name='WorkTeleService', demand_type='wtsterm1', id='wts', path=member_home) self.assertEquals(wts.checkIfPylonNumberInOptionalFields(), '') wts = self.invokeFactoryTS(type_name='WorkTeleService', demand_type='wtsterm2', id='wts1', path=member_home) self.assertEquals(wts.checkIfPylonNumberInOptionalFields(), DEFAULT_NO_VALUE) def testCheckIfInOptionalFields(self): """ return DEFAULT_NO_VALUE if the field is not enabled in DemandTypeTerm.optionalFields """ self.login('member') member_home = self.portal.Members.member.myteleservices wts = self.invokeFactoryTS(type_name='WorkTeleService', demand_type='wtsterm1', id='wts', path=member_home) self.assertEquals(wts.checkIfInOptionalFields('officialComment'), '') wts = self.invokeFactoryTS(type_name='WorkTeleService', demand_type='wtsterm2', id='wts1', path=member_home) self.assertEquals(wts.checkIfInOptionalFields('officialComment'), DEFAULT_NO_VALUE) def test_suite(): from unittest import TestSuite, makeSuite suite = TestSuite() suite.addTest(makeSuite(testWorkTeleService)) return suite ##code-section module-footer #fill in your manual code here ##/code-section module-footer if __name__ == '__main__': framework()