testERP5BankingCheckPayment.py 25.2 KB
Newer Older
Yoshinori Okuji's avatar
Yoshinori Okuji committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
##############################################################################
#
# Copyright (c) 2005-2006 Nexedi SARL and Contributors. All Rights Reserved.
#                    Yoshinori Okuji <yo@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################


# import requested python module
import os
from zLOG import LOG
from DateTime import DateTime
from Products.CMFCore.utils import getToolByName
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.Sequence import SequenceList
from Products.DCWorkflow.DCWorkflow import Unauthorized, ValidationFailed
from Testing.ZopeTestCase.PortalTestCase import PortalTestCase
39
from Products.ERP5Banking.tests.TestERP5BankingMixin import TestERP5BankingMixin
Yoshinori Okuji's avatar
Yoshinori Okuji committed
40 41 42 43 44 45 46 47 48 49 50

# Needed in order to have a log file inside the current folder
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'

# Define how to launch the script if we don't use runUnitTest script
if __name__ == '__main__':
  execfile(os.path.join(sys.path[0], 'framework.py'))


51
class TestERP5BankingCheckPaymentMixin:
Yoshinori Okuji's avatar
Yoshinori Okuji committed
52
  """
53
  Unit test class for the check payment module
Yoshinori Okuji's avatar
Yoshinori Okuji committed
54
  """
55

Yoshinori Okuji's avatar
Yoshinori Okuji committed
56 57 58 59
  # pseudo constants
  RUN_ALL_TEST = 1 # we want to run all test
  QUIET = 0 # we don't want the test to be quiet

60
  login = PortalTestCase.login
Yoshinori Okuji's avatar
Yoshinori Okuji committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

  def getTitle(self):
    """
      Return the title of the test
    """
    return "ERP5BankingCheckPayment"


  def getBusinessTemplateList(self):
    """
      Return the list of business templates we need to run the test.
      This method is called during the initialization of the unit test by
      the unit test framework in order to know which business templates
      need to be installed to run the test on.
    """
76
    return ('erp5_base',
77 78
            'erp5_trade',
            'erp5_accounting',
79 80 81
            'erp5_banking_core',
            'erp5_banking_inventory',
            'erp5_banking_check')
Yoshinori Okuji's avatar
Yoshinori Okuji committed
82 83 84 85 86 87


  def afterSetUp(self):
    """
      Method called before the launch of the test to initialize some data
    """
88
    self.initDefaultVariable()
Yoshinori Okuji's avatar
Yoshinori Okuji committed
89 90 91 92 93 94 95 96 97 98 99 100
    # the check payment module
    self.check_payment_module = self.getCheckPaymentModule()
    # the checkbook module
    self.checkbook_module = self.getCheckbookModule()

    # Create a user and login as manager to populate the erp5 portal with objects for tests.
    self.createManagerAndLogin()

    # Define static values (only use prime numbers to prevent confusions like 2 * 6 == 3 * 4)
    # variation list is the list of years for banknotes and coins
    self.variation_list = ('variation/1992', 'variation/2003')

101 102 103 104 105 106 107
    self.createFunctionGroupSiteCategory()
    self.createBanknotesAndCoins()

    # Before the test, we need to input the inventory
    inventory_dict_line_1 = {'id' : 'inventory_line_1',
                             'resource': self.billet_10000,
                             'variation_id': ('emission_letter', 'cash_status', 'variation'),
Aurel's avatar
Aurel committed
108
                             'variation_value': ('emission_letter/p', 'cash_status/valid') + self.variation_list,
109
                             'quantity': self.quantity_10000}
110

111 112 113
    inventory_dict_line_2 = {'id' : 'inventory_line_2',
                             'resource': self.billet_200,
                             'variation_id': ('emission_letter', 'cash_status', 'variation'),
Aurel's avatar
Aurel committed
114
                             'variation_value': ('emission_letter/p', 'cash_status/valid') + self.variation_list,
115 116 117 118 119
                             'quantity': self.quantity_200}

    inventory_dict_line_3 = {'id' : 'inventory_line_3',
                             'resource': self.billet_5000,
                             'variation_id': ('emission_letter', 'cash_status', 'variation'),
Aurel's avatar
Aurel committed
120
                             'variation_value': ('emission_letter/p', 'cash_status/valid') + self.variation_list,
121
                             'quantity': self.quantity_5000}
122

123
    line_list = [inventory_dict_line_1, inventory_dict_line_2, inventory_dict_line_3]
124
    self.line_list = line_list
125 126 127
    self.bi_counter = self.paris.surface.banque_interne
    self.bi_counter_vault = self.paris.surface.banque_interne.guichet_1.encaisse_des_billets_et_monnaies.sortante
    self.createCashInventory(source=None, destination=self.bi_counter_vault, currency=self.currency_1,
128
                             line_list=line_list)
Aurel's avatar
Aurel committed
129
    self.stepTic()
130 131 132 133 134 135 136
    # create a person and a bank account
    self.person_1 = self.createPerson(id='person_1',
                                      first_name='toto',
                                      last_name='titi')
    self.bank_account_1 = self.createBankAccount(person=self.person_1,
                                                 account_id='bank_account_1',
                                                 currency=self.currency_1,
137
                                                 amount=100000)
Yoshinori Okuji's avatar
Yoshinori Okuji committed
138

139 140
    # now we need to create a user as Manager to do the test
    # in order to have an assigment defined which is used to do transition
Yoshinori Okuji's avatar
Yoshinori Okuji committed
141
    # Create an Organisation that will be used for users assignment
142
    self.checkUserFolderType()
Yoshinori Okuji's avatar
Yoshinori Okuji committed
143
    self.organisation = self.organisation_module.newContent(id='baobab_org', portal_type='Organisation',
Aurel's avatar
Aurel committed
144
                          function='banking', group='baobab',  site='testsite/paris')
145
    # define the user
Yoshinori Okuji's avatar
Yoshinori Okuji committed
146
    user_dict = {
147
        'super_user' : [['Manager'], self.organisation, 'banking/comptable', 'baobab', 'testsite/paris/surface/banque_interne/guichet_1']
Yoshinori Okuji's avatar
Yoshinori Okuji committed
148 149 150 151
      }
    # call method to create this user
    self.createERP5Users(user_dict)
    self.logout()
152
    self.login('super_user')
Yoshinori Okuji's avatar
Yoshinori Okuji committed
153

154 155 156 157
    # open counter date and counter
    self.openCounterDate(site=self.paris)
    self.openCounter(site=self.bi_counter_vault)

158 159 160 161 162 163 164 165 166 167 168
    # create a check
    self.checkbook_1 = self.createCheckbook(id= 'checkbook_1',
                                            vault=self.bi_counter,
                                            bank_account=self.bank_account_1,
                                            min=50,
                                            max=100,
                                            )

    self.check_1 = self.createCheck(id='check_1',
                                    reference='50',
                                    checkbook=self.checkbook_1)
169 170 171 172 173 174 175 176 177
    self.check_2 = self.createCheck(id='check_2',
                                    reference='51',
                                    checkbook=self.checkbook_1)
    self.check_3 = self.createCheck(id='check_3',
                                    reference='52',
                                    checkbook=self.checkbook_1)
    self.check_4 = self.createCheck(id='check_4',
                                    reference='53',
                                    checkbook=self.checkbook_1)
178 179 180
    self.check_5 = self.createCheck(id='check_5',
                                    reference='54',
                                    checkbook=self.checkbook_1)
181
    self.non_existant_check_reference = '55'
182
    self.createCheckbookModel()
Yoshinori Okuji's avatar
Yoshinori Okuji committed
183 184 185 186 187 188 189

  def stepCheckObjects(self, sequence=None, sequence_list=None, **kwd):
    """
    Check that all the objects we created in afterSetUp or
    that were added by the business template and that we rely
    on are really here.
    """
190
    self.checkResourceCreated()
Yoshinori Okuji's avatar
Yoshinori Okuji committed
191 192 193 194 195 196 197 198 199 200 201 202
    # check that Check Payment Module was created
    self.assertEqual(self.check_payment_module.getPortalType(), 'Check Payment Module')
    # check check payment module is empty
    self.assertEqual(len(self.check_payment_module.objectValues()), 0)


  def stepCheckInitialInventory(self, sequence=None, sequence_list=None, **kwd):
    """
    Check the initial inventory before any operations
    """
    self.simulation_tool = self.getSimulationTool()
    # check we have 5 banknotes of 10000 in encaisse_billets_et_monnaies
203 204
    self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.bi_counter_vault.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0)
    self.assertEqual(self.simulation_tool.getFutureInventory(node=self.bi_counter_vault.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0)
Yoshinori Okuji's avatar
Yoshinori Okuji committed
205
    # check we have 12 coin of 200 in encaisse_billets_et_monnaies
206 207
    self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.bi_counter_vault.getRelativeUrl(), resource = self.billet_200.getRelativeUrl()), 12.0)
    self.assertEqual(self.simulation_tool.getFutureInventory(node=self.bi_counter_vault.getRelativeUrl(), resource = self.billet_200.getRelativeUrl()), 12.0)
Yoshinori Okuji's avatar
Yoshinori Okuji committed
208
    # check we have 24 banknotes of 200 in encaisse_billets_et_monnaies
209 210
    self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.bi_counter_vault.getRelativeUrl(), resource = self.billet_5000.getRelativeUrl()), 24.0)
    self.assertEqual(self.simulation_tool.getFutureInventory(node=self.bi_counter_vault.getRelativeUrl(), resource = self.billet_5000.getRelativeUrl()), 24.0)
211 212 213
    # check the inventory of the bank account
    self.assertEqual(self.simulation_tool.getCurrentInventory(payment=self.bank_account_1.getRelativeUrl()), 100000)
    self.assertEqual(self.simulation_tool.getFutureInventory(payment=self.bank_account_1.getRelativeUrl()), 100000)
Yoshinori Okuji's avatar
Yoshinori Okuji committed
214 215 216 217 218 219 220 221


  def stepCreateCheckPayment(self, sequence=None, sequence_list=None, **kwd):
    """
    Create a check payment document and check it
    """
    self.check_payment = self.check_payment_module.newContent(id = 'check_payment', portal_type = 'Check Payment',
                                         destination_payment_value = self.bank_account_1,
222 223 224
                                         # aggregate_value = self.check_1,
                                         resource_value = self.currency_1,
                                         aggregate_free_text = "50",
225
                                         description = "test",
Aurel's avatar
Aurel committed
226
                                         # source_value = self.bi_counter,
227
                                         start_date = DateTime().Date(),
Yoshinori Okuji's avatar
Yoshinori Okuji committed
228
                                         source_total_asset_price = 20000.0)
229
    # call set source to go into the interaction workflow to update local roles
Aurel's avatar
Aurel committed
230
    self.check_payment._setSource(self.bi_counter.getRelativeUrl())
Yoshinori Okuji's avatar
Yoshinori Okuji committed
231 232 233
    self.assertNotEqual(self.check_payment, None)
    self.assertEqual(self.check_payment.getTotalPrice(), 0.0)
    self.assertEqual(self.check_payment.getDestinationPayment(), self.bank_account_1.getRelativeUrl())
234
    self.assertEqual(self.check_payment.getAggregateFreeText(), self.check_1.getReference())
Yoshinori Okuji's avatar
Yoshinori Okuji committed
235
    self.assertEqual(self.check_payment.getSourceTotalAssetPrice(), 20000.0)
Aurel's avatar
Aurel committed
236
    self.assertEqual(self.check_payment.getSource(), self.bi_counter.getRelativeUrl())
237 238 239 240 241
    # set source reference
    self.setDocumentSourceReference(self.check_payment)
    # check source reference
    self.assertNotEqual(self.check_payment.getSourceReference(), '')
    self.assertNotEqual(self.check_payment.getSourceReference(), None)
Yoshinori Okuji's avatar
Yoshinori Okuji committed
242 243 244 245 246 247 248 249
    # the initial state must be draft
    self.assertEqual(self.check_payment.getSimulationState(), 'draft')

    # source reference must be automatically generated
    self.check_payment.setSourceReference(self.check_payment.Baobab_getUniqueReference())
    self.assertNotEqual(self.check_payment.getSourceReference(), None)
    self.assertNotEqual(self.check_payment.getSourceReference(), '')

250 251 252 253
  def stepValidateAnotherCheckPaymentWorks(self, sequence=None, sequence_list=None, **kwd):
    """ Make sure we can validate another check payment """
    self.createAnotherCheckPayment(sequence=sequence,will_fail=0,number="51")

254 255 256 257
  def stepValidateAnotherCheckPaymentWorksAgain(self, sequence=None, sequence_list=None, **kwd):
    """ Make sure we can validate another check payment """
    self.createAnotherCheckPayment(sequence=sequence,will_fail=0,number="54")

258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
  def stepValidateAnotherCheckPaymentFails(self, sequence=None, sequence_list=None, **kwd):
    """ Make sure that we can not validate another check payment """
    self.createAnotherCheckPayment(sequence=sequence,will_fail=1,number="52")

  def stepValidateAnotherCheckPaymentFailsAgain(self, sequence=None, sequence_list=None, **kwd):
    """ Make sure that we can not validate another check payment """
    self.createAnotherCheckPayment(sequence=sequence,will_fail=1,number="53")

  def createAnotherCheckPayment(self, will_fail=0, sequence=None, number=None,**kwd):
    new_payment = self.check_payment_module.newContent(portal_type = 'Check Payment',
                                         destination_payment_value = self.bank_account_1,
                                         # aggregate_value = self.check_1,
                                         resource_value = self.currency_1,
                                         aggregate_free_text = number,
                                         # source_value = self.bi_counter,
                                         start_date = DateTime().Date(),
                                         source_total_asset_price = 90000.0)
    new_payment._setSource(self.bi_counter.getRelativeUrl())
    self.workflow_tool.doActionFor(new_payment, 'plan_action', 
                                   wf_id='check_payment_workflow')
    self.assertEqual(new_payment.getSimulationState(), 'planned')
279
    get_transaction().commit()
280 281 282 283
    if will_fail:
      self.assertRaises(ValidationFailed,self.workflow_tool.doActionFor, 
                        new_payment, 'confirm_action', 
                        wf_id='check_payment_workflow')
284 285
      self.assertEqual(new_payment.getSimulationState(), 'planned')
      get_transaction().commit()
286 287 288 289 290 291
      self.workflow_tool.doActionFor(new_payment, 'cancel_action', 
                                     wf_id='check_payment_workflow')
    else:
      self.workflow_tool.doActionFor( 
                        new_payment, 'confirm_action', 
                        wf_id='check_payment_workflow')
292 293
      self.assertEqual(new_payment.getSimulationState(), 'confirmed')
      get_transaction().commit()
294 295 296 297
      self.workflow_tool.doActionFor(new_payment, 'cancel_action', 
                                     wf_id='check_payment_workflow')


Yoshinori Okuji's avatar
Yoshinori Okuji committed
298 299 300 301 302 303 304
  def stepCheckConsistency(self, sequence=None, sequence_list=None, **kwd):
    """
    Check the consistency of the check payment

    FIXME: check if the transition fails when a category or property is invalid.
    """
    self.workflow_tool.doActionFor(self.check_payment, 'plan_action', wf_id='check_payment_workflow')
305
    self.assertNotEqual(self.check_payment.getAggregateValue(), None)
Yoshinori Okuji's avatar
Yoshinori Okuji committed
306 307
    self.assertEqual(self.check_payment.getSimulationState(), 'planned')

308 309 310 311 312 313 314 315
  def stepAggregateToInnexistantCheck(self, sequence=None, sequence_list=None, **kwd):
    """
      Set the aggrate relation to direct to an innexistant object, thus
      requiring the test process to generate one.
    """
    self.check_payment.setAggregateFreeText(self.non_existant_check_reference)
    self.assertEqual(self.check_payment.getAggregateValue(), None)

316 317 318 319
  def stepTryCheckConsistencyWithoutAutomaticCheckCreation(self, sequence=None, sequence_list=None, **kwd):
    """
      Do not enable automatic check creation and verify that validation fails.
    """
320 321 322 323
    self.assertFalse(self.getPortal().Base_isAutomaticCheckCreationAllowed())
    self.assertEqual(self.check_payment.getAggregateValue(), None)
    self.assertNotEqual(self.check_payment.getSimulationState(), 'planned')

324
    self.assertRaises(ValidationFailed, self.workflow_tool.doActionFor, self.check_payment, 'plan_action', wf_id='check_payment_workflow')
325

326 327
    self.assertEqual(self.check_payment.getAggregateValue(), None)
    self.assertNotEqual(self.check_payment.getSimulationState(), 'planned')
328

329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
  def stepTryCheckConsistencyWithAutomaticCheckCreation(self, sequence=None, sequence_list=None, **kwd):
    """
      Enable automatic check creation and verify that validation succeeds.
    """
    check_creation_script = self.getPortal().Base_isAutomaticCheckCreationAllowed
    original_script_source = check_creation_script._body
    check_creation_script.ZPythonScript_edit(check_creation_script._params, 'return True')
    self.assertTrue(self.getPortal().Base_isAutomaticCheckCreationAllowed())
    self.assertEqual(self.check_payment.getAggregateValue(), None)
    self.assertNotEqual(self.check_payment.getSimulationState(), 'planned')

    self.workflow_tool.doActionFor(self.check_payment, 'plan_action', wf_id='check_payment_workflow')

    self.assertNotEqual(self.check_payment.getAggregateValue(), None)
    self.assertEqual(self.check_payment.getSimulationState(), 'planned')
    check_creation_script.ZPythonScript_edit(check_creation_script._params, original_script_source)

Yoshinori Okuji's avatar
Yoshinori Okuji committed
346 347 348 349 350 351 352 353 354 355 356 357
  def stepSendToCounter(self, sequence=None, sequence_list=None, **kwd):
    """
    Send the check payment to the counter

    FIXME: check if the transition fails when a category or property is invalid.
    """
    self.workflow_tool.doActionFor(self.check_payment, 'confirm_action', wf_id='check_payment_workflow')
    self.assertEqual(self.check_payment.getSimulationState(), 'confirmed')

    self.assertEqual(self.check_payment.getSourceTotalAssetPrice(),
                     - self.check_payment.getTotalPrice(portal_type = 'Banking Operation Line'))

358 359 360 361 362 363
  def stepCheckConfirmedInventory(self, sequence=None, sequence_list=None, **kwd):
    """
    Check the inventoryinb state confirmed
    """
    self.simulation_tool = self.getSimulationTool()
    # check we have 5 banknotes of 10000 in encaisse_billets_et_monnaies
364 365
    self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.bi_counter_vault.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0)
    self.assertEqual(self.simulation_tool.getFutureInventory(node=self.bi_counter_vault.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 5.0)
366
    # check we have 12 coin of 200 in encaisse_billets_et_monnaies
367 368
    self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.bi_counter_vault.getRelativeUrl(), resource = self.billet_200.getRelativeUrl()), 12.0)
    self.assertEqual(self.simulation_tool.getFutureInventory(node=self.bi_counter_vault.getRelativeUrl(), resource = self.billet_200.getRelativeUrl()), 12.0)
369
    # check we have 24 banknotes of 200 in encaisse_billets_et_monnaies
370 371
    self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.bi_counter_vault.getRelativeUrl(), resource = self.billet_5000.getRelativeUrl()), 24.0)
    self.assertEqual(self.simulation_tool.getFutureInventory(node=self.bi_counter_vault.getRelativeUrl(), resource = self.billet_5000.getRelativeUrl()), 24.0)
372 373 374
    # check the inventory of the bank account, must be planned to be decrease by 20000
    self.assertEqual(self.simulation_tool.getCurrentInventory(payment=self.bank_account_1.getRelativeUrl()), 100000)
    self.assertEqual(self.simulation_tool.getFutureInventory(payment=self.bank_account_1.getRelativeUrl()), 80000)
375

376

Yoshinori Okuji's avatar
Yoshinori Okuji committed
377 378 379 380 381 382
  def stepInputCashDetails(self, sequence=None, sequence_list=None, **kwd):
    """
    Input cash details
    """
    self.addCashLineToDelivery(self.check_payment, 'line_1', 'Cash Delivery Line', self.billet_10000,
            ('emission_letter', 'cash_status', 'variation'),
Aurel's avatar
Aurel committed
383
            ('emission_letter/p', 'cash_status/valid') + self.variation_list[1:],
Yoshinori Okuji's avatar
Yoshinori Okuji committed
384 385 386 387 388
            {self.variation_list[1] : 1})
    self.assertEqual(self.check_payment.line_1.getPrice(), 10000)

    self.addCashLineToDelivery(self.check_payment, 'line_2', 'Cash Delivery Line', self.billet_5000,
            ('emission_letter', 'cash_status', 'variation'),
Aurel's avatar
Aurel committed
389
            ('emission_letter/p', 'cash_status/valid') + self.variation_list[1:],
Yoshinori Okuji's avatar
Yoshinori Okuji committed
390 391 392 393 394 395 396 397 398 399 400
            {self.variation_list[1] : 2})
    self.assertEqual(self.check_payment.line_2.getPrice(), 5000)

  def stepPay(self, sequence=None, sequence_list=None, **kwd):
    """
    Pay the check payment

    FIXME: check if the transition fails when a category or property is invalid.
    """
    self.assertEqual(self.check_payment.getSourceTotalAssetPrice(),
                     self.check_payment.getTotalPrice(portal_type = 'Cash Delivery Cell'))
401
    self.workflow_tool.doActionFor(self.check_payment, 'deliver_action', wf_id='check_payment_workflow')
Yoshinori Okuji's avatar
Yoshinori Okuji committed
402 403
    self.assertEqual(self.check_payment.getSimulationState(), 'delivered')

404 405 406 407 408 409 410

  def stepCheckFinalInventory(self, sequence=None, sequence_list=None, **kwd):
    """
    Check the initial inventory before any operations
    """
    self.simulation_tool = self.getSimulationTool()
    # check we have 5 banknotes of 10000 in encaisse_billets_et_monnaies
411 412
    self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.bi_counter_vault.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 4.0)
    self.assertEqual(self.simulation_tool.getFutureInventory(node=self.bi_counter_vault.getRelativeUrl(), resource = self.billet_10000.getRelativeUrl()), 4.0)
413
    # check we have 12 coin of 200 in encaisse_billets_et_monnaies
414 415
    self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.bi_counter_vault.getRelativeUrl(), resource = self.billet_200.getRelativeUrl()), 12.0)
    self.assertEqual(self.simulation_tool.getFutureInventory(node=self.bi_counter_vault.getRelativeUrl(), resource = self.billet_200.getRelativeUrl()), 12.0)
416
    # check we have 24 banknotes of 200 in encaisse_billets_et_monnaies
417 418
    self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.bi_counter_vault.getRelativeUrl(), resource = self.billet_5000.getRelativeUrl()), 22.0)
    self.assertEqual(self.simulation_tool.getFutureInventory(node=self.bi_counter_vault.getRelativeUrl(), resource = self.billet_5000.getRelativeUrl()), 22.0)
419 420 421 422
    # check the final inventory of the bank account
    self.assertEqual(self.simulation_tool.getCurrentInventory(payment=self.bank_account_1.getRelativeUrl()), 80000)
    self.assertEqual(self.simulation_tool.getFutureInventory(payment=self.bank_account_1.getRelativeUrl()), 80000)

423 424 425 426 427 428 429 430 431
  def stepCleanup(self, sequence=None, sequence_list=None, **kwd):
    """
      Cleanup test remains
    """
    # Fetch all ids before deleting the objects, otherwise the iterator will
    # skip objects as the list dynamicaly shrinks.
    object_id_list = [x for x in self.check_payment_module.objectIds()]
    for id in object_id_list:
      self.check_payment_module.deleteContent(id)
Yoshinori Okuji's avatar
Yoshinori Okuji committed
432

433 434 435 436 437 438 439
class TestERP5BankingCheckPayment(TestERP5BankingCheckPaymentMixin,
                                  TestERP5BankingMixin, ERP5TypeTestCase):

  # pseudo constants
  RUN_ALL_TEST = 1 # we want to run all test
  QUIET = 0 # we don't want the test to be quiet

Yoshinori Okuji's avatar
Yoshinori Okuji committed
440 441 442 443 444 445 446 447 448 449
  def test_01_ERP5BankingCheckPayment(self, quiet=QUIET, run=RUN_ALL_TEST):
    """
    Define the sequence of step that will be play
    """
    if not run: return
    sequence_list = SequenceList()
    # define the sequence
    sequence_string = 'Tic CheckObjects Tic CheckInitialInventory ' \
                      'CreateCheckPayment Tic ' \
                      'CheckConsistency Tic ' \
450 451 452
                      'stepValidateAnotherCheckPaymentWorks Tic ' \
                      'SendToCounter ' \
                      'stepValidateAnotherCheckPaymentFails Tic ' \
453
                      'CheckConfirmedInventory ' \
454
                      'stepValidateAnotherCheckPaymentFailsAgain Tic ' \
Yoshinori Okuji's avatar
Yoshinori Okuji committed
455
                      'InputCashDetails Tic ' \
456
                      'Pay Tic ' \
457 458 459 460 461
                      'CheckFinalInventory Cleanup Tic'
    # sequence 2 : check if validating with non-exiting check fail if
    # automatic check creation is disabled.
    sequence_string_2 = 'Tic CheckObjects Tic CheckInitialInventory ' \
                        'CreateCheckPayment Tic ' \
462
                        'AggregateToInnexistantCheck Tic ' \
463
                        'TryCheckConsistencyWithoutAutomaticCheckCreation Tic ' \
464 465 466 467 468
                        'Cleanup Tic'
    # sequence 3 : check is validating with non-existing check succeeds if
    # automatic check creation is enabled.
    sequence_string_3 = 'Tic CheckObjects Tic CheckInitialInventory ' \
                        'CreateCheckPayment Tic ' \
469 470
                        'AggregateToInnexistantCheck Tic ' \
                        'TryCheckConsistencyWithAutomaticCheckCreation Tic ' \
471
                        'Cleanup Tic'
Yoshinori Okuji's avatar
Yoshinori Okuji committed
472
    sequence_list.addSequenceString(sequence_string)
473
    sequence_list.addSequenceString(sequence_string_2)
474
    sequence_list.addSequenceString(sequence_string_3)
Yoshinori Okuji's avatar
Yoshinori Okuji committed
475 476 477 478 479 480 481 482 483 484 485 486
    # play the sequence
    sequence_list.play(self)

# define how we launch the unit test
if __name__ == '__main__':
  framework()
else:
  import unittest
  def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestERP5BankingCheckPayment))
    return suite