Commit 7766ac25 authored by Aurel's avatar Aurel

add many comments in the test


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5168 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 08655107
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
############################################################################## ##############################################################################
# import requested python module
import os import os
import AccessControl import AccessControl
from zLOG import LOG from zLOG import LOG
...@@ -39,23 +39,26 @@ from Products.ERP5Type.Utils import convertToUpperCase ...@@ -39,23 +39,26 @@ from Products.ERP5Type.Utils import convertToUpperCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.Sequence import SequenceList from Products.ERP5Type.tests.Sequence import SequenceList
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from Products.DCWorkflow.DCWorkflow import Unauthorized
from Testing.ZopeTestCase.PortalTestCase import PortalTestCase
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
# Needed in order to have a log file inside the current folder # Needed in order to have a log file inside the current folder
os.environ['EVENT_LOG_FILE'] = os.path.join(os.getcwd(), 'zLOG.log') os.environ['EVENT_LOG_FILE'] = os.path.join(os.getcwd(), 'zLOG.log')
# Define the level of log we want, here is all
os.environ['EVENT_LOG_SEVERITY'] = '-300' os.environ['EVENT_LOG_SEVERITY'] = '-300'
# Define how to launch the script if we don't use runUnitTest script
from Products.DCWorkflow.DCWorkflow import Unauthorized if __name__ == '__main__':
from Testing.ZopeTestCase.PortalTestCase import PortalTestCase execfile(os.path.join(sys.path[0], 'framework.py'))
class TestERP5BankingCashTransfer(ERP5TypeTestCase): class TestERP5BankingCashTransfer(ERP5TypeTestCase):
""" """
This class is a unit test to check the module of Cash Transfer
Here are the following step that will be done in the test :
- before the test, we need to create some movements that will put resources in the source - before the test, we need to create some movements that will put resources in the source
- create a cash transfer - create a cash transfer
...@@ -102,14 +105,14 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase): ...@@ -102,14 +105,14 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase):
def getTitle(self): def getTitle(self):
""" """
Return the title Return the title of the test
""" """
return "ERP5BankingCashTransfer" return "ERP5BankingCashTransfer"
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
""" """
Return the list of business templates we need Return the list of business templates we need to run the test
""" """
return ( 'erp5_trade' # erp5_trade is not required to make erp5_banking_cash_transfer working. return ( 'erp5_trade' # erp5_trade is not required to make erp5_banking_cash_transfer working.
# As explained below erp5_trade is just used to help us initialize ressources # As explained below erp5_trade is just used to help us initialize ressources
...@@ -135,12 +138,18 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase): ...@@ -135,12 +138,18 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase):
def afterSetUp(self): def afterSetUp(self):
""" """
Method called before the test to initialize some data
""" """
# Set variables # Set some variables :
# the erp5 site
self.portal = self.getPortal() self.portal = self.getPortal()
# the cahs transfer module
self.cash_transfer_module = self.getCashTransferModule() self.cash_transfer_module = self.getCashTransferModule()
# the person module
self.person_folder = self.getPersonModule() self.person_folder = self.getPersonModule()
# the organisation module
self.organisation_folder = self.getOrganisationModule() self.organisation_folder = self.getOrganisationModule()
# the categort tool
self.category_tool = self.getCategoryTool() self.category_tool = self.getCategoryTool()
# Let us know which user folder is used # Let us know which user folder is used
...@@ -150,48 +159,85 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase): ...@@ -150,48 +159,85 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase):
self.createManagerAndLogin() self.createManagerAndLogin()
# Define static values (only use prime numbers to prevent confusions like 2 * 6 == 3 * 4) # Define static values (only use prime numbers to prevent confusions like 2 * 6 == 3 * 4)
# the list of years fo banknotes and coin
self.variation_list = ('variation/1992', 'variation/2003') self.variation_list = ('variation/1992', 'variation/2003')
# quantity of banknotes of 10000 :
self.quantity_10000 = {} self.quantity_10000 = {}
# 2 banknotes of 10000 for the year 1992
self.quantity_10000[self.variation_list[0]] = 2 self.quantity_10000[self.variation_list[0]] = 2
# 3 banknotes of 10000 for the year of 2003
self.quantity_10000[self.variation_list[1]] = 3 self.quantity_10000[self.variation_list[1]] = 3
# quantity of coin of 200
self.quantity_200 = {} self.quantity_200 = {}
# 5 coins of 200 for the year 1992
self.quantity_200[self.variation_list[0]] = 5 self.quantity_200[self.variation_list[0]] = 5
# 7 coins of 200 for the year 2003
self.quantity_200[self.variation_list[1]] = 7 self.quantity_200[self.variation_list[1]] = 7
# quantity of banknotes of 5000
self.quantity_5000 = {} self.quantity_5000 = {}
# 11 banknotes of 5000 for hte year 1992
self.quantity_5000[self.variation_list[0]] = 11 self.quantity_5000[self.variation_list[0]] = 11
# 13 banknotes of 5000 for the year 2003
self.quantity_5000[self.variation_list[1]] = 13 self.quantity_5000[self.variation_list[1]] = 13
# Create Categories (vaults) # Create Categories (vaults)
#self.createCategories()
# as local roles are defined in portal types as real categories, we will need to reproduce (or import) the real category tree # as local roles are defined in portal types as real categories, we will need to reproduce (or import) the real category tree
# get the base category function
self.function_base_category = getattr(self.category_tool, 'function') self.function_base_category = getattr(self.category_tool, 'function')
# add category banking in function which hold all functions neccessary for bank
self.banking = self.function_base_category.newContent(id='banking', portal_type='Category', codification='BNK') self.banking = self.function_base_category.newContent(id='banking', portal_type='Category', codification='BNK')
# add category caisier_principal in function banking
self.caissier_principal = self.banking.newContent(id='caissier_principal', portal_type='Category', codification='CCP') self.caissier_principal = self.banking.newContent(id='caissier_principal', portal_type='Category', codification='CCP')
# add category controleur_caisse in function banking
self.controleur_caisse = self.banking.newContent(id='controleur_caisse', portal_type='Category', codification='CCT') self.controleur_caisse = self.banking.newContent(id='controleur_caisse', portal_type='Category', codification='CCT')
# add category void_function in function banking
self.void_function = self.banking.newContent(id='void_function', portal_type='Category', codification='VOID') self.void_function = self.banking.newContent(id='void_function', portal_type='Category', codification='VOID')
# add category gestionnaire_caisse_courante in function banking
self.gestionnaire_caisse_courante = self.banking.newContent(id='gestionnaire_caisse_courante', portal_type='Category', codification='CCO') self.gestionnaire_caisse_courante = self.banking.newContent(id='gestionnaire_caisse_courante', portal_type='Category', codification='CCO')
# add category gestionnaire_caveau in function banking
self.gestionnaire_caveau = self.banking.newContent(id='gestionnaire_caveau', portal_type='Category', codification='CCV') self.gestionnaire_caveau = self.banking.newContent(id='gestionnaire_caveau', portal_type='Category', codification='CCV')
# add category caissier_particulier in function banking
self.caissier_particulier = self.banking.newContent(id='caissier_particulier', portal_type='Category', codification='CGU') self.caissier_particulier = self.banking.newContent(id='caissier_particulier', portal_type='Category', codification='CGU')
# get the base category group
self.group_base_category = getattr(self.category_tool, 'group') self.group_base_category = getattr(self.category_tool, 'group')
# add the group baobab in the group category
self.baobab = self.group_base_category.newContent(id='baobab', portal_type='Category', codification='BAOBAB') self.baobab = self.group_base_category.newContent(id='baobab', portal_type='Category', codification='BAOBAB')
# get the base category site
self.site_base_category = getattr(self.category_tool, 'site') self.site_base_category = getattr(self.category_tool, 'site')
# add the category testsite in the category site which hold vault situated in the bank
self.testsite = self.site_base_category.newContent(id='testsite', portal_type='Category', codification='TEST') self.testsite = self.site_base_category.newContent(id='testsite', portal_type='Category', codification='TEST')
# add vault caisse_1 in testsite
self.caisse_1 = self.testsite.newContent(id='caisse_1', portal_type='Category', codification='C1') self.caisse_1 = self.testsite.newContent(id='caisse_1', portal_type='Category', codification='C1')
# add vault caisse_2 in testsite
self.caisse_2 = self.testsite.newContent(id='caisse_2', portal_type='Category', codification='C2') self.caisse_2 = self.testsite.newContent(id='caisse_2', portal_type='Category', codification='C2')
# get the base category cash_status
self.cash_status_base_category = getattr(self.category_tool, 'cash_status') self.cash_status_base_category = getattr(self.category_tool, 'cash_status')
# add the category valid in cash_status which define status of banknotes and coin
self.cash_status_valid = self.cash_status_base_category.newContent(id='valid', portal_type='Category') self.cash_status_valid = self.cash_status_base_category.newContent(id='valid', portal_type='Category')
# get the base category emission letter
self.emission_letter_base_category = getattr(self.category_tool, 'emission_letter') self.emission_letter_base_category = getattr(self.category_tool, 'emission_letter')
# add the category k in emission letter
self.emission_letter_k = self.emission_letter_base_category.newContent(id='k', portal_type='Category') self.emission_letter_k = self.emission_letter_base_category.newContent(id='k', portal_type='Category')
# get the base category variation which hold the year of banknotes and coins
self.variation_base_category = getattr(self.category_tool, 'variation') self.variation_base_category = getattr(self.category_tool, 'variation')
# add the category 1992 in variation
self.variation_1992 = self.variation_base_category.newContent(id='1992', portal_type='Category') self.variation_1992 = self.variation_base_category.newContent(id='1992', portal_type='Category')
# add the category 2003 in varitation
self.variation_2003 = self.variation_base_category.newContent(id='2003', portal_type='Category') self.variation_2003 = self.variation_base_category.newContent(id='2003', portal_type='Category')
# get the base category quantity_unit
self.variation_base_category = getattr(self.category_tool, 'quantity_unit') self.variation_base_category = getattr(self.category_tool, 'quantity_unit')
# add category unit in quantity_unit which is the unit of banknotes and coins
self.unit = self.variation_base_category.newContent(id='unit', title='Unit') self.unit = self.variation_base_category.newContent(id='unit', title='Unit')
# Create an Organisation that will be used for users assignment # Create an Organisation that will be used for users assignment
...@@ -208,6 +254,7 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase): ...@@ -208,6 +254,7 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase):
, 'user_2' : [[], self.organisation, 'banking/controleur_caisse' , 'baobab', 'testsite'] , 'user_2' : [[], self.organisation, 'banking/controleur_caisse' , 'baobab', 'testsite']
, 'user_3' : [[], self.organisation, 'banking/void_function' , 'baobab', 'testsite'] , 'user_3' : [[], self.organisation, 'banking/void_function' , 'baobab', 'testsite']
} }
# call method to create this user
self.createERP5Users(user_dict) self.createERP5Users(user_dict)
# We must assign local roles to cash_transfer_module manually, as they are # We must assign local roles to cash_transfer_module manually, as they are
...@@ -218,37 +265,48 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase): ...@@ -218,37 +265,48 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase):
# The group local roles must be the one for gestionnaire_caisse_courante # The group local roles must be the one for gestionnaire_caisse_courante
self.cash_transfer_module.manage_addLocalGroupRoles('CCO_BAOBAB_TEST', ('Author',)) self.cash_transfer_module.manage_addLocalGroupRoles('CCO_BAOBAB_TEST', ('Author',))
# Create a Currency # get the currency module
self.currency_module = self.getCurrencyModule() self.currency_module = self.getCurrencyModule()
# create the currency euro inside the currency module
self.currency_1 = self .currency_module.newContent(id='EUR', title='Euro') self.currency_1 = self .currency_module.newContent(id='EUR', title='Euro')
# Create Resources (Banknotes) # Create Resources (Banknotes)
# get the currency cash module
self.currency_cash_module = self.getCurrencyCashModule() self.currency_cash_module = self.getCurrencyCashModule()
# create banknote of 10000 euros from years 1992 and 2003
self.billet_10000 = self.currency_cash_module.newContent(id='billet_10000', portal_type='Banknote', base_price=10000, price_currency_value=self.currency_1, variation_list=('1992', '2003'), quantity_unit_value=self.unit) self.billet_10000 = self.currency_cash_module.newContent(id='billet_10000', portal_type='Banknote', base_price=10000, price_currency_value=self.currency_1, variation_list=('1992', '2003'), quantity_unit_value=self.unit)
# create banknote of 500 euros from years 1992 and 2003
self.billet_5000 = self.currency_cash_module.newContent(id='billet_5000', portal_type='Banknote', base_price=5000, price_currency_value=self.currency_1, variation_list=('1992', '2003'), quantity_unit_value=self.unit) self.billet_5000 = self.currency_cash_module.newContent(id='billet_5000', portal_type='Banknote', base_price=5000, price_currency_value=self.currency_1, variation_list=('1992', '2003'), quantity_unit_value=self.unit)
# create coin of 200 euros from years 1992 and 2003
self.piece_200 = self.currency_cash_module.newContent(id='piece_200', portal_type='Coin', base_price=200, price_currency_value=self.currency_1, variation_list=('1992', '2003'), quantity_unit_value=self.unit) self.piece_200 = self.currency_cash_module.newContent(id='piece_200', portal_type='Coin', base_price=200, price_currency_value=self.currency_1, variation_list=('1992', '2003'), quantity_unit_value=self.unit)
# Before the test, we need to create resources in the source. # Before the test, we need to create resources in the source.
# Using internal_packing_list from erp5_trade is the easiest. # Using internal_packing_list from erp5_trade is the easiest.
# set the type of delivery
self.portal.portal_delivery_type_list = list(self.portal.portal_delivery_type_list) self.portal.portal_delivery_type_list = list(self.portal.portal_delivery_type_list)
self.portal.portal_delivery_type_list.append('Internal Packing List') self.portal.portal_delivery_type_list.append('Internal Packing List')
self.portal.portal_delivery_type_list = tuple(self.portal.portal_delivery_type_list) self.portal.portal_delivery_type_list = tuple(self.portal.portal_delivery_type_list)
# set the type of delivey movement
self.portal.portal_delivery_movement_type_list = list(self.portal.portal_delivery_movement_type_list) self.portal.portal_delivery_movement_type_list = list(self.portal.portal_delivery_movement_type_list)
self.portal.portal_delivery_movement_type_list.append('Internal Packing List Line') self.portal.portal_delivery_movement_type_list.append('Internal Packing List Line')
self.portal.portal_delivery_movement_type_list = tuple(self.portal.portal_delivery_movement_type_list) self.portal.portal_delivery_movement_type_list = tuple(self.portal.portal_delivery_movement_type_list)
# get the internal packing list module
self.internal_packing_list_module = self.getInternalPackingListModule() self.internal_packing_list_module = self.getInternalPackingListModule()
# add a new packing list for caisse_1
self.internal_packing_list = self.internal_packing_list_module.newContent(id='packing_list_1', portal_type='Internal Packing List', self.internal_packing_list = self.internal_packing_list_module.newContent(id='packing_list_1', portal_type='Internal Packing List',
source=None, destination_value=self.caisse_1) source=None, destination_value=self.caisse_1)
# add banknotes of 10000 with emission letter k, status valid and from years 1992 and 2003 with the quantity defined before in quantity_10000 (2 for 1992 and 3 for 2003)
self.addCashLineToDelivery(self.internal_packing_list, 'delivery_init_1', 'Internal Packing List Line', self.billet_10000, self.addCashLineToDelivery(self.internal_packing_list, 'delivery_init_1', 'Internal Packing List Line', self.billet_10000,
('emission_letter', 'cash_status', 'variation'), ('emission_letter/k', 'cash_status/valid') + self.variation_list, ('emission_letter', 'cash_status', 'variation'), ('emission_letter/k', 'cash_status/valid') + self.variation_list,
self.quantity_10000) self.quantity_10000)
# add coins of 200 with emission letter k, status valid and from years 1992 and 2003 with the quantity defined before in quantity_200 (5 for 1992 and 7 for 2003)
self.addCashLineToDelivery(self.internal_packing_list, 'delivery_init_2', 'Internal Packing List Line', self.piece_200, self.addCashLineToDelivery(self.internal_packing_list, 'delivery_init_2', 'Internal Packing List Line', self.piece_200,
('emission_letter', 'cash_status', 'variation'), ('emission_letter/k', 'cash_status/valid') + self.variation_list, ('emission_letter', 'cash_status', 'variation'), ('emission_letter/k', 'cash_status/valid') + self.variation_list,
self.quantity_200) self.quantity_200)
# Finally, login as user_1 # logout from manager
self.logout() self.logout()
# Finally, login as user_1
self.login('user_1') self.login('user_1')
...@@ -259,6 +317,7 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase): ...@@ -259,6 +317,7 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase):
self.user_folder = self.getUserFolder() self.user_folder = self.getUserFolder()
self.PAS_installed = 0 self.PAS_installed = 0
if self.user_folder.meta_type == 'Pluggable Auth Service': if self.user_folder.meta_type == 'Pluggable Auth Service':
# we use PAS
self.PAS_installed = 1 self.PAS_installed = 1
...@@ -326,15 +385,19 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase): ...@@ -326,15 +385,19 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase):
def addCashLineToDelivery(self, delivery_object, line_id, line_portal_type, resource_object, def addCashLineToDelivery(self, delivery_object, line_id, line_portal_type, resource_object,
variation_base_category_list, variation_category_list, resource_quantity_dict): variation_base_category_list, variation_category_list, resource_quantity_dict):
""" """
Add a cash line to a delivery
""" """
base_id = 'movement' base_id = 'movement'
line_kwd = {'base_id':base_id} line_kwd = {'base_id':base_id}
# create the line
line = delivery_object.newContent( id = line_id line = delivery_object.newContent( id = line_id
, portal_type = line_portal_type , portal_type = line_portal_type
, resource_value = resource_object , resource_value = resource_object # banknote or coin
, quantity_unit_value = self.unit , quantity_unit_value = self.unit
) )
# set base cateogy list
line.setVariationBaseCategoryList(variation_base_category_list) line.setVariationBaseCategoryList(variation_base_category_list)
# set category
line.setVariationCategoryList(variation_category_list) line.setVariationCategoryList(variation_category_list)
line.updateCellRange(script_id='CashDetail_asCellRange', base_id=base_id) line.updateCellRange(script_id='CashDetail_asCellRange', base_id=base_id)
cell_range_key_list = line.getCellRangeKeyList(base_id=base_id) cell_range_key_list = line.getCellRangeKeyList(base_id=base_id)
...@@ -348,42 +411,70 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase): ...@@ -348,42 +411,70 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase):
, category_list = category_list , category_list = category_list
, force_update = 1 , force_update = 1
) )
# set quantity on cell
for variation in self.variation_list: for variation in self.variation_list:
cell = line.getCell('emission_letter/k', variation, 'cash_status/valid') cell = line.getCell('emission_letter/k', variation, 'cash_status/valid')
cell.setQuantity(resource_quantity_dict[variation]) cell.setQuantity(resource_quantity_dict[variation])
# cell.setResourceValue(resource_object)
# cell.setDestinationValue(self.caisse_1)
# LOG("XXX set Resource Value >>>>>>",0, repr(resource_object))
# LOG("XXX set Destination Value >>>>>>",0, repr(self.caisse_1))
# LOG("XXX get Destination Value On Cell >>>>>>",0, repr(cell))
# LOG("XXX get Destination Value >>>>>>",0, repr(cell.getDestinationValue()))
# LOG("XXX get Baobab Destination Value >>>>>>",0, repr(cell.getBaobabDestinationValue()))
# LOG("XXX get Destination UID >>>>>>",0, repr(cell.getDestinationUid()))
# LOG("XXX get Baobab Destination UID >>>>>>",0, repr(cell.getBaobabDestinationUid()))
# LOG("XXX getBaobabDestinationUID func >>>>>>",0, repr(getattr(cell, 'getBaobabDestinationUid', None)))
# LOG("XXX func dict >>>>>>",0, repr(getattr(cell, 'getBaobabDestinationUid', None).__dict__))
# LOG("XXX func module >>>>>>",0, repr(getattr(cell, 'getBaobabDestinationUid', None).__module__))
def getUserFolder(self): def getUserFolder(self):
"""
Return the user folder
"""
return getattr(self.getPortal(), 'acl_users', None) return getattr(self.getPortal(), 'acl_users', None)
def getPersonModule(self): def getPersonModule(self):
"""
Return the person module
"""
return getattr(self.getPortal(), 'person_module', None) return getattr(self.getPortal(), 'person_module', None)
def getOrganisationModule(self): def getOrganisationModule(self):
"""
Return the organisation module
"""
return getattr(self.getPortal(), 'organisation_module', None) return getattr(self.getPortal(), 'organisation_module', None)
def getCurrencyCashModule(self): def getCurrencyCashModule(self):
"""
Return the Currency Cash Module
"""
return getattr(self.getPortal(), 'currency_cash_module', None) return getattr(self.getPortal(), 'currency_cash_module', None)
def getCashTransferModule(self): def getCashTransferModule(self):
"""
Return the Cash Transer Module
"""
return getattr(self.getPortal(), 'cash_transfer_module', None) return getattr(self.getPortal(), 'cash_transfer_module', None)
def getInternalPackingListModule(self): def getInternalPackingListModule(self):
"""
Return the Internal Packing List Module
"""
return getattr(self.getPortal(), 'internal_packing_list_module', None) return getattr(self.getPortal(), 'internal_packing_list_module', None)
def getCurrencyModule(self): def getCurrencyModule(self):
"""
Return the Currency Module
"""
return getattr(self.getPortal(), 'currency_module', None) return getattr(self.getPortal(), 'currency_module', None)
def getCategoryTool(self): def getCategoryTool(self):
"""
Return the Category Tool
"""
return getattr(self.getPortal(), 'portal_categories', None) return getattr(self.getPortal(), 'portal_categories', None)
def getWorkflowTool(self): def getWorkflowTool(self):
"""
Return the Worklfow Tool
"""
return getattr(self.getPortal(), 'portal_workflow', None) return getattr(self.getPortal(), 'portal_workflow', None)
def getSimulationTool(self): def getSimulationTool(self):
"""
Return the Simulation Tool
"""
return getattr(self.getPortal(), 'portal_simulation', None) return getattr(self.getPortal(), 'portal_simulation', None)
...@@ -394,76 +485,104 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase): ...@@ -394,76 +485,104 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase):
def stepTic(self, **kwd): def stepTic(self, **kwd):
""" """
The is used to simulate the zope_tic_loop script
""" """
self.tic() self.tic()
def stepCheckObjects(self, sequence=None, sequence_list=None, **kwd): def stepCheckObjects(self, sequence=None, sequence_list=None, **kwd):
""" """
Check that all the objects we created in afterSetUp or Check that all the objects we created in afterSetUp or
that were added by the business template and that we rely that were added by the business template and that we rely
on are really here. on are really here.
""" """
# check that Categories were created # check that Categories were created
self.assertEqual(self.caisse_1.getPortalType(), 'Category') self.assertEqual(self.caisse_1.getPortalType(), 'Category')
self.assertEqual(self.caisse_2.getPortalType(), 'Category') self.assertEqual(self.caisse_2.getPortalType(), 'Category')
# check that Resources were created # check that Resources were created
# check portal type of billet_10000
self.assertEqual(self.billet_10000.getPortalType(), 'Banknote') self.assertEqual(self.billet_10000.getPortalType(), 'Banknote')
# check value of billet_10000
self.assertEqual(self.billet_10000.getBasePrice(), 10000) self.assertEqual(self.billet_10000.getBasePrice(), 10000)
# check currency value of billet_10000
self.assertEqual(self.billet_10000.getPriceCurrency(), 'currency_module/EUR') self.assertEqual(self.billet_10000.getPriceCurrency(), 'currency_module/EUR')
# check years of billet_10000
self.assertEqual(self.billet_10000.getVariationList(), ['1992', '2003']) self.assertEqual(self.billet_10000.getVariationList(), ['1992', '2003'])
# check portal type of billet_5000
self.assertEqual(self.billet_5000.getPortalType(), 'Banknote') self.assertEqual(self.billet_5000.getPortalType(), 'Banknote')
# check value of billet_5000
self.assertEqual(self.billet_5000.getBasePrice(), 5000) self.assertEqual(self.billet_5000.getBasePrice(), 5000)
# check currency value of billet_5000
self.assertEqual(self.billet_5000.getPriceCurrency(), 'currency_module/EUR') self.assertEqual(self.billet_5000.getPriceCurrency(), 'currency_module/EUR')
# check years of billet_5000
self.assertEqual(self.billet_5000.getVariationList(), ['1992', '2003']) self.assertEqual(self.billet_5000.getVariationList(), ['1992', '2003'])
# check portal type of piece_200
self.assertEqual(self.piece_200.getPortalType(), 'Coin') self.assertEqual(self.piece_200.getPortalType(), 'Coin')
# check value of piece_200
self.assertEqual(self.piece_200.getBasePrice(), 200) self.assertEqual(self.piece_200.getBasePrice(), 200)
# check currency value of piece_200
self.assertEqual(self.piece_200.getPriceCurrency(), 'currency_module/EUR') self.assertEqual(self.piece_200.getPriceCurrency(), 'currency_module/EUR')
# check years of piece_200
self.assertEqual(self.piece_200.getVariationList(), ['1992', '2003']) self.assertEqual(self.piece_200.getVariationList(), ['1992', '2003'])
# check that CashTransfer Module was created # check that CashTransfer Module was created
self.assertEqual(self.cash_transfer_module.getPortalType(), 'Cash Transfer Module') self.assertEqual(self.cash_transfer_module.getPortalType(), 'Cash Transfer Module')
# check cash transfer module is empty
self.assertEqual(len(self.cash_transfer_module.objectValues()), 0) self.assertEqual(len(self.cash_transfer_module.objectValues()), 0)
def stepCheckInitialInventory(self, sequence=None, sequence_list=None, **kwd): def stepCheckInitialInventory(self, sequence=None, sequence_list=None, **kwd):
""" """
Check the initial inventory. Check the initial inventory.
""" """
self.simulation_tool = self.getSimulationTool() self.simulation_tool = self.getSimulationTool()
# check we have 5 banknotes of 10000
self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_1.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0) self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_1.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0)
self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_1.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0) self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_1.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0)
# check we have 12 coin of 200
self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_1.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 12.0) self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_1.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 12.0)
self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_1.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 12.0) self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_1.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 12.0)
def stepCheckSource(self, sequence=None, sequence_list=None, **kwd): def stepCheckSource(self, sequence=None, sequence_list=None, **kwd):
""" """
Check inventory in source vault
""" """
# check we have 5 banknotes of 10000
self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_1.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0) self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_1.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0)
self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_1.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0) self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_1.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0)
# check we have 12 coin of 200
self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_1.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 12.0) self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_1.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 12.0)
self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_1.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 12.0) self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_1.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 12.0)
def stepCheckDestination(self, sequence=None, sequence_list=None, **kwd): def stepCheckDestination(self, sequence=None, sequence_list=None, **kwd):
""" """
Check inventory in destination vault
""" """
# check we don't have banknotes of 10000
self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_2.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 0.0) self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_2.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 0.0)
self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_2.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 0.0) self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_2.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 0.0)
# check we don't have coins of 200
self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_2.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 0.0) self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_2.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 0.0)
self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_2.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 0.0) self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_2.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 0.0)
def stepCheckCashTransfer(self, sequence=None, sequence_list=None, **kwd): def stepCheckCashTransfer(self, sequence=None, sequence_list=None, **kwd):
""" """
Check data in the cash transfer
""" """
# check wehave only one cash transfer
self.assertEqual(len(self.cash_transfer_module.objectValues()), 1) self.assertEqual(len(self.cash_transfer_module.objectValues()), 1)
# get the cash transfer
self.cash_transfer = getattr(self.cash_transfer_module, 'cash_transfer_1') self.cash_transfer = getattr(self.cash_transfer_module, 'cash_transfer_1')
# check its portal type
self.assertEqual(self.cash_transfer.getPortalType(), 'Cash Transfer') self.assertEqual(self.cash_transfer.getPortalType(), 'Cash Transfer')
# check its source
self.assertEqual(self.cash_transfer.getSource(), 'site/testsite/caisse_1') self.assertEqual(self.cash_transfer.getSource(), 'site/testsite/caisse_1')
# check its destination
self.assertEqual(self.cash_transfer.getDestination(), 'site/testsite/caisse_2') self.assertEqual(self.cash_transfer.getDestination(), 'site/testsite/caisse_2')
#XXX Check roles were correctly affected #XXX Check roles were correctly affected
#self.security_manager = AccessControl.getSecurityManager() #self.security_manager = AccessControl.getSecurityManager()
...@@ -473,23 +592,38 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase): ...@@ -473,23 +592,38 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase):
def stepCheckValidLine1(self, sequence=None, sequence_list=None, **kwd): def stepCheckValidLine1(self, sequence=None, sequence_list=None, **kwd):
""" """
Check the valid line as been well created
""" """
# check there is only one line
self.assertEqual(len(self.cash_transfer.objectValues()), 1) self.assertEqual(len(self.cash_transfer.objectValues()), 1)
# get the line
self.valid_line_1 = getattr(self.cash_transfer, 'valid_line_1') self.valid_line_1 = getattr(self.cash_transfer, 'valid_line_1')
# check portal type
self.assertEqual(self.valid_line_1.getPortalType(), 'Cash Transfer Line') self.assertEqual(self.valid_line_1.getPortalType(), 'Cash Transfer Line')
# check the resource is banknotes of 10000
self.assertEqual(self.valid_line_1.getResourceValue(), self.billet_10000) self.assertEqual(self.valid_line_1.getResourceValue(), self.billet_10000)
# chek the value of the banknote
self.assertEqual(self.valid_line_1.getPrice(), 10000.0) self.assertEqual(self.valid_line_1.getPrice(), 10000.0)
# check the unit of banknote
self.assertEqual(self.valid_line_1.getQuantityUnit(), 'quantity_unit/unit') self.assertEqual(self.valid_line_1.getQuantityUnit(), 'quantity_unit/unit')
# check we have two cells: (one for year 1992 and one for 2003)
self.assertEqual(len(self.valid_line_1.objectValues()), 2) self.assertEqual(len(self.valid_line_1.objectValues()), 2)
for variation in self.variation_list: for variation in self.variation_list:
# get the cell
cell = self.valid_line_1.getCell('emission_letter/k', variation, 'cash_status/valid') cell = self.valid_line_1.getCell('emission_letter/k', variation, 'cash_status/valid')
# chek portal types
self.assertEqual(cell.getPortalType(), 'Delivery Cell') self.assertEqual(cell.getPortalType(), 'Delivery Cell')
# check the banknote of the cell is banknote of 10000
self.assertEqual(cell.getResourceValue(), self.billet_10000)
# check the source vault is caisse_1
self.assertEqual(cell.getSourceValue(), self.caisse_1)
# check the destination vault is caisse_2
self.assertEqual(cell.getDestinationValue(), self.caisse_2)
if cell.getId() == 'movement_0_0_0': if cell.getId() == 'movement_0_0_0':
# check the quantity of banknote for year 1992 is 2
self.assertEqual(cell.getQuantity(), 2.0) self.assertEqual(cell.getQuantity(), 2.0)
self.assertEqual(cell.getResourceValue(), self.billet_10000)
self.assertEqual(cell.getSourceValue(), self.caisse_1)
self.assertEqual(cell.getDestinationValue(), self.caisse_2)
elif cell.getId() == 'movement_0_1_0': elif cell.getId() == 'movement_0_1_0':
# check the quantity of banknote for year 2003 is 3
self.assertEqual(cell.getQuantity(), 3.0) self.assertEqual(cell.getQuantity(), 3.0)
else: else:
self.fail('Wrong cell created : %s' % cell.getId()) self.fail('Wrong cell created : %s' % cell.getId())
...@@ -497,29 +631,44 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase): ...@@ -497,29 +631,44 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase):
def stepCheckSubTotal(self, sequence=None, sequence_list=None, **kwd): def stepCheckSubTotal(self, sequence=None, sequence_list=None, **kwd):
""" """
Check the amount after the creation of line 1
""" """
# Check number of lines # Check number of lines
self.assertEqual(len(self.cash_transfer.objectValues()), 1) self.assertEqual(len(self.cash_transfer.objectValues()), 1)
# Check sum # Check quantity of banknotes (2 for 1992 and 3 for 2003)
self.assertEqual(self.cash_transfer.getTotalQuantity(), 5.0) self.assertEqual(self.cash_transfer.getTotalQuantity(), 5.0)
# Check the total price
self.assertEqual(self.cash_transfer.getTotalPrice(), 10000 * 5.0) self.assertEqual(self.cash_transfer.getTotalPrice(), 10000 * 5.0)
def stepCheckValidLine2(self, sequence=None, sequence_list=None, **kwd): def stepCheckValidLine2(self, sequence=None, sequence_list=None, **kwd):
""" """
Check the line 2 has been well created
""" """
# check the number of lines (line1 + line2)
self.assertEqual(len(self.cash_transfer.objectValues()), 2) self.assertEqual(len(self.cash_transfer.objectValues()), 2)
# get the second line
self.valid_line_2 = getattr(self.cash_transfer, 'valid_line_2') self.valid_line_2 = getattr(self.cash_transfer, 'valid_line_2')
# check portal types
self.assertEqual(self.valid_line_2.getPortalType(), 'Cash Transfer Line') self.assertEqual(self.valid_line_2.getPortalType(), 'Cash Transfer Line')
# check the resource is coin of 200
self.assertEqual(self.valid_line_2.getResourceValue(), self.piece_200) self.assertEqual(self.valid_line_2.getResourceValue(), self.piece_200)
# check the value
self.assertEqual(self.valid_line_2.getPrice(), 200.0) self.assertEqual(self.valid_line_2.getPrice(), 200.0)
# check the unit
self.assertEqual(self.valid_line_2.getQuantityUnit(), 'quantity_unit/unit') self.assertEqual(self.valid_line_2.getQuantityUnit(), 'quantity_unit/unit')
# check we have two cells: (one for year 1992 and one for 2003)
self.assertEqual(len(self.valid_line_2.objectValues()), 2)
for variation in self.variation_list: for variation in self.variation_list:
# get the cell
cell = self.valid_line_2.getCell('emission_letter/k', variation, 'cash_status/valid') cell = self.valid_line_2.getCell('emission_letter/k', variation, 'cash_status/valid')
# check the portal type
self.assertEqual(cell.getPortalType(), 'Delivery Cell') self.assertEqual(cell.getPortalType(), 'Delivery Cell')
if cell.getId() == 'movement_0_0_0': if cell.getId() == 'movement_0_0_0':
# check the quantity for coin for year 1992 is 5
self.assertEqual(cell.getQuantity(), 5.0) self.assertEqual(cell.getQuantity(), 5.0)
elif cell.getId() == 'movement_0_1_0': elif cell.getId() == 'movement_0_1_0':
# check the quantity for coin for year 2003 is 7
self.assertEqual(cell.getQuantity(), 7.0) self.assertEqual(cell.getQuantity(), 7.0)
else: else:
self.fail('Wrong cell created : %s' % cell.getId()) self.fail('Wrong cell created : %s' % cell.getId())
...@@ -527,114 +676,162 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase): ...@@ -527,114 +676,162 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase):
def stepCheckTotal(self, sequence=None, sequence_list=None, **kwd): def stepCheckTotal(self, sequence=None, sequence_list=None, **kwd):
""" """
Check the total after the creation of the two lines
""" """
# Check number of lines # Check number of lines (line1 + line2)
self.assertEqual(len(self.cash_transfer.objectValues()), 2) self.assertEqual(len(self.cash_transfer.objectValues()), 2)
# Check sum # Check quantity, banknotes : 2 for 1992 and 3 for 2003, coin : 5 for 1992 and 7 for 2003
self.assertEqual(self.cash_transfer.getTotalQuantity(), 5.0 + 12.0) self.assertEqual(self.cash_transfer.getTotalQuantity(), 5.0 + 12.0)
# check the total price
self.assertEqual(self.cash_transfer.getTotalPrice(), 10000 * 5.0 + 200 * 12.0) self.assertEqual(self.cash_transfer.getTotalPrice(), 10000 * 5.0 + 200 * 12.0)
def stepCheckBadTotal(self, sequence=None, sequence_list=None, **kwd): def stepCheckBadTotal(self, sequence=None, sequence_list=None, **kwd):
""" """
Check the total with the invalid line
""" """
# Check number of lines # Check number of lines
self.assertEqual(len(self.cash_transfer.objectValues()), 3) self.assertEqual(len(self.cash_transfer.objectValues()), 3)
# Check sum # Check quantity, same as checkTotal + banknote of 500: 11 for 1992 and 13 for 2003
self.assertEqual(self.cash_transfer.getTotalQuantity(), 5.0 + 12.0 + 24) self.assertEqual(self.cash_transfer.getTotalQuantity(), 5.0 + 12.0 + 24)
# chect the total price
self.assertEqual(self.cash_transfer.getTotalPrice(), 10000 * 5.0 + 200 * 12.0 + 5000 * 24) self.assertEqual(self.cash_transfer.getTotalPrice(), 10000 * 5.0 + 200 * 12.0 + 5000 * 24)
def stepCheckBadUserConfirmCashTransfer(self, sequence=None, sequence_list=None, **kwd): def stepCheckBadUserConfirmCashTransfer(self, sequence=None, sequence_list=None, **kwd):
""" """
Check that the try of confirm by a bad user doesn't change the cahs transfer
""" """
# get state of cash transfer
state = self.cash_transfer.getSimulationState() state = self.cash_transfer.getSimulationState()
# check it has remain as draft
self.assertEqual(state, 'draft') self.assertEqual(state, 'draft')
# get the workflow history
workflow_history = self.workflow_tool.getInfoFor(ob=self.cash_transfer, name='history', wf_id='cash_transfer_workflow') workflow_history = self.workflow_tool.getInfoFor(ob=self.cash_transfer, name='history', wf_id='cash_transfer_workflow')
# check its len is one
self.assertEqual(len(workflow_history), 1) self.assertEqual(len(workflow_history), 1)
def stepCheckBadInventoryConfirmCashTransfer(self, sequence=None, sequence_list=None, **kwd): def stepCheckBadInventoryConfirmCashTransfer(self, sequence=None, sequence_list=None, **kwd):
""" """
Check the try of confirm the cash transfer with the invalid line
""" """
# get state
state = self.cash_transfer.getSimulationState() state = self.cash_transfer.getSimulationState()
# check state is draft
self.assertEqual(state, 'draft') self.assertEqual(state, 'draft')
# get workflow history
workflow_history = self.workflow_tool.getInfoFor(ob=self.cash_transfer, name='history', wf_id='cash_transfer_workflow') workflow_history = self.workflow_tool.getInfoFor(ob=self.cash_transfer, name='history', wf_id='cash_transfer_workflow')
# check len is 2
self.assertEqual(len(workflow_history), 2) self.assertEqual(len(workflow_history), 2)
# check we get an "Insufficient balance" message in the workflow history
self.assertEqual('Insufficient balance' in workflow_history[-1]['error_message'], True) self.assertEqual('Insufficient balance' in workflow_history[-1]['error_message'], True)
def stepCheckConfirmCashTransfer(self, sequence=None, sequence_list=None, **kwd): def stepCheckConfirmCashTransfer(self, sequence=None, sequence_list=None, **kwd):
""" """
Check the confirm the cash transfer
""" """
# get state
state = self.cash_transfer.getSimulationState() state = self.cash_transfer.getSimulationState()
# check state is confirmed
self.assertEqual(state, 'confirmed') self.assertEqual(state, 'confirmed')
# get workflow history
workflow_history = self.workflow_tool.getInfoFor(ob=self.cash_transfer, name='history', wf_id='cash_transfer_workflow') workflow_history = self.workflow_tool.getInfoFor(ob=self.cash_transfer, name='history', wf_id='cash_transfer_workflow')
# check len of workflow history is 4
self.assertEqual(len(workflow_history), 4) self.assertEqual(len(workflow_history), 4)
def stepCheckSourceDebitPlanned(self, sequence=None, sequence_list=None, **kwd): def stepCheckSourceDebitPlanned(self, sequence=None, sequence_list=None, **kwd):
""" """
Check that compution of inventory at vault caisse_1 is well before deliver
""" """
# check we have 5 banknotes of 10000 currently
self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_1.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0) self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_1.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0)
# check we will have 0 banknote of 10000 after deliver
self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_1.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 0.0) self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_1.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 0.0)
# check we have 12 coins of 200 currently
self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_1.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 12.0) self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_1.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 12.0)
# check we will have 0 coin of 200 after deliver
self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_1.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 0.0) self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_1.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 0.0)
def stepCheckDestinationCreditPlanned(self, sequence=None, sequence_list=None, **kwd): def stepCheckDestinationCreditPlanned(self, sequence=None, sequence_list=None, **kwd):
""" """
Check that compution of inventory at vault caisse_2 is well before deliver
""" """
# check we have 0 banknote of 10000 currently
self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_2.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 0.0) self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_2.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 0.0)
# check we will have 5 banknotes of 10000 after deliver
self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_2.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0) self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_2.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0)
# check we have 0 coin of 200 currently
self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_2.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 0.0) self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_2.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 0.0)
# check we will have 12 coins of 200 after deliver
self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_2.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 12.0) self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_2.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 12.0)
def stepBadUserCheckDeliverCashTransfer(self, sequence=None, sequence_list=None, **kwd): def stepBadUserCheckDeliverCashTransfer(self, sequence=None, sequence_list=None, **kwd):
""" """
Check that the try to deliver Cash Transfer with a bad user have failed
""" """
# get state
state = self.cash_transfer.getSimulationState() state = self.cash_transfer.getSimulationState()
# check state is confirmed
self.assertEqual(state, 'confirmed') self.assertEqual(state, 'confirmed')
# get workflow history
workflow_history = self.workflow_tool.getInfoFor(ob=self.cash_transfer, name='history', wf_id='cash_transfer_workflow') workflow_history = self.workflow_tool.getInfoFor(ob=self.cash_transfer, name='history', wf_id='cash_transfer_workflow')
# check len of workflow history is 4
self.assertEqual(len(workflow_history), 4) self.assertEqual(len(workflow_history), 4)
def stepCheckDeliverCashTransfer(self, sequence=None, sequence_list=None, **kwd): def stepCheckDeliverCashTransfer(self, sequence=None, sequence_list=None, **kwd):
""" """
Check the deliver of a cash tranfer have achieved
""" """
# get state
state = self.cash_transfer.getSimulationState() state = self.cash_transfer.getSimulationState()
# check state is deliver
self.assertEqual(state, 'delivered') self.assertEqual(state, 'delivered')
# get workflow history
workflow_history = self.workflow_tool.getInfoFor(ob=self.cash_transfer, name='history', wf_id='cash_transfer_workflow') workflow_history = self.workflow_tool.getInfoFor(ob=self.cash_transfer, name='history', wf_id='cash_transfer_workflow')
# check len of len workflow history is 6
self.assertEqual(len(workflow_history), 6) self.assertEqual(len(workflow_history), 6)
def stepCheckSourceDebit(self, sequence=None, sequence_list=None, **kwd): def stepCheckSourceDebit(self, sequence=None, sequence_list=None, **kwd):
""" """
Check inventory at source (vault caisse_1) after deliver of cash transfer
""" """
# check we have 0 banknote of 10000
self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_1.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 0.0) self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_1.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 0.0)
self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_1.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 0.0) self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_1.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 0.0)
# check we have 0 coin of 200
self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_1.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 0.0) self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_1.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 0.0)
self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_1.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 0.0) self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_1.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 0.0)
def stepCheckDestinationCredit(self, sequence=None, sequence_list=None, **kwd): def stepCheckDestinationCredit(self, sequence=None, sequence_list=None, **kwd):
""" """
Check inventory at destination (vault caisse_2) after deliver of cash transfer
""" """
# check we have 5 banknotes of 10000
self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_2.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0) self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_2.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0)
self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_2.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0) self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_2.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0)
# check we have 12 coins of 200
self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_2.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 12.0) self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.caisse_2.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 12.0)
self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_2.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 12.0) self.assertEqual(self.simulation_tool.getFutureInventory(node=self.caisse_2.getRelativeUrl(), resource = self.piece_200.getRelativeUrl()), 12.0)
def stepCreateCashTransfer(self, sequence=None, sequence_list=None, **kwd): def stepCreateCashTransfer(self, sequence=None, sequence_list=None, **kwd):
""" """
Create a cash transfer
""" """
self.cash_transfer = self.cash_transfer_module.newContent(id='cash_transfer_1', portal_type='Cash Transfer', source_value=self.caisse_1, destination_value=self.caisse_2, price=52400.0) # 5 * 1000 + 12 * 200 self.cash_transfer = self.cash_transfer_module.newContent(id='cash_transfer_1', portal_type='Cash Transfer', source_value=self.caisse_1, destination_value=self.caisse_2, price=52400.0) # 5 * 1000 + 12 * 200
def stepCreateValidLine1(self, sequence=None, sequence_list=None, **kwd): def stepCreateValidLine1(self, sequence=None, sequence_list=None, **kwd):
""" """
Create the line 1 with banknotes of 10000
""" """
self.addCashLineToDelivery(self.cash_transfer, 'valid_line_1', 'Cash Transfer Line', self.billet_10000, self.addCashLineToDelivery(self.cash_transfer, 'valid_line_1', 'Cash Transfer Line', self.billet_10000,
('emission_letter', 'cash_status', 'variation'), ('emission_letter/k', 'cash_status/valid') + self.variation_list, ('emission_letter', 'cash_status', 'variation'), ('emission_letter/k', 'cash_status/valid') + self.variation_list,
...@@ -643,6 +840,7 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase): ...@@ -643,6 +840,7 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase):
def stepCreateValidLine2(self, sequence=None, sequence_list=None, **kwd): def stepCreateValidLine2(self, sequence=None, sequence_list=None, **kwd):
""" """
Create the line 2 wiht coins of 200
""" """
self.addCashLineToDelivery(self.cash_transfer, 'valid_line_2', 'Cash Transfer Line', self.piece_200, self.addCashLineToDelivery(self.cash_transfer, 'valid_line_2', 'Cash Transfer Line', self.piece_200,
('emission_letter', 'cash_status', 'variation'), ('emission_letter/k', 'cash_status/valid') + self.variation_list, ('emission_letter', 'cash_status', 'variation'), ('emission_letter/k', 'cash_status/valid') + self.variation_list,
...@@ -651,7 +849,10 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase): ...@@ -651,7 +849,10 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase):
def stepCreateInvalidLine(self, sequence=None, sequence_list=None, **kwd): def stepCreateInvalidLine(self, sequence=None, sequence_list=None, **kwd):
""" """
Create an invalid line
""" """
# create a line in which quanity of banknotes of 5000 is higher that quantity available at source
# here create a line with 24 (11+13) banknotes of 500 although the vault caisse_1 has no banknote of 5000
self.addCashLineToDelivery(self.cash_transfer, 'invalid_line', 'Cash Transfer Line', self.billet_5000, self.addCashLineToDelivery(self.cash_transfer, 'invalid_line', 'Cash Transfer Line', self.billet_5000,
('emission_letter', 'cash_status', 'variation'), ('emission_letter/k', 'cash_status/valid') + self.variation_list, ('emission_letter', 'cash_status', 'variation'), ('emission_letter/k', 'cash_status/valid') + self.variation_list,
self.quantity_5000) self.quantity_5000)
...@@ -659,66 +860,76 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase): ...@@ -659,66 +860,76 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase):
def stepDelInvalidLine(self, sequence=None, sequence_list=None, **kwd): def stepDelInvalidLine(self, sequence=None, sequence_list=None, **kwd):
""" """
Delete the invalid line previously create
""" """
self.cash_transfer.deleteContent('invalid_line') self.cash_transfer.deleteContent('invalid_line')
def stepBadUserConfirmCashTransfer(self, sequence=None, sequence_list=None, **kwd): def stepBadUserConfirmCashTransfer(self, sequence=None, sequence_list=None, **kwd):
""" """
Try to confirm cash transfer with a user that doesn't have the right
""" """
# log in as bad user # logout from user_1
self.logout() self.logout()
# log in as bad user
self.login('user_3') self.login('user_3')
# try to doActionFor # try to doActionFor
self.workflow_tool = self.getWorkflowTool() self.workflow_tool = self.getWorkflowTool()
# check that an nauthorized exception is raised
self.assertRaises(Unauthorized, self.workflow_tool.doActionFor, self.cash_transfer, 'confirm_action', wf_id='cash_transfer_workflow') self.assertRaises(Unauthorized, self.workflow_tool.doActionFor, self.cash_transfer, 'confirm_action', wf_id='cash_transfer_workflow')
# log in as default user # logout from user_3
self.logout() self.logout()
# login as default user
self.login('user_1') self.login('user_1')
def stepBadInventoryConfirmCashTransfer(self, sequence=None, sequence_list=None, **kwd): def stepBadInventoryConfirmCashTransfer(self, sequence=None, sequence_list=None, **kwd):
""" """
Try to confirm thre cash transfer with a bad line
""" """
# fix amount # fix amount (10000 * 5.0 + 200 * 12.0 + 5000 * 24)
self.cash_transfer.setPrice('172400.0') self.cash_transfer.setPrice('172400.0')
# logged in as good user # try to do the workflow action
# try to doActionFor
self.workflow_tool.doActionFor(self.cash_transfer, 'confirm_action', wf_id='cash_transfer_workflow') self.workflow_tool.doActionFor(self.cash_transfer, 'confirm_action', wf_id='cash_transfer_workflow')
def stepConfirmCashTransfer(self, sequence=None, sequence_list=None, **kwd): def stepConfirmCashTransfer(self, sequence=None, sequence_list=None, **kwd):
""" """
Confir the cash transfer
""" """
# fix amount # fix amount (10000 * 5.0 + 200 * 12.0)
self.cash_transfer.setPrice('52400.0') self.cash_transfer.setPrice('52400.0')
# logged in as good user # do the orkflow action
# try to doActionFor
self.workflow_tool.doActionFor(self.cash_transfer, 'confirm_action', wf_id='cash_transfer_workflow') self.workflow_tool.doActionFor(self.cash_transfer, 'confirm_action', wf_id='cash_transfer_workflow')
def stepBadUserDeliverCashTransfer(self, sequence=None, sequence_list=None, **kwd): def stepBadUserDeliverCashTransfer(self, sequence=None, sequence_list=None, **kwd):
""" """
Try to deliver a cash transfer with a user that don't have the right
""" """
# log in as bad user # logout from user_1
self.logout() self.logout()
# log in as bad user
self.login('user_3') self.login('user_3')
# try to doActionFor # check we raise an Unauthorized Exception if we try to deliver cash transfer
self.assertRaises(Unauthorized, self.workflow_tool.doActionFor, self.cash_transfer, 'deliver_action', wf_id='cash_transfer_workflow') self.assertRaises(Unauthorized, self.workflow_tool.doActionFor, self.cash_transfer, 'deliver_action', wf_id='cash_transfer_workflow')
# log in as default user # logout from bad user
self.logout() self.logout()
# log in as default user
self.login('user_1') self.login('user_1')
def stepDeliverCashTransfer(self, sequence=None, sequence_list=None, **kwd): def stepDeliverCashTransfer(self, sequence=None, sequence_list=None, **kwd):
""" """
Deliver the cash transfer with a good user
""" """
# log in as good user # logout from user_1
self.logout() self.logout()
# log in as good user (controleur_caisse)
self.login('user_2') self.login('user_2')
# try to doActionFor # self.security_manager = AccessControl.getSecurityManager()
self.security_manager = AccessControl.getSecurityManager() # self.user = self.security_manager.getUser()
self.user = self.security_manager.getUser() # do the workflow transition "deliver_action"
self.workflow_tool.doActionFor(self.cash_transfer, 'deliver_action', wf_id='cash_transfer_workflow') self.workflow_tool.doActionFor(self.cash_transfer, 'deliver_action', wf_id='cash_transfer_workflow')
# log in as default user # log in as default user
self.logout() self.logout()
...@@ -732,10 +943,11 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase): ...@@ -732,10 +943,11 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase):
def test_01_ERP5BankingCashTransfer(self, quiet=QUIET, run=RUN_ALL_TEST): def test_01_ERP5BankingCashTransfer(self, quiet=QUIET, run=RUN_ALL_TEST):
""" """
We'll play the sequence Define the sequence of step that will be play
""" """
if not run: return if not run: return
sequence_list = SequenceList() sequence_list = SequenceList()
# define the sequence
sequence_string = 'Tic CheckObjects Tic CheckInitialInventory CheckSource CheckDestination' \ sequence_string = 'Tic CheckObjects Tic CheckInitialInventory CheckSource CheckDestination' \
+ ' CreateCashTransfer Tic CheckCashTransfer' \ + ' CreateCashTransfer Tic CheckCashTransfer' \
+ ' CreateValidLine1 Tic CheckValidLine1 CheckSubTotal' \ + ' CreateValidLine1 Tic CheckValidLine1 CheckSubTotal' \
...@@ -752,11 +964,10 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase): ...@@ -752,11 +964,10 @@ class TestERP5BankingCashTransfer(ERP5TypeTestCase):
+ ' DeliverCashTransfer Tic CheckDeliverCashTransfer' \ + ' DeliverCashTransfer Tic CheckDeliverCashTransfer' \
+ ' CheckSourceDebit CheckDestinationCredit' + ' CheckSourceDebit CheckDestinationCredit'
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
# play the sequence
sequence_list.play(self) sequence_list.play(self)
# define how we launch the unit test
if __name__ == '__main__': if __name__ == '__main__':
framework() framework()
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment