# -*- coding: utf-8 -*- # # File: testPopulationTeleService.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 Products.validation import validation 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 testPopulationTeleService(BaseTeleServicesTestCase): """Test-cases for class(es) .""" ##code-section class-header_testPopulationTeleService #fill in your manual code here ##/code-section class-header_testPopulationTeleService def afterSetUp(self): BaseTeleServicesTestCase.afterSetup(self) # Manually created methods def testIsMemberWithEid(self): """ we test the validator isMemberWithEid """ v = validation.validatorFor('isMemberWithEid') # None is returned when validation is ok self.login('member') #demandtype with eidRequired to False -> ok self.failUnlessEqual(v('ptsterm1', **{'instance':self.portal}), True) #demandtype with eidRequired to True, member has no role MemberWithEid -> nok self.failUnlessEqual(v('ptsterm3', **{'instance':self.portal}), 'You must be connected with your eID card to order this document.') self.login('ptsmanager') #demandtype with eidRequired to True, member is TSManager -> ok self.failUnlessEqual(v('ptsterm3', **{'instance':self.portal}), True) self.login('admin') self.portal.acl_users.portal_role_manager.assignRoleToPrincipal('MemberWithEid', 'member') self.login('member') member = self.portal.portal_membership.getAuthenticatedMember() #demandtype with eidRequired to True, member has role MemberWithEid -> ok self.failUnlessEqual(v('ptsterm3', **{'instance':self.portal}), True) def testIsBelgianNationalRegOrValidDateValidator(self): """ we test the validator isBelgianNROrDate """ v = validation.validatorFor('isBelgianNROrDate') # True is returned when validation is ok self.login('member') #valid national register number self.failUnlessEqual(v('00000000097', 0), True) #valid date self.failUnlessEqual(v('12/12/1943', 0), True) #invalid national register number self.failIfEqual(v('00000000098', 0), True) #invalid national register number self.failIfEqual(v('000000098', 0), True) #invalid date self.failIfEqual(v('12/43/1943 azerty', 0), True) #invalid date self.failIfEqual(v('43/12/1942', 0), True) #invalid date self.failIfEqual(v('birthdate is 43/12/1942', 0), True) def testGetFormattedTitle(self): """ we test that getFormattedTitle() return the correct title from the demand_type """ self.login('member') #the member add a PTS member_home = self.portal.Members.member.myteleservices pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts', path=member_home) self.assertEquals(pts.getFormattedTitle(), 'PopulationTeleService1') 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') #the member add a PTS member_home = self.portal.Members.member.myteleservices #we create a pts WITH a demand_type pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts', path=member_home) #if pts hasattr demand_type, no problem self.assertEquals(pts.getUserDemandType(), 'ptsterm1') #we create a pts WITHOUT demand_type #demandType is required, it MUST raises a AttributeError... self.assertRaises(AttributeError, self.invokeFactoryTS, type_name='PopulationTeleService', id='pts2', path=member_home) def testCheckDestinationVocabFromDemandType(self): """ we check if a vocabulary exists for destination """ self.login('member') #the member add a PTS member_home = self.portal.Members.member.myteleservices #we create a pts WITH a demand_type pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts', path=member_home) #we check if a vocabulary exists for destination self.failUnless(pts.checkDestinationVocabFromDemandType()) pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm2', id='pts2', path=member_home) #we check if a vocabulary exists for destination self.failIf(pts.checkDestinationVocabFromDemandType()) def testCheckMotivationVocabFromDemandType(self): """ we check if a vocabulary exists for motivation """ self.login('member') #the member add a PTS member_home = self.portal.Members.member.myteleservices #we create a pts WITH a demand_type pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts', path=member_home) #we check if a vocabulary exists for destination self.failUnless(pts.checkMotivationVocabFromDemandType()) pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm2', id='pts2', path=member_home) #we check if a vocabulary exists for destination self.failIf(pts.checkMotivationVocabFromDemandType()) def testCalculatePrice(self): """ Calculate the price of the demand (demandType + motivation + destination) """ self.login('member') #the member add a PTS member_home = self.portal.Members.member.myteleservices #--- DEMAND WITHOUT PRICE + MOTIVATION WITH PRICE + DESTINATION WITH PRICE --- dict = { 'destination': 'destterm2', 'motivation': 'motivterm1', 'copies': 2 } pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts', path=member_home, **dict) self.assertEquals(pts.calculatePrice(), (2 * (0.7+1.14) + 0.52)) #--- DEMAND WITH PRICE + MOTIVATION WITHOUT PRICE + DESTINATION WITHOUT PRICE --- dict = { 'destination': 'destterm1', 'motivation': 'motivterm4', 'copies': 2, } pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts2', path=member_home, **dict) self.assertEquals(pts.calculatePrice(), (2 * 1.14)) #--- FREE DEMAND --- dict = { 'destination': 'destterm1', 'motivation': 'motivterm4', 'copies': 2, } pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm3', id='pts3', path=member_home, **dict) self.assertEquals(pts.calculatePrice(), 0) def testNoPaymentTransmit(self): """ Transmit a demand if no payment is required for treatment return True if no payment required (used in automatic transition from waiting_payment) """ self.login('member') member_home = self.portal.Members.member.myteleservices #--- DEMAND WITH PRICE AND DESTINATIONTERM with PAYMENTREQUIRED = True --- dict = { 'destination': 'destterm2', 'motivation': 'motivterm1', } pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts', path=member_home, **dict) #we calculatePrice because the price is set only in the confirm workflow transition pts.setAmount(pts.calculatePrice()) self.failIf(pts.noPaymentTransmit()) #--- DEMAND WITH PRICE AND DESTINATIONTERM with PAYMENTREQUIRED = False --- dict = { 'destination': 'destterm1', 'motivation': 'motivterm1', } pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts2', path=member_home, **dict) pts.setAmount(pts.calculatePrice()) self.failUnless(pts.noPaymentTransmit()) #--- TOTALY FREE DEMAND --> PRICE = 0 --- dict = { 'destination': 'destterm1', 'motivation': 'motivterm4', } pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm3', id='pts3', path=member_home, **dict) pts.setAmount(pts.calculatePrice()) self.failUnless(pts.noPaymentTransmit()) def testListPopulationDemandTypes(self): """ This will return the vocab containing the DemandTypeTerm found in portal_teleservices """ self.login('member') member_home = self.portal.Members.member.myteleservices pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts', path=member_home) res = ['ptsterm1', 'ptsterm3'] self.assertEquals(Set(pts.listPopulationDemandTypes()), Set(res)) #Set on a DisplayList does a list with the first value of each tuple def testListPopulationMotivations(self): """ This will return the vocab containing the MotivationTerm found in portal_teleservices for a particular DemandTypeTerm """ self.login('member') member_home = self.portal.Members.member.myteleservices pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts', path=member_home) res = ['motivterm1', 'motivterm2'] if ADD_EMPTY_VOCAB_VALUE: res.append('') self.assertEquals(Set(pts.listPopulationMotivations()), Set(res)) #Set on a DisplayList does a list with the first value of each tuple def testListPopulationDestinations(self): """ This will return the vocab containing the DestinationTerm found in portal_teleservices for a particular DemandTypeTerm """ self.login('member') member_home = self.portal.Members.member.myteleservices pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts', path=member_home) res = ['destterm1', 'destterm2'] if ADD_EMPTY_VOCAB_VALUE: res.append('') self.assertEquals(Set(pts.listPopulationDestinations()), Set(res)) #Set on a DisplayList does a list with the first value of each tuple def testListPaymentModes(self): """ we link a vocabulary to the String field so we save the key and display the value """ self.login('member') member_home = self.portal.Members.member.myteleservices pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts', path=member_home) self.assertEquals(Set(pts.listPaymentModes()), Set(PAYMENT_MODES)) def testCheckIfOfficialCommentInOptionalFields(self): """ check if the officialComment field is enabled for the current DemandType """ self.login('member') member_home = self.portal.Members.member.myteleservices pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts', path=member_home) self.assertEquals(pts.checkIfOfficialCommentInOptionalFields(), '') pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm2', id='pts1', path=member_home) self.assertEquals(pts.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 pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts', path=member_home) self.assertEquals(pts.checkIfCommentInOptionalFields(), '') pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm2', id='pts1', path=member_home) self.assertEquals(pts.checkIfCommentInOptionalFields(), 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 pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts', path=member_home) self.assertEquals(pts.checkIfInOptionalFields('officialComment'), '') pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm2', id='pts1', path=member_home) self.assertEquals(pts.checkIfInOptionalFields('officialComment'), DEFAULT_NO_VALUE) def testCheckIfChildNameInOptionalFields(self): """ check if the ChildName field is enabled for the current DemandType """ self.login('member') member_home = self.portal.Members.member.myteleservices pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts', path=member_home) self.assertEquals(pts.checkIfChildNameInOptionalFields(), '') pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm2', id='pts1', path=member_home) self.assertEquals(pts.checkIfChildNameInOptionalFields(), DEFAULT_NO_VALUE) def testCheckIfChildSurnameInOptionalFields(self): """ check if the ChildSurname field is enabled for the current DemandType """ self.login('member') member_home = self.portal.Members.member.myteleservices pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts', path=member_home) self.assertEquals(pts.checkIfChildSurnameInOptionalFields(), '') pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm2', id='pts1', path=member_home) self.assertEquals(pts.checkIfChildSurnameInOptionalFields(), DEFAULT_NO_VALUE) def testCheckIfChildBirthDateInOptionalFields(self): """ check if the ChildBirthDate field is enabled for the current DemandType """ self.login('member') member_home = self.portal.Members.member.myteleservices pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts', path=member_home) self.assertEquals(pts.checkIfChildBirthDateInOptionalFields(), '') pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm2', id='pts1', path=member_home) self.assertEquals(pts.checkIfChildBirthDateInOptionalFields(), DEFAULT_DATE_NO_VALUE) def testCheckFieldDisplayInPopulationTeleserviceView(self): """ check if a populationteleservice attribute can be displayed in populationteleservice_view """ self.login('member') member_home = self.portal.Members.member.myteleservices dict = { 'destination': 'destterm1', 'motivation': 'motivterm1', 'copies': 2, 'childName': 'xxx', } pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts', path=member_home) self.failIf(pts.checkFieldDisplayInPopulationTeleserviceView('title','xxx')) self.failIf(pts.checkFieldDisplayInPopulationTeleserviceView('id','xxx')) self.failIf(pts.checkFieldDisplayInPopulationTeleserviceView('excludeFromNav','xxx')) self.failIf(pts.checkFieldDisplayInPopulationTeleserviceView('test',None)) self.failIf(pts.checkFieldDisplayInPopulationTeleserviceView('test','')) self.failIf(pts.checkFieldDisplayInPopulationTeleserviceView('test',DEFAULT_NO_VALUE)) self.failIf(pts.checkFieldDisplayInPopulationTeleserviceView('test',DEFAULT_DATE_NO_VALUE)) self.failIf(pts.checkFieldDisplayInPopulationTeleserviceView('amount',0)) self.failUnless(pts.checkFieldDisplayInPopulationTeleserviceView('test','xxx')) def testCheckIfChildSurnameInOptionalFields(self): """ check if the ChildSurname field is enabled for the current DemandType """ self.login('member') member_home = self.portal.Members.member.myteleservices pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm1', id='pts', path=member_home) self.assertEquals(pts.checkIfChildSurnameInOptionalFields(), '') pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm2', id='pts1', path=member_home) self.assertEquals(pts.checkIfChildSurnameInOptionalFields(), DEFAULT_NO_VALUE) def testGetAccountDTS(self): """ get Account from demandTypeTerm (DTS) if have one """ self.login('member') member_home = self.portal.Members.member.myteleservices pts = self.invokeFactoryTS(type_name='PopulationTeleService', demand_type='ptsterm3', id='pts3', path=member_home) pts.setPopulationAccountNumber('BE54 0000 0000 0097') self.assertEquals(pts.getAccountDTS(), '') self.assertEquals(pts.getPopulationAccountNumber(), 'BE54 0000 0000 0097') def test_suite(): from unittest import TestSuite, makeSuite suite = TestSuite() suite.addTest(makeSuite(testPopulationTeleService)) return suite ##code-section module-footer #fill in your manual code here ##/code-section module-footer if __name__ == '__main__': framework()