Fix newSimulationExpectedFailures in testDivergenceTester

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@44575 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7e4b52a7
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
import unittest import unittest
import transaction import transaction
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.Sequence import SequenceList from Products.ERP5Type.tests.Sequence import Sequence
from Products.ERP5.tests.testPackingList import TestPackingListMixin from Products.ERP5.tests.testPackingList import TestPackingListMixin
from Products.ERP5.tests.utils import newSimulationExpectedFailure from Products.ERP5.tests.utils import newSimulationExpectedFailure
...@@ -40,6 +40,14 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase): ...@@ -40,6 +40,14 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase):
run_all_test = 1 run_all_test = 1
quiet = 0 quiet = 0
divergence_test_sequence_suffix = '''
SetPackingListMovementAndSimulationMovement
ResetDeliveringRule
CheckPackingListIsNotDivergent
'''
divergence_test_sequence = (TestPackingListMixin.default_sequence +
divergence_test_sequence_suffix)
def getTitle(self): def getTitle(self):
return "Divergence Tester" return "Divergence Tester"
...@@ -48,79 +56,56 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase): ...@@ -48,79 +56,56 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase):
validation_state="validated") validation_state="validated")
def afterSetUp(self): def afterSetUp(self):
""" self.validateRules()
Remove all divergence testers from order_rule.
""" def beforeTearDown(self):
rule = self.getDeliveringRule() transaction.abort()
portal_rules = self.portal.portal_rules
rule_id_list = [rule_id for rule_id in portal_rules.objectIds()
if rule_id.startswith('testDivergenceTester_')]
if rule_id_list:
portal_rules.deleteContent(rule_id_list)
transaction.commit()
self.tic()
def stepResetDeliveringRule(self, sequence):
original_rule = rule = self.getDeliveringRule()
self.assertEqual(rule.getId(), 'new_delivery_simulation_rule')
# We clone the rule and clean it up to be able to experiment with it
portal_rules = self.portal.portal_rules
prefix = 'testDivergenceTester_'
new_rule_id = prefix + rule.getId()
new_rule_reference = prefix + rule.getReference()
rule = portal_rules.manage_clone(rule, new_rule_id)
transaction.savepoint(optimistic=True)
rule.setVersion(str(int(rule.getVersion()) + 1))
rule.setReference(new_rule_reference)
tester_list = rule.contentValues( tester_list = rule.contentValues(
portal_type=rule.getPortalDivergenceTesterTypeList()) portal_type=rule.getPortalDivergenceTesterTypeList())
rule.deleteContent([x.getId() for x in tester_list]) rule.deleteContent([x.getId() for x in tester_list])
rule.validate()
# override the rule that oversees the packing_list_lines if possible:
movement = sequence.get('packing_list_line')
if movement is not None:
applied_rule = movement.getDeliveryRelatedValue().getParentValue()
applied_rule.setSpecialiseValue(rule)
transaction.commit() transaction.commit()
self.tic() self.tic()
sequence.edit(rule=rule)
def bootstrapSite(self): def stepSetPackingListMovementAndSimulationMovement(self, sequence):
"""
Manager has to create an administrator user first.
"""
self.logMessage("Bootstrap the site by creating required " \
"order, simulation, ...")
sequence_list = SequenceList()
# Create a clean packing list
sequence_string = ' \
stepCreateOrganisation1 \
stepCreateOrganisation2 \
stepCreateOrganisation3 \
stepCreateOrder \
stepSetOrderProfile \
stepCreateNotVariatedResource \
stepTic \
stepCreateOrderLine \
stepSetOrderLineResource \
stepSetOrderLineDefaultValues \
stepOrderOrder \
stepTic \
stepConfirmOrder \
stepTic \
'
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self, quiet=self.quiet)
self.logMessage("Bootstrap finished")
def setUpOnce(self, quiet=1, run=run_all_test):
"""
Create an order and generate a packing list from it.
This has to be called only once.
"""
self.validateRules()
transaction.commit()
self.tic(verbose=1)
self.bootstrapSite()
def stepGetPackingList(self, sequence=None, sequence_list=None, **kw):
""" """
Set the packing list in the sequence Set the packing movement, delivery
""" """
sql_result = self.getPortal().portal_catalog( packing_list = sequence['packing_list']
portal_type=self.packing_list_portal_type) # XXX-Leo can't we just use sequence['packing_list_line']?
self.assertEquals(1, len(sql_result)) movement = packing_list.getMovementList()[0]
packing_list = sql_result[0].getObject()
# XXX Hardcoded id
movement=packing_list['1']
rule = self.getDeliveringRule() rule = self.getDeliveringRule()
sequence.edit( sequence.edit(
packing_list=packing_list, packing_list=packing_list,
movement=movement, movement=movement,
rule=rule,
sim_mvt=movement.getDeliveryRelatedValueList()[0]) sim_mvt=movement.getDeliveryRelatedValueList()[0])
def stepCheckPackingListIsDivergent(self, sequence=None,
sequence_list=None, **kw):
"""
Test if packing list is divergent
"""
packing_list = sequence.get('packing_list')
self.assertTrue(packing_list.isDivergent())
def stepSetNewQuantity(self, sequence=None, def stepSetNewQuantity(self, sequence=None,
sequence_list=None, **kw): sequence_list=None, **kw):
""" """
...@@ -148,26 +133,56 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase): ...@@ -148,26 +133,56 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase):
self.assertNotEqual(prevision, decision) self.assertNotEqual(prevision, decision)
movement.setQuantity(decision) movement.setQuantity(decision)
def stepAddQuantityDivergenceTester(self, sequence=None, def _addDivergenceTester(self, sequence, tester_type, tester_name, **kw):
sequence_list=None, **kw):
""" """
Add a quantity divergence tester in the rule Add a divergence tester to the rule
""" """
kw.setdefault('tested_property', tester_name)
rule = sequence.get('rule') rule = sequence.get('rule')
rule.newContent(portal_type='Quantity Divergence Tester') divergence_tester = rule.newContent(id=tester_name,
portal_type=tester_type,
**kw)
sequence[tester_name + '_divergence_tester'] = divergence_tester
return divergence_tester
def stepAddQuantityDivergenceTester(self, sequence):
self._addDivergenceTester(
sequence,
tester_name='quantity',
tester_type='Net Converted Quantity Divergence Tester',
quantity_range_max=0.0,
)
def stepAddSourceCategoryDivergenceTester(self, sequence):
self._addDivergenceTester(
sequence,
tester_name='source',
tester_type='Category Membership Divergence Tester',
)
def stepAddAggregateCategoryDivergenceTester(self, sequence):
self._addDivergenceTester(
sequence,
tester_name='aggregate',
tester_type='Category Membership Divergence Tester',
)
def stepAddStartDateDivergenceTester(self, sequence):
self._addDivergenceTester(
sequence,
tester_name='start_date',
tester_type='DateTime Divergence Tester',
quantity=0,
)
@newSimulationExpectedFailure
def test_01_QuantityDivergenceTester(self, quiet=quiet, run=run_all_test): def test_01_QuantityDivergenceTester(self, quiet=quiet, run=run_all_test):
""" """
Test the quantity divergence tester Test the quantity divergence tester
""" """
if not run: return if not run: return
sequence_list = SequenceList() sequence_string = self.divergence_test_sequence + """
# Create a clean packing list
sequence_string = """
GetPackingList
CheckPackingListIsNotDivergent
SetNewQuantity SetNewQuantity
Tic
CheckPackingListIsNotDivergent CheckPackingListIsNotDivergent
AddQuantityDivergenceTester AddQuantityDivergenceTester
CheckPackingListIsDivergent CheckPackingListIsDivergent
...@@ -177,8 +192,8 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase): ...@@ -177,8 +192,8 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase):
CheckPackingListIsNotDivergent CheckPackingListIsNotDivergent
Tic Tic
""" """
sequence_list.addSequenceString(sequence_string) sequence = Sequence(self)
sequence_list.play(self, quiet=self.quiet) sequence(sequence_string, quiet=self.quiet)
def stepSetNewSource(self, sequence=None, def stepSetNewSource(self, sequence=None,
sequence_list=None, **kw): sequence_list=None, **kw):
...@@ -188,23 +203,6 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase): ...@@ -188,23 +203,6 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase):
packing_list = sequence.get('packing_list') packing_list = sequence.get('packing_list')
packing_list.setSource(None) packing_list.setSource(None)
def stepAddCategoryDivergenceTester(self, sequence=None,
sequence_list=None, **kw):
"""
Add a category divergence tester in the rule
"""
rule = sequence.get('rule')
tester = rule.newContent(portal_type='Category Divergence Tester')
sequence.edit(tester=tester)
def stepConfigureCategoryDivergenceTesterForSource(self, sequence=None,
sequence_list=None, **kw):
"""
Add a category divergence tester in the rule
"""
tester = sequence.get('tester')
tester.setTestedPropertyList(['source | Source'])
def stepSetPreviousSource(self, sequence=None, def stepSetPreviousSource(self, sequence=None,
sequence_list=None, **kw): sequence_list=None, **kw):
""" """
...@@ -214,29 +212,23 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase): ...@@ -214,29 +212,23 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase):
packing_list = sequence.get('packing_list') packing_list = sequence.get('packing_list')
packing_list.setSource(sim_mvt.getSource()) packing_list.setSource(sim_mvt.getSource())
@newSimulationExpectedFailure
def test_02_CategoryDivergenceTester(self, quiet=quiet, run=run_all_test): def test_02_CategoryDivergenceTester(self, quiet=quiet, run=run_all_test):
""" """
Test the category divergence tester Test the category divergence tester
""" """
if not run: return if not run: return
sequence_list = SequenceList() sequence_string = self.divergence_test_sequence + """
# Create a clean packing list
sequence_string = """
GetPackingList
CheckPackingListIsNotDivergent
SetNewSource SetNewSource
Tic
CheckPackingListIsNotDivergent CheckPackingListIsNotDivergent
AddCategoryDivergenceTester AddSourceCategoryDivergenceTester
CheckPackingListIsNotDivergent
ConfigureCategoryDivergenceTesterForSource
CheckPackingListIsDivergent CheckPackingListIsDivergent
SetPreviousSource SetPreviousSource
CheckPackingListIsNotDivergent CheckPackingListIsNotDivergent
Tic Tic
""" """
sequence_list.addSequenceString(sequence_string) sequence = Sequence(self)
sequence_list.play(self, quiet=self.quiet) sequence(sequence_string, quiet=self.quiet)
def stepSetNewStartDate(self, sequence=None, def stepSetNewStartDate(self, sequence=None,
sequence_list=None, **kw): sequence_list=None, **kw):
...@@ -246,23 +238,6 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase): ...@@ -246,23 +238,6 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase):
packing_list = sequence.get('packing_list') packing_list = sequence.get('packing_list')
packing_list.setStartDate(packing_list.getStartDate()+10) packing_list.setStartDate(packing_list.getStartDate()+10)
def stepAddPropertyDivergenceTester(self, sequence=None,
sequence_list=None, **kw):
"""
Add a property divergence tester in the rule
"""
rule = sequence.get('rule')
tester = rule.newContent(portal_type='Property Divergence Tester')
sequence.edit(tester=tester)
def stepConfigurePropertyDivergenceTesterForStartDate(self, sequence=None,
sequence_list=None, **kw):
"""
Add a property divergence tester in the rule
"""
tester = sequence.get('tester')
tester.setTestedPropertyList(['start_date | Start Date'])
def stepSetPreviousStartDate(self, sequence=None, def stepSetPreviousStartDate(self, sequence=None,
sequence_list=None, **kw): sequence_list=None, **kw):
""" """
...@@ -272,29 +247,22 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase): ...@@ -272,29 +247,22 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase):
packing_list = sequence.get('packing_list') packing_list = sequence.get('packing_list')
packing_list.setStartDate(sim_mvt.getStartDate()) packing_list.setStartDate(sim_mvt.getStartDate())
@newSimulationExpectedFailure
def test_03_PropertyDivergenceTester(self, quiet=quiet, run=run_all_test): def test_03_PropertyDivergenceTester(self, quiet=quiet, run=run_all_test):
""" """
Test the property divergence tester Test the property divergence tester
""" """
if not run: return if not run: return
sequence_list = SequenceList() sequence_string = self.divergence_test_sequence + """
# Create a clean packing list
sequence_string = """
GetPackingList
CheckPackingListIsNotDivergent
SetNewStartDate SetNewStartDate
CheckPackingListIsNotDivergent CheckPackingListIsNotDivergent
AddPropertyDivergenceTester AddStartDateDivergenceTester
CheckPackingListIsNotDivergent
ConfigurePropertyDivergenceTesterForStartDate
CheckPackingListIsDivergent CheckPackingListIsDivergent
SetPreviousStartDate SetPreviousStartDate
CheckPackingListIsNotDivergent CheckPackingListIsNotDivergent
Tic Tic
""" """
sequence_list.addSequenceString(sequence_string) sequence = Sequence(self)
sequence_list.play(self, quiet=self.quiet) sequence(sequence_string, quiet=self.quiet)
def stepSetNewAggregate(self, sequence=None, def stepSetNewAggregate(self, sequence=None,
sequence_list=None, **kw): sequence_list=None, **kw):
...@@ -302,18 +270,10 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase): ...@@ -302,18 +270,10 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase):
Modify the aggregate of the delivery movement Modify the aggregate of the delivery movement
""" """
movement = sequence.get('movement') movement = sequence.get('movement')
# Set a aggregate value which does not exist # Set an aggregate value which does not exist
# but it should not be a problem for testing the divergency # but it should not be a problem for testing the divergence
movement.setAggregate('a_great_module/a_random_id') movement.setAggregate('a_great_module/a_random_id')
def stepConfigureCategoryDivergenceTesterForAggregate(self, sequence=None,
sequence_list=None, **kw):
"""
Add a category divergence tester in the rule
"""
tester = sequence.get('tester')
tester.setTestedPropertyList(['aggregate | Aggregate'])
def stepSetPreviousAggregate(self, sequence=None, def stepSetPreviousAggregate(self, sequence=None,
sequence_list=None, **kw): sequence_list=None, **kw):
""" """
...@@ -322,56 +282,67 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase): ...@@ -322,56 +282,67 @@ class TestDivergenceTester(TestPackingListMixin, ERP5TypeTestCase):
movement = sequence.get('movement') movement = sequence.get('movement')
movement.setAggregate(None) movement.setAggregate(None)
@newSimulationExpectedFailure
def test_04_CategoryDivergenceTester(self, quiet=quiet, run=run_all_test): def test_04_CategoryDivergenceTester(self, quiet=quiet, run=run_all_test):
""" """
Test the category divergence tester Test the category divergence tester
""" """
if not run: return if not run: return
sequence_list = SequenceList() sequence_string = self.divergence_test_sequence + """
# Create a clean packing list
sequence_string = """
GetPackingList
CheckPackingListIsNotDivergent
SetNewAggregate SetNewAggregate
CheckPackingListIsNotDivergent CheckPackingListIsNotDivergent
AddCategoryDivergenceTester AddAggregateCategoryDivergenceTester
CheckPackingListIsNotDivergent
ConfigureCategoryDivergenceTesterForAggregate
CheckPackingListIsDivergent CheckPackingListIsDivergent
SetPreviousAggregate SetPreviousAggregate
CheckPackingListIsNotDivergent CheckPackingListIsNotDivergent
Tic Tic
""" """
sequence_list.addSequenceString(sequence_string) sequence = Sequence(self)
sequence_list.play(self, quiet=self.quiet) sequence(sequence_string, quiet=self.quiet)
@newSimulationExpectedFailure
def test_QuantityDivergenceTesterCompareMethod(self): def test_QuantityDivergenceTesterCompareMethod(self):
rule = self.portal.portal_rules.newContent(portal_type='Delivery Rule') # XXX-Leo this test is actually just testing
divergence_tester = rule.newContent(portal_type='Quantity Divergence Tester') # FloatEquivalenceTester, and is incomplete. It should test also
# with:
#
# * divergence_test_sequence.setProperty('quantity_range_min', ...)
# * divergence_test_sequence.setProperty('tolerance_base', ...)
# * including all variants like resources, prices and precisions
sequence = Sequence(self)
sequence(self.confirmed_order_without_packing_list + '''
ResetDeliveringRule
AddQuantityDivergenceTester
''')
divergence_tester = sequence['quantity_divergence_tester']
decision = sequence['order_line']
prevision = decision.getDeliveryRelatedValue(
portal_type=self.simulation_movement_portal_type)
def divergence_tester_compare(prevision_value, decision_value):
prevision.setQuantity(prevision_value)
decision.setQuantity(decision_value)
return divergence_tester.compare(prevision, decision)
self.assert_(not divergence_tester.isDecimalAlignmentEnabled()) self.assertFalse(divergence_tester.isDecimalAlignmentEnabled())
self.assertEqual(divergence_tester.compare(3.0, 3.001), False) self.assertFalse(divergence_tester_compare(3.0, 3.001))
self.assertEqual(divergence_tester.compare(3.0, 3.0), True) self.assertTrue(divergence_tester_compare(3.0, 3.0))
divergence_tester.setDecimalAlignmentEnabled(True) divergence_tester.setDecimalAlignmentEnabled(True)
divergence_tester.setDecimalRoundingOption('ROUND_DOWN') divergence_tester.setDecimalRoundingOption('ROUND_DOWN')
divergence_tester.setDecimalExponent('0.01') divergence_tester.setDecimalExponent('0.01')
self.assertEqual(divergence_tester.compare(3.0, 3.001), True) self.assertTrue(divergence_tester_compare(3.0, 3.001))
self.assertEqual(divergence_tester.compare(3.0, 3.0), True) self.assertTrue(divergence_tester_compare(3.0, 3.0))
divergence_tester.setDecimalExponent('0.001') divergence_tester.setDecimalExponent('0.001')
self.assertEqual(divergence_tester.compare(3.0, 3.001), False) self.assertFalse(divergence_tester_compare(3.0, 3.001))
divergence_tester.setDecimalRoundingOption('ROUND_UP') divergence_tester.setDecimalRoundingOption('ROUND_UP')
divergence_tester.setDecimalExponent('0.01') divergence_tester.setDecimalExponent('0.01')
self.assertEqual(divergence_tester.compare(3.0, 3.001), False) self.assertFalse(divergence_tester_compare(3.0, 3.001))
divergence_tester.setDecimalRoundingOption('ROUND_HALF_UP') divergence_tester.setDecimalRoundingOption('ROUND_HALF_UP')
divergence_tester.setDecimalExponent('0.01') divergence_tester.setDecimalExponent('0.01')
self.assertEqual(divergence_tester.compare(3.0, 3.001), True) self.assertTrue(divergence_tester_compare(3.0, 3.001))
def test_suite(): def test_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