# -*- coding: utf-8 -*- # # File: testDemandTypeTerm.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 from Products.validation import validation from sets import Set import string ##/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 testDemandTypeTerm(BaseTeleServicesTestCase): """Test-cases for class(es) .""" ##code-section class-header_testDemandTypeTerm #fill in your manual code here ##/code-section class-header_testDemandTypeTerm def afterSetUp(self): """ """ BaseTeleServicesTestCase.afterSetup(self) # Manually created methods def testIsValidStructuredComBegin(self): """ we test the validator isValidStructuredComBegin """ v = validation.validatorFor('isValidStructuredComBegin') # None is returned when validation is ok self.failUnlessEqual(v('a0'), 'You must enter only digits.') value = string.zfill('', SCB_LENGTH) self.failUnlessEqual(v(value), None) value += '1' self.failUnlessEqual(v(value), "The length must be less or equal to %d."%SCB_LENGTH) if SCB_LENGTH > 0: self.failUnlessEqual(v('1'), None) def testSetStructuredComBegin(self): """ while setting the structuredcombegin value, we update the structured_com_counters dictionary of TSTool """ self.login('admin') tst = self.portal.portal_teleservices dtt = tst.getTermObject('PopulationTeleService', 'DemandTypeTerm', 'ptsterm1') dtt.setStructuredComBegin('111') counters = tst.getCounters() self.failUnless(counters.has_key('111')) def testListOptionalFields(self): """ return a DisplayList of fields wich are marked as optional (CP added attribute on the Fields of TeleService) """ self.login('admin') tst = self.portal.portal_teleservices dtt = tst.getTermObject('PopulationTeleService', 'DemandTypeTerm', 'ptsterm1') res = ['childName', 'childSurname', 'childBirthDate', 'comment', 'officialComment', 'childContactPerson' , 'deceasedBirthDateOrNationalRegister', 'deceasedName', 'deceasedName2'] self.assertEquals(Set(dtt.listOptionalFields()), Set(res)) #Set on a DisplayList does a list with the first value of each tuple dtt = tst.getTermObject('WorkTeleService', 'DemandTypeTerm', 'wtsterm1') res = ['pylonNumber', 'comment', 'officialComment', 'elementsNumber'] self.assertEquals(Set(dtt.listOptionalFields()), Set(res)) def testIsPopulationDemand(self): """ return True if demandtypeterm is a population demand and False if is a work demand """ self.login('admin') tst = self.portal.portal_teleservices dtt = tst.getTermObject('PopulationTeleService', 'DemandTypeTerm', 'ptsterm1') self.assertEquals(dtt.isPopulationDemand(), True) dtt = tst.getTermObject('WorkTeleService', 'DemandTypeTerm', 'wtsterm1') res = ['pylonNumber', 'comment', 'officialComment', 'elementsNumber'] self.assertEquals(dtt.isPopulationDemand(), False) def test_suite(): from unittest import TestSuite, makeSuite suite = TestSuite() suite.addTest(makeSuite(testDemandTypeTerm)) return suite ##code-section module-footer #fill in your manual code here ##/code-section module-footer if __name__ == '__main__': framework()