Commit 7b92c2f8 authored by Łukasz Nowak's avatar Łukasz Nowak

- avoid code duplication by merging common parts and passing parameters

 - do more checks about simulations


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28144 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8676aa31
...@@ -37,8 +37,7 @@ It uses only Sale path to demonstrate BPM. ...@@ -37,8 +37,7 @@ It uses only Sale path to demonstrate BPM.
It is advised to *NOT* remove erp5_administration. It is advised to *NOT* remove erp5_administration.
TODOs: TODOs:
* avoid duplication of code: * avoid duplication of code when possible
* _checkOrderBPMSimulation and _checkPackingListBPMSimulation
* implement tests wisely, to support at least both BPM cases * implement tests wisely, to support at least both BPM cases
""" """
import unittest import unittest
...@@ -102,45 +101,44 @@ class TestBPMEvaluationMixin(TestBPMMixin): ...@@ -102,45 +101,44 @@ class TestBPMEvaluationMixin(TestBPMMixin):
stop_date = self.order_stop_date, stop_date = self.order_stop_date,
specialise_value = self.trade_condition) specialise_value = self.trade_condition)
def _checkOrderBPMSimulation(self): def _checkBPMSimulation(self, delivery, root_applied_rule_portal_type):
"""Checks BPM related simumation.
Note: Simulation tree is the same, it is totally independent from
BPM sequence"""
# TODO: # TODO:
# - gather errors into one list # - gather errors into one list
bpm_order_rule = self.order.getCausalityRelatedValue( bpm_root_rule = delivery.getCausalityRelatedValue(
portal_type='Applied Rule') portal_type='Applied Rule')
self.assertEqual(bpm_order_rule.getSpecialiseValue().getPortalType(), self.assertEqual(bpm_root_rule.getSpecialiseValue().getPortalType(),
'BPM Order Rule') root_applied_rule_portal_type)
order_simulation_movement_list = bpm_order_rule.contentValues() root_simulation_movement_list = bpm_root_rule.contentValues()
self.assertEqual(len(self.order.getMovementList()), self.assertEqual(len(delivery.getMovementList()),
len(order_simulation_movement_list)) len(root_simulation_movement_list))
for order_simulation_movement in order_simulation_movement_list: for root_simulation_movement in root_simulation_movement_list:
self.assertEqual(order_simulation_movement.getPortalType(), self.assertEqual(root_simulation_movement.getPortalType(),
'Simulation Movement') 'Simulation Movement')
order_line = order_simulation_movement.getOrderValue() movement = root_simulation_movement.getOrderValue()
property_problem_list = [] property_problem_list = []
for property in 'resource', 'price', 'quantity', 'start_date', \ for property in 'resource', 'price', 'quantity', 'start_date', \
'stop_date', 'source', 'destination', 'source_section', \ 'stop_date', 'source', 'destination', 'source_section', \
'destination_section': 'destination_section':
if order_line.getProperty(property) != order_simulation_movement \ if movement.getProperty(property) != root_simulation_movement \
.getProperty(property): .getProperty(property):
property_problem_list.append('property %s movement %s ' property_problem_list.append('property %s movement %s '
'simulation %s' % (property, order_line.getProperty(property), 'simulation %s' % (property, movement.getProperty(property),
order_simulation_movement.getProperty(property))) root_simulation_movement.getProperty(property)))
if len(property_problem_list) > 0: if len(property_problem_list) > 0:
self.fail('\n'.join(property_problem_list)) self.fail('\n'.join(property_problem_list))
for bpm_invoicing_rule in order_simulation_movement.contentValues(): self.assertEquals(len(root_simulation_movement.contentValues()), 1)
for bpm_invoicing_rule in root_simulation_movement.contentValues():
self.assertEqual(bpm_invoicing_rule.getPortalType(), 'Applied Rule') self.assertEqual(bpm_invoicing_rule.getPortalType(), 'Applied Rule')
self.assertEqual(bpm_invoicing_rule.getSpecialiseValue() \ self.assertEqual(bpm_invoicing_rule.getSpecialiseValue() \
.getPortalType(), 'BPM Invoicing Rule') .getPortalType(), 'BPM Invoicing Rule')
self.assertEquals(len(bpm_invoicing_rule.contentValues()), 1)
for invoicing_simulation_movement in bpm_invoicing_rule \ for invoicing_simulation_movement in bpm_invoicing_rule \
.contentValues(): .contentValues():
self.assertEqual(invoicing_simulation_movement.getPortalType(), self.assertEqual(invoicing_simulation_movement.getPortalType(),
'Simulation Movement') 'Simulation Movement')
self.assertEqual(invoicing_simulation_movement.getCausalityValue(), self.assertEqual(invoicing_simulation_movement.getCausalityValue(),
self.invoice_path) self.invoice_path)
self.assertEquals(len(invoicing_simulation_movement.contentValues()), 1)
for trade_model_rule in invoicing_simulation_movement \ for trade_model_rule in invoicing_simulation_movement \
.contentValues(): .contentValues():
self.assertEqual(trade_model_rule.getPortalType(), 'Applied Rule') self.assertEqual(trade_model_rule.getPortalType(), 'Applied Rule')
...@@ -149,6 +147,13 @@ class TestBPMEvaluationMixin(TestBPMMixin): ...@@ -149,6 +147,13 @@ class TestBPMEvaluationMixin(TestBPMMixin):
self.assertSameSet(trade_model_rule.contentValues( self.assertSameSet(trade_model_rule.contentValues(
portal_type='Simulation Movement'), []) portal_type='Simulation Movement'), [])
def _checkOrderBPMSimulation(self):
"""Checks BPM related simumation.
Note: Simulation tree is the same, it is totally independent from
BPM sequence"""
self._checkBPMSimulation(self.order, 'BPM Order Rule')
class TestBPMEvaluationDefaultProcessMixin: class TestBPMEvaluationDefaultProcessMixin:
def _createBusinessProcess(self): def _createBusinessProcess(self):
self.business_process = self.createBusinessProcess() self.business_process = self.createBusinessProcess()
...@@ -305,47 +310,7 @@ class TestPackingList(TestBPMEvaluationMixin): ...@@ -305,47 +310,7 @@ class TestPackingList(TestBPMEvaluationMixin):
Note: Simulation tree is the same, it is totally independent from Note: Simulation tree is the same, it is totally independent from
BPM sequence""" BPM sequence"""
# TODO: self._checkBPMSimulation(self.packing_list, 'BPM Delivery Rule')
# - gather errors into one list
bpm_packing_list_rule = self.packing_list.getCausalityRelatedValue(
portal_type='Applied Rule')
self.assertEqual(bpm_packing_list_rule.getSpecialiseValue().getPortalType(),
'BPM Delivery Rule')
packing_list_simulation_movement_list = bpm_packing_list_rule.contentValues()
self.assertEqual(len(self.packing_list.getMovementList()),
len(packing_list_simulation_movement_list))
for packing_list_simulation_movement in packing_list_simulation_movement_list:
self.assertEqual(packing_list_simulation_movement.getPortalType(),
'Simulation Movement')
packing_list_line = packing_list_simulation_movement.getOrderValue()
property_problem_list = []
for property in 'resource', 'price', 'quantity', 'start_date', \
'stop_date', 'source', 'destination', 'source_section', \
'destination_section':
if packing_list_line.getProperty(property) != packing_list_simulation_movement \
.getProperty(property):
property_problem_list.append('property %s movement %s '
'simulation %s' % (property, packing_list_line.getProperty(property),
packing_list_simulation_movement.getProperty(property)))
if len(property_problem_list) > 0:
self.fail('\n'.join(property_problem_list))
for bpm_invoicing_rule in packing_list_simulation_movement.contentValues():
self.assertEqual(bpm_invoicing_rule.getPortalType(), 'Applied Rule')
self.assertEqual(bpm_invoicing_rule.getSpecialiseValue() \
.getPortalType(), 'BPM Invoicing Rule')
for invoicing_simulation_movement in bpm_invoicing_rule \
.contentValues():
self.assertEqual(invoicing_simulation_movement.getPortalType(),
'Simulation Movement')
self.assertEqual(invoicing_simulation_movement.getCausalityValue(),
self.invoice_path)
for trade_model_rule in invoicing_simulation_movement \
.contentValues():
self.assertEqual(trade_model_rule.getPortalType(), 'Applied Rule')
self.assertEqual(trade_model_rule.getSpecialiseValue() \
.getPortalType(), 'Trade Model Rule')
self.assertSameSet(trade_model_rule.contentValues(
portal_type='Simulation Movement'), [])
def test_confirming_packing_list_only(self): def test_confirming_packing_list_only(self):
self._createPackingList() self._createPackingList()
......
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