Commit 5b115a8f authored by Łukasz Nowak's avatar Łukasz Nowak

- create generic rule mixing tests

 - use it for testing BPM Order Rule and BPM Delivery Rule
 - test for building packing list from order using interaction workflow from BPM
 - updated docstrings and comments
 - refactor names for more generic test behaviour
 - use double editing instead of next transition to check stability of expand in case of duplicated lines


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28425 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f431b9a5
...@@ -38,7 +38,8 @@ It is advised to *NOT* remove erp5_administration. ...@@ -38,7 +38,8 @@ It is advised to *NOT* remove erp5_administration.
TODOs: TODOs:
* avoid duplication of code when possible * avoid duplication of code when possible
* implement tests wisely, to support at least both BPM cases * implement tests wisely, to support at least both BPM scenarios
* test for root rule (similarity) and deeper rules
Scenarios to cover: Scenarios to cover:
...@@ -71,7 +72,7 @@ class TestBPMEvaluationMixin(TestBPMMixin): ...@@ -71,7 +72,7 @@ class TestBPMEvaluationMixin(TestBPMMixin):
self._createNodes() self._createNodes()
self._createBusinessProcess() self._createBusinessProcess()
self._createTradeCondition() self._createTradeCondition()
self._createOrder() self._createRootDocument()
self.stepTic() self.stepTic()
def _createDocument(self, portal_type, **kw): def _createDocument(self, portal_type, **kw):
...@@ -89,8 +90,9 @@ class TestBPMEvaluationMixin(TestBPMMixin): ...@@ -89,8 +90,9 @@ class TestBPMEvaluationMixin(TestBPMMixin):
self.trade_condition_portal_type, self.trade_condition_portal_type,
specialise_value=self.business_process, **kw) specialise_value=self.business_process, **kw)
def _createOrderLine(self, **kw): def _createRootDocumentLine(self, **kw):
return self.order.newContent(portal_type=self.order_line_portal_type, **kw) return self.root_document.newContent(
portal_type=self.root_document_line_portal_type, **kw)
def _createNodes(self): def _createNodes(self):
self.source, self.source_section = self._createNode(), self._createNode() self.source, self.source_section = self._createNode(), self._createNode()
...@@ -105,8 +107,8 @@ class TestBPMEvaluationMixin(TestBPMMixin): ...@@ -105,8 +107,8 @@ class TestBPMEvaluationMixin(TestBPMMixin):
title=state_name) title=state_name)
setattr(self,'%s_state' % state_name, state_document) setattr(self,'%s_state' % state_name, state_document)
def _createOrder(self): def _createRootDocument(self):
self.order = self._createDocument(self.order_portal_type, self.root_document = self._createDocument(self.root_document_portal_type,
source_value = self.source, source_value = self.source,
source_section_value = self.source_section, source_section_value = self.source_section,
destination_value = self.destination, destination_value = self.destination,
...@@ -115,19 +117,19 @@ class TestBPMEvaluationMixin(TestBPMMixin): ...@@ -115,19 +117,19 @@ 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 _checkBPMSimulation(self, delivery, root_applied_rule_portal_type): def _checkBPMSimulation(self):
"""Checks BPM related simumation. """Checks BPM related simumation.
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: # TODO:
# - gather errors into one list # - gather errors into one list
bpm_root_rule = delivery.getCausalityRelatedValue( bpm_root_rule = self.root_document.getCausalityRelatedValue(
portal_type='Applied Rule') portal_type='Applied Rule')
self.assertEqual(bpm_root_rule.getSpecialiseValue().getPortalType(), self.assertEqual(bpm_root_rule.getSpecialiseValue().getPortalType(),
root_applied_rule_portal_type) self.root_rule_portal_type)
root_simulation_movement_list = bpm_root_rule.contentValues() root_simulation_movement_list = bpm_root_rule.contentValues()
self.assertEqual(len(delivery.getMovementList()), self.assertEqual(len(self.root_document.getMovementList()),
len(root_simulation_movement_list)) len(root_simulation_movement_list))
for root_simulation_movement in root_simulation_movement_list: for root_simulation_movement in root_simulation_movement_list:
self.assertEqual(root_simulation_movement.getPortalType(), self.assertEqual(root_simulation_movement.getPortalType(),
...@@ -160,15 +162,15 @@ class TestBPMEvaluationMixin(TestBPMMixin): ...@@ -160,15 +162,15 @@ class TestBPMEvaluationMixin(TestBPMMixin):
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 movement.getProperty(property) != invoicing_simulation_movement \ if movement.getProperty(property) != \
.getProperty(property): invoicing_simulation_movement.getProperty(property):
property_problem_list.append('property %s movement %s ' property_problem_list.append('property %s movement %s '
'simulation %s' % (property, movement.getProperty(property), 'simulation %s' % (property, movement.getProperty(property),
invoicing_simulation_movement.getProperty(property))) invoicing_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))
self.assertEquals(len(invoicing_simulation_movement.contentValues()), self.assertEquals(
1) 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')
...@@ -177,9 +179,6 @@ class TestBPMEvaluationMixin(TestBPMMixin): ...@@ -177,9 +179,6 @@ 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):
self._checkBPMSimulation(self.order, 'BPM Order Rule')
class TestBPMEvaluationDefaultProcessMixin: class TestBPMEvaluationDefaultProcessMixin:
def _createBusinessProcess(self): def _createBusinessProcess(self):
self.business_process = self.createBusinessProcess(title=self.id()) self.business_process = self.createBusinessProcess(title=self.id())
...@@ -254,158 +253,164 @@ class TestBPMEvaluationDifferentProcessMixin: ...@@ -254,158 +253,164 @@ class TestBPMEvaluationDifferentProcessMixin:
self.stepTic() self.stepTic()
class TestOrder(TestBPMEvaluationMixin): class GenericRuleTestsMixin:
"""Evaluation of BPM Sale Order system""" """Tests which are generic for BPM Order, Delivery and Invoice Rule"""
def test_transition(self):
def test_planning(self): self.order_line = self._createRootDocumentLine(
self.order_line = self._createOrderLine(resource_value = self._createProduct(), resource_value = self._createProduct(), quantity = 10, price = 5)
quantity = 10, price = 5)
self.stepTic() self.stepTic()
self.order.plan() self._doFirstTransition(self.root_document)
self.stepTic() self.stepTic()
self._checkOrderBPMSimulation() self._checkBPMSimulation()
def test_planning_line_edit(self): def test_transition_line_edit(self):
self.test_planning() self.test_transition()
self.order_line.edit(quantity = 8, price = 6) self.order_line.edit(quantity = 8, price = 6)
self.stepTic() self.stepTic()
self._checkOrderBPMSimulation() self._checkBPMSimulation()
def test_planning_line_edit_add(self): def test_transition_line_edit_add(self):
self.test_planning_line_edit() self.test_transition_line_edit()
self.order_line_2 = self._createOrderLine( self.order_line_2 = self._createRootDocumentLine(
resource_value = self._createProduct(), quantity = 4, price = 2) resource_value = self._createProduct(), quantity = 4, price = 2)
self.stepTic() self.stepTic()
self._checkOrderBPMSimulation() self._checkBPMSimulation()
def test_planning_line_edit_add_many_transactions(self): def test_transition_line_edit_add_many_transactions(self):
self.test_planning_line_edit() self.test_transition_line_edit()
self.order_line_9 = self._createOrderLine() self.order_line_9 = self._createRootDocumentLine()
self.stepTic() self.stepTic()
self._checkOrderBPMSimulation() self._checkBPMSimulation()
self.order_line_9.edit(resource_value = self._createProduct()) self.order_line_9.edit(resource_value = self._createProduct())
self.stepTic() self.stepTic()
self._checkOrderBPMSimulation() self._checkBPMSimulation()
self.order_line_9.edit(quantity = 1) self.order_line_9.edit(quantity = 1)
self.stepTic() self.stepTic()
self._checkOrderBPMSimulation() self._checkBPMSimulation()
self.order_line_9.edit(price = 33) self.order_line_9.edit(price = 33)
self.stepTic() self.stepTic()
self._checkOrderBPMSimulation() self._checkBPMSimulation()
self.order_line_9.edit(resource_value = self._createProduct()) self.order_line_9.edit(resource_value = self._createProduct())
self.stepTic() self.stepTic()
self._checkOrderBPMSimulation() self._checkBPMSimulation()
def test_planning_line_edit_add_same_resource(self): def test_transition_line_edit_add_same_resource(self):
self.test_planning_line_edit() self.test_transition_line_edit()
resource = self.order_line.getResourceValue() resource = self.order_line.getResourceValue()
self.order_line_10 = self._createOrderLine(resource_value = resource, self.order_line_10 = self._createRootDocumentLine(
quantity = 9, price = 2) resource_value = resource, quantity = 9, price = 2)
self.stepTic() self.stepTic()
self._checkOrderBPMSimulation() self._checkBPMSimulation()
def test_planning_line_edit_add_same_resource_than_order(self): def test_transition_line_edit_add_same_resource_edit_again(self):
self.test_planning_line_edit_add_same_resource() self.test_transition_line_edit_add_same_resource()
self.order.order()
self.stepTic()
self._checkOrderBPMSimulation()
class TestPackingList(TestBPMEvaluationMixin): self.root_document.edit(title = self.root_document.getTitle() + 'a' )
"""Evaluation of BPM Order to Packing List""" self.stepTic()
packing_list_start_date = TestBPMEvaluationMixin.order_start_date self._checkBPMSimulation()
packing_list_stop_date = TestBPMEvaluationMixin.order_stop_date
def _createPackingListLine(self, **kw):
return self.packing_list.newContent(
portal_type=self.packing_list_line_portal_type, **kw)
def _createPackingList(self): class TestOrder(TestBPMEvaluationMixin, GenericRuleTestsMixin):
self.packing_list = self._createDocument(self.packing_list_portal_type, """Check BPM Order Rule behaviour"""
source_value = self.source, root_document_portal_type = 'Sale Order'
source_section_value = self.source_section, root_document_line_portal_type = 'Sale Order Line'
destination_value = self.destination, root_rule_portal_type = 'BPM Order Rule'
destination_section_value = self.destination_section,
start_date = self.packing_list_start_date,
stop_date = self.packing_list_stop_date,
specialise_value = self.trade_condition)
def _checkPackingListBPMSimulation(self): def _doFirstTransition(self, document):
self._checkBPMSimulation(self.packing_list, 'BPM Delivery Rule') document.plan()
def test_confirming_packing_list_only(self): def test_confirming(self):
self._createPackingList() self.order_line = self._createRootDocumentLine(
self.packing_list_line = self._createPackingListLine(
resource_value = self._createProduct(), quantity = 10, price = 5) resource_value = self._createProduct(), quantity = 10, price = 5)
self.stepTic() self.stepTic()
self.packing_list.confirm() self.root_document.confirm()
self.stepTic() self.stepTic()
self._checkPackingListBPMSimulation() self._checkBPMSimulation()
self.assertEqual(
2,
len(self.root_document.getCausalityRelatedList())
)
self.assertEqual(
'Applied Rule',
self.root_document.getCausalityRelatedValue(
portal_type='Applied Rule').getPortalType()
)
class TestInvoice(TestBPMEvaluationMixin): self.assertEqual(
"""Evaluation of BPM Order through Packing List to Invoice Transaction""" self.packing_list_portal_type,
pass self.root_document.getCausalityRelatedValue(
portal_type=self.packing_list_portal_type).getPortalType()
)
class TestOrderDefaultProcess(TestOrder, TestBPMEvaluationDefaultProcessMixin): class TestPackingList(TestBPMEvaluationMixin, GenericRuleTestsMixin):
pass """Check BPM Delivery Rule behaviour"""
root_document_portal_type = 'Sale Packing List'
root_document_line_portal_type = 'Sale Packing List Line'
root_rule_portal_type = 'BPM Delivery Rule'
def _doFirstTransition(self, document):
document.confirm()
class TestPackingListDefaultProcess(TestPackingList, TestBPMEvaluationDefaultProcessMixin): class TestInvoice(TestBPMEvaluationMixin, GenericRuleTestsMixin):
"""Check BPM Invoice Rule behaviour"""
# not implemented yet
pass pass
class TestInvoiceDefaultProcess(TestInvoice, TestBPMEvaluationDefaultProcessMixin): class TestOrderDefaultProcess(TestOrder,
def test_confirming(self): TestBPMEvaluationDefaultProcessMixin):
self.order_line = self._createOrderLine(resource_value = self._createProduct(), pass
quantity = 10, price = 5)
self.stepTic()
self.order.confirm() class TestPackingListDefaultProcess(TestPackingList,
self.stepTic() TestBPMEvaluationDefaultProcessMixin):
self._checkOrderBPMSimulation() pass
self.assertEqual(
1,
len(self.order.getCausalityRelatedList(
portal_type=self.packing_list_portal_type))
)
class TestInvoiceDefaultProcess(TestInvoice,
TestBPMEvaluationDefaultProcessMixin):
pass
class TestOrderDifferentProcess(TestOrder, TestBPMEvaluationDifferentProcessMixin): class TestOrderDifferentProcess(TestOrder,
TestBPMEvaluationDifferentProcessMixin):
def test_confirming(self): def test_confirming(self):
# in current BPM configuration nothing shall be built # in current BPM configuration nothing shall be built
# as soon as test business process will be finished, it shall built proper # as soon as test business process will be finished, it shall built proper
# delivery # delivery
self.order_line = self._createOrderLine(resource_value = self._createProduct(), self.order_line = self._createRootDocumentLine(
quantity = 10, price = 5) resource_value = self._createProduct(), quantity = 10, price = 5)
self.stepTic() self.stepTic()
self.order.confirm() self.root_document.confirm()
self.stepTic() self.stepTic()
self._checkOrderBPMSimulation() self._checkBPMSimulation()
self.assertEqual( self.assertEqual(
1, 1,
len(self.order.getCausalityRelatedList()) len(self.root_document.getCausalityRelatedList())
) )
self.assertEqual( self.assertEqual(
'Applied Rule', 'Applied Rule',
self.order.getCausalityRelatedValue().getPortalType() self.root_document.getCausalityRelatedValue().getPortalType()
) )
class TestPackingListDifferentProcess(TestPackingList, TestBPMEvaluationDifferentProcessMixin): class TestPackingListDifferentProcess(TestPackingList,
TestBPMEvaluationDifferentProcessMixin):
pass pass
class TestInvoiceDifferentProcess(TestInvoice, TestBPMEvaluationDifferentProcessMixin): class TestInvoiceDifferentProcess(TestInvoice,
TestBPMEvaluationDifferentProcessMixin):
pass pass
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestOrderDefaultProcess)) suite.addTest(unittest.makeSuite(TestOrderDefaultProcess))
suite.addTest(unittest.makeSuite(TestPackingListDefaultProcess)) suite.addTest(unittest.makeSuite(TestPackingListDefaultProcess))
suite.addTest(unittest.makeSuite(TestInvoiceDefaultProcess)) # suite.addTest(unittest.makeSuite(TestInvoiceDefaultProcess))
suite.addTest(unittest.makeSuite(TestOrderDifferentProcess)) suite.addTest(unittest.makeSuite(TestOrderDifferentProcess))
suite.addTest(unittest.makeSuite(TestPackingListDifferentProcess)) suite.addTest(unittest.makeSuite(TestPackingListDifferentProcess))
suite.addTest(unittest.makeSuite(TestInvoiceDifferentProcess)) # suite.addTest(unittest.makeSuite(TestInvoiceDifferentProcess))
return suite return suite
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