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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
##############################################################################
#
# Copyright (c) 2006-2010 Nexedi SA and Contributors. All Rights Reserved.
# Sebastien Robin <seb@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 Products.ERP5Type.tests.Sequence import SequenceList
from Products.DCWorkflow.DCWorkflow import Unauthorized, ValidationFailed
from Products.ERP5Banking.tests.testERP5BankingCheckbookVaultTransfer \
import TestERP5BankingCheckbookVaultTransferMixin
from Products.ERP5Banking.tests.testERP5BankingCheckbookUsualCashTransfer \
import TestERP5BankingCheckbookUsualCashTransferMixin
from Products.ERP5Banking.tests.testERP5BankingCheckbookDelivery \
import TestERP5BankingCheckbookDeliveryMixin
from DateTime import DateTime
from zLOG import LOG
# 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'
class TestERP5BankingStopPayment( TestERP5BankingCheckbookDeliveryMixin,
TestERP5BankingCheckbookUsualCashTransferMixin,
TestERP5BankingCheckbookVaultTransferMixin):
"""
This class is a unit test to check the module of Stop Payment
"""
# pseudo constants
RUN_ALL_TEST = 1 # we want to run all test
QUIET = 0 # we don't want the test to be quiet
def getTitle(self):
"""
Return the title of the test
"""
return "ERP5BankingStopPayment"
def getStopPaymentModule(self):
"""
Return the Stop Payment Module
"""
return getattr(self.getPortal(), 'stop_payment_module', None)
def afterSetUp(self):
"""
Method called before the launch of the test to initialize some data
"""
# Set some variables :
TestERP5BankingCheckbookDeliveryMixin.afterSetUp(self)
self.stepTic()
self.createCheckbookDelivery()
# the stop payment module
self.stop_payment_module = self.getStopPaymentModule()
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.
"""
self.checkResourceCreated()
# check that StopPayment Module was created
self.assertEqual(self.stop_payment_module.getPortalType(), 'Stop Payment Module')
# check module is empty
self.assertEqual(len(self.stop_payment_module.objectValues()), 0)
def stepCheckInitialAndFinalCheckbookInventory(self, sequence=None, sequence_list=None, **kw):
"""
Check initial account inventory.
For this test, the intial inventory and the final inventory is the same
"""
# check the inventory of the bank account
self.assertEqual(self.simulation_tool.getCurrentInventory(payment=self.bank_account_2.getRelativeUrl(),resource=self.currency_1.getRelativeUrl()), 100000)
self.assertEqual(self.simulation_tool.getFutureInventory(payment=self.bank_account_2.getRelativeUrl(),resource=self.currency_1.getRelativeUrl()), 100000)
def stepCreateStopPayment(self, sequence=None, sequence_list=None, **kwd):
"""
Create a stop payment
"""
# We will do the transfer ot two items.
self.stop_payment = self.stop_payment_module.newContent(
id='stop_payment', portal_type='Stop Payment',
destination_payment_value=self.bank_account_2,
resource_value=self.currency_1,
description='test',
start_date=self.date,
reference_range_min='0000051',
aggregate_resource_value=self.check_model_1,
source_total_asset_price=20000)
# set source reference
self.setDocumentSourceReference(self.stop_payment)
# check source reference
self.assertNotEqual(self.stop_payment.getSourceReference(), '')
self.assertNotEqual(self.stop_payment.getSourceReference(), None)
# check its portal type
self.assertEqual(self.stop_payment.getPortalType(), 'Stop Payment')
# check source
self.assertEqual(self.stop_payment.getBaobabSource(),
None)
# check destination
self.assertEqual(self.stop_payment.getBaobabDestination(), None)
def stepCheckLineCreated(self, sequence=None, sequence_list=None, **kwd):
"""
Make sure we have found the check corresponding to the
reference and that a new line was created
"""
line_list = self.stop_payment.objectValues(
portal_type='Checkbook Delivery Line')
self.assertEqual(len(line_list),1)
line = line_list[0]
self.assertEqual(line.getAggregateValue(),self.check_1)
self.assertEqual(line.getQuantity(),1)
def stepSetStopPaymentDebit(self, sequence=None, sequence_list=None, **kwd):
"""
Set the debit required
"""
self.stop_payment.setDebitRequired(1)
def stepDeleteStopPayment(self, sequence=None, sequence_list=None, **kwd):
"""
Set the debit required
"""
self.stop_payment_module.manage_delObjects(['stop_payment',])
def stepConfirmStopPayment(self, sequence=None, sequence_list=None, **kw):
"""
Confirm the stop payment
"""
state = self.stop_payment.getSimulationState()
# check that state is draft
self.assertEqual(state, 'draft')
self.workflow_tool.doActionFor(self.stop_payment,
'confirm_action',
wf_id='stop_payment_workflow')
# get state of cash sorting
state = self.stop_payment.getSimulationState()
# check that state is delivered
self.assertEqual(state, 'confirmed')
# get workflow history
workflow_history = self.workflow_tool.getInfoFor(ob=self.stop_payment,
name='history', wf_id='stop_payment_workflow')
self.assertEqual(len(workflow_history), 3)
def stepStartStopPayment(self, sequence=None, sequence_list=None, **kw):
"""
Start the stop payment
"""
state = self.stop_payment.getSimulationState()
# check that state is draft
self.assertEqual(state, 'confirmed')
self.workflow_tool.doActionFor(self.stop_payment,
'start_action',
wf_id='stop_payment_workflow')
# get state of cash sorting
state = self.stop_payment.getSimulationState()
# check that state is delivered
self.assertEqual(state, 'started')
# get workflow history
workflow_history = self.workflow_tool.getInfoFor(ob=self.stop_payment,
name='history', wf_id='stop_payment_workflow')
self.assertEqual(len(workflow_history), 5)
def stepStopStopPayment(self, sequence=None, sequence_list=None, **kw):
"""
Stop the stop payment
"""
state = self.stop_payment.getSimulationState()
# check that state is draft
self.assertEqual(state, 'started')
self.workflow_tool.doActionFor(self.stop_payment,
'stop_action',
wf_id='stop_payment_workflow')
# get state of cash sorting
state = self.stop_payment.getSimulationState()
# check that state is delivered
self.assertEqual(state, 'stopped')
# get workflow history
workflow_history = self.workflow_tool.getInfoFor(ob=self.stop_payment,
name='history', wf_id='stop_payment_workflow')
self.assertEqual(len(workflow_history), 7)
def stepDebitStopStopPayment(self, sequence=None, sequence_list=None, **kw):
"""
Deliver the stop payment
"""
state = self.stop_payment.getSimulationState()
# check that state is draft
self.assertEqual(state, 'started')
self.workflow_tool.doActionFor(self.stop_payment,
'debit_stop_action',
wf_id='stop_payment_workflow',
stop_date=self.stop_payment.getStartDate())
# get state of cash sorting
state = self.stop_payment.getSimulationState()
# check that state is delivered
self.assertEqual(state, 'stopped')
# get workflow history
workflow_history = self.workflow_tool.getInfoFor(ob=self.stop_payment,
name='history', wf_id='stop_payment_workflow')
self.assertEqual(len(workflow_history), 7)
def stepDeliverStopPayment(self, sequence=None, sequence_list=None, **kw):
"""
Deliver the stop payment
"""
state = self.stop_payment.getSimulationState()
# check that state is draft
self.assertEqual(state, 'stopped')
self.workflow_tool.doActionFor(self.stop_payment,
'deliver_action',
wf_id='stop_payment_workflow')
# get state of cash sorting
state = self.stop_payment.getSimulationState()
# check that state is delivered
self.assertEqual(state, 'delivered')
# get workflow history
workflow_history = self.workflow_tool.getInfoFor(ob=self.stop_payment,
name='history', wf_id='stop_payment_workflow')
self.assertEqual(len(workflow_history), 9)
def stepDebitDeliverStopPayment(self, sequence=None, sequence_list=None, **kw):
"""
Deliver the stop payment
"""
state = self.stop_payment.getSimulationState()
# check that state is draft
self.assertEqual(state, 'stopped')
self.workflow_tool.doActionFor(self.stop_payment,
'debit_deliver_action',
wf_id='stop_payment_workflow')
# get state of cash sorting
state = self.stop_payment.getSimulationState()
# check that state is delivered
self.assertEqual(state, 'delivered')
# get workflow history
workflow_history = self.workflow_tool.getInfoFor(ob=self.stop_payment,
name='history', wf_id='stop_payment_workflow')
self.assertEqual(len(workflow_history), 9)
def stepCheckConfirmedCheckbookInventory(self, sequence=None, sequence_list=None, **kw):
"""
Check cash checkbook in item table
"""
# check the inventory of the bank account
self.assertEqual(self.simulation_tool.getCurrentInventory(
payment=self.bank_account_2.getRelativeUrl()
,resource=self.currency_1.getRelativeUrl()), 100000)
self.assertEqual(self.simulation_tool.getAvailableInventory(
payment=self.bank_account_2.getRelativeUrl()
,resource=self.currency_1.getRelativeUrl()), 80000)
self.assertEqual(self.simulation_tool.getFutureInventory(
payment=self.bank_account_2.getRelativeUrl()
,resource=self.currency_1.getRelativeUrl()), 80000)
def stepCheckCheckIsStopped(self, sequence=None, sequence_list=None, **kw):
"""
Check that the check is stopped
"""
self.assertEqual(self.check_1.getSimulationState(),'stopped')
def stepCheckCheckIsConfirmed(self, sequence=None, sequence_list=None, **kw):
"""
Check that the check is confirmed
"""
self.assertEqual(self.check_1.getSimulationState(),'confirmed')
##################################
## Tests
##################################
def test_01_ERP5BankingStopPayment(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
# Here we will debit the account
sequence_string = 'Tic CheckObjects Tic CheckInitialAndFinalCheckbookInventory ' \
+ 'CreateStopPayment Tic ' \
+ 'SetStopPaymentDebit Tic ' \
+ 'ConfirmStopPayment Tic ' \
+ 'CheckLineCreated Tic ' \
+ 'CheckConfirmedCheckbookInventory ' \
+ 'StartStopPayment Tic ' \
+ 'CheckCheckIsStopped Tic ' \
+ 'DebitStopStopPayment Tic ' \
+ 'DebitDeliverStopPayment Tic ' \
+ 'CheckCheckIsConfirmed Tic ' \
+ 'CheckInitialAndFinalCheckbookInventory '
sequence_list.addSequenceString(sequence_string)
# Here we will not debit the account
sequence_string = 'DeleteStopPayment ' \
+ 'Tic CheckObjects Tic CheckInitialAndFinalCheckbookInventory ' \
+ 'CreateStopPayment Tic ' \
+ 'ConfirmStopPayment Tic ' \
+ 'CheckLineCreated Tic ' \
+ 'CheckInitialAndFinalCheckbookInventory ' \
+ 'StartStopPayment Tic ' \
+ 'CheckCheckIsStopped Tic ' \
+ 'StopStopPayment Tic ' \
+ 'DeliverStopPayment Tic ' \
+ 'CheckCheckIsConfirmed Tic ' \
+ 'CheckInitialAndFinalCheckbookInventory '
sequence_list.addSequenceString(sequence_string)
# play the sequence
sequence_list.play(self)