Commit 97648cbc authored by Vincent Pelletier's avatar Vincent Pelletier

Cleanup test a bit.

- sort with key instead of cmp
- sorting once is enough
- use 0-based sequences, to allow using enumerate
- simplify dict creation
- word-wrap a bit
- simplify sequence declaration
- make it easier to navigate from steps to sequence and vice-versa


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@44640 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0f64af16
...@@ -134,38 +134,36 @@ class TestERP5BankingCashMovementNewNotEmitted(TestERP5BankingMonetaryReceptionM ...@@ -134,38 +134,36 @@ class TestERP5BankingCashMovementNewNotEmitted(TestERP5BankingMonetaryReceptionM
# get the cash container item from the monetary reception # get the cash container item from the monetary reception
cash_container_item_list = [x.getObject() for x in self.simulation_tool.getCurrentTrackingList(node=self.reception.getRelativeUrl())] cash_container_item_list = [x.getObject() for x in self.simulation_tool.getCurrentTrackingList(node=self.reception.getRelativeUrl())]
self.assertEqual(len(cash_container_item_list), 2) self.assertEqual(len(cash_container_item_list), 2)
def reference_sort(a, b): cash_container_item_list.sort(key=lambda x: x.getReference())
return cmp(a.getReference(), b.getReference())
cash_container_item_list.sort(reference_sort)
# contruct list of dict to create cash container # contruct list of dict to create cash container
new_cash_container_list = [] new_cash_container_list = []
i = 1 append = new_cash_container_list.append
for cash_container in cash_container_item_list: for i, cash_container in enumerate(cash_container_item_list):
# register cash container on self to check aggregate value later # register cash container on self to check aggregate value later
setattr(self, 'cash_container_item_%s' %(str(i), ), cash_container) setattr(self, 'cash_container_item_%s' % (i, ), cash_container)
container_dict = {}
container_dict['id'] = str(i)
container_dict['reference'] = cash_container.getReference()
container_dict['range_start'] = cash_container.getCashNumberRangeStart()
container_dict['range_stop'] = cash_container.getCashNumberRangeStop()
cash_container_line = cash_container.objectValues()[0] cash_container_line = cash_container.objectValues()[0]
container_dict['quantity'] = cash_container_line.getQuantity() append({
container_dict['aggregate'] = cash_container 'id': str(i),
new_cash_container_list.append(container_dict) 'reference': cash_container.getReference(),
i += 1 'range_start': cash_container.getCashNumberRangeStart(),
'range_stop': cash_container.getCashNumberRangeStop(),
def reference_sort(a, b): 'quantity': cash_container_line.getQuantity(),
return cmp(a['reference'], b['reference']) 'aggregate': cash_container,
new_cash_container_list.sort(reference_sort) })
global_dict = {} self.createCashContainer(
global_dict['emission_letter'] = 'p' self.cash_movement,
global_dict['variation'] = '2003' 'Cash Movement New Not Emitted Container',
global_dict['cash_status'] = 'new_not_emitted' {
global_dict['resource'] = self.billet_10000 'emission_letter': 'p',
'variation': '2003',
self.createCashContainer(self.cash_movement, 'Cash Movement New Not Emitted Container', global_dict, new_cash_container_list, 'Cash Movement New Not Emitted Line') 'cash_status': 'new_not_emitted',
'resource': self.billet_10000,
},
new_cash_container_list,
'Cash Movement New Not Emitted Line',
)
self.stepTic() self.stepTic()
self.assertEqual(len(self.cash_movement.objectValues()), 3) self.assertEqual(len(self.cash_movement.objectValues()), 3)
...@@ -242,8 +240,7 @@ class TestERP5BankingCashMovementNewNotEmitted(TestERP5BankingMonetaryReceptionM ...@@ -242,8 +240,7 @@ class TestERP5BankingCashMovementNewNotEmitted(TestERP5BankingMonetaryReceptionM
self.assertEqual(self.container_1.getCashNumberRangeStart(), '0') self.assertEqual(self.container_1.getCashNumberRangeStart(), '0')
self.assertEqual(self.container_1.getCashNumberRangeStop(), '100') self.assertEqual(self.container_1.getCashNumberRangeStop(), '100')
self.assertEqual(len(self.container_1.getAggregateValueList()), 1) self.assertEqual(len(self.container_1.getAggregateValueList()), 1)
self.assertEqual(self.container_1.getAggregateValueList()[0], self.cash_container_item_1) self.assertEqual(self.container_1.getAggregateValueList()[0], self.cash_container_item_0)
# self.assertTrue(self.container_1.getAggregateValueList()[0] == self.cash_container_item_1 or self.container_1.getAggregateValueList()[0] == self.cash_container_item_2)
self.assertEqual(len(self.container_1.objectIds()), 1) self.assertEqual(len(self.container_1.objectIds()), 1)
# now get the line and check it # now get the line and check it
self.container_line_1 = self.container_1.objectValues()[0] self.container_line_1 = self.container_1.objectValues()[0]
...@@ -279,8 +276,7 @@ class TestERP5BankingCashMovementNewNotEmitted(TestERP5BankingMonetaryReceptionM ...@@ -279,8 +276,7 @@ class TestERP5BankingCashMovementNewNotEmitted(TestERP5BankingMonetaryReceptionM
self.assertEqual(self.container_2.getCashNumberRangeStart(), '100') self.assertEqual(self.container_2.getCashNumberRangeStart(), '100')
self.assertEqual(self.container_2.getCashNumberRangeStop(), '200') self.assertEqual(self.container_2.getCashNumberRangeStop(), '200')
self.assertEqual(len(self.container_2.getAggregateValueList()), 1) self.assertEqual(len(self.container_2.getAggregateValueList()), 1)
self.assertEqual(self.container_2.getAggregateValueList()[0], self.cash_container_item_2) self.assertEqual(self.container_2.getAggregateValueList()[0], self.cash_container_item_1)
# self.assertTrue(self.container_2.getAggregateValueList()[0] == self.cash_container_item_2 or self.container_2.getAggregateValueList()[0] == self.cash_container_item_1)
self.assertEqual(len(self.container_2.objectIds()), 1) self.assertEqual(len(self.container_2.objectIds()), 1)
# now get the line and check it # now get the line and check it
self.container_line_2 = self.container_2.objectValues()[0] self.container_line_2 = self.container_2.objectValues()[0]
...@@ -335,18 +331,18 @@ class TestERP5BankingCashMovementNewNotEmitted(TestERP5BankingMonetaryReceptionM ...@@ -335,18 +331,18 @@ class TestERP5BankingCashMovementNewNotEmitted(TestERP5BankingMonetaryReceptionM
# define the sequence # define the sequence
sequence_string = 'Tic CheckObjects ' \ sequence_string = 'stepTic stepCheckObjects ' \
+ 'CreateMonetaryReception Tic ' \ 'stepCreateMonetaryReception stepTic ' \
+ 'CheckInitialInventory CheckInitialContainerInventory ' \ 'stepCheckInitialInventory stepCheckInitialContainerInventory ' \
+ 'CreateCashMovement Tic ' \ 'stepCreateCashMovement stepTic ' \
+ 'CreateCashContainer Tic ' \ 'stepCreateCashContainer stepTic ' \
+ 'CheckCashDeliveryLine ' \ 'stepCheckCashDeliveryLine ' \
+ 'CheckCashContainer1 CheckCashContainer2 ' \ 'stepCheckCashContainer1 stepCheckCashContainer2 ' \
+ 'ConfirmDocument Tic ' \ 'stepConfirmDocument stepTic ' \
+ 'StartDocument Tic ' \ 'stepStartDocument stepTic ' \
+ 'StopDocument Tic ' \ 'stepStopDocument stepTic ' \
+ 'DeliverDocument Tic ' \ 'stepDeliverDocument stepTic ' \
+ 'CheckFinalInventory CheckFinalContainerInventory' 'stepCheckFinalInventory stepCheckFinalContainerInventory'
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
......
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