Commit cc98d08e authored by Julien Muchembled's avatar Julien Muchembled

Fix testRule

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40112 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f95d845e
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>return context.generatePredicate(criterion_property_list=("start_date",))\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>_getattr_</string>
<string>context</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>RuleMixin_asPredicate</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
144 145
\ No newline at end of file \ No newline at end of file
...@@ -29,12 +29,11 @@ ...@@ -29,12 +29,11 @@
import zope.interface import zope.interface
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, interfaces from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.Core.Predicate import Predicate
from Products.ERP5.mixin.rule import RuleMixin, MovementGeneratorMixin from Products.ERP5.mixin.rule import RuleMixin, MovementGeneratorMixin
from Products.ERP5.mixin.movement_collection_updater import \ from Products.ERP5.mixin.movement_collection_updater import \
MovementCollectionUpdaterMixin MovementCollectionUpdaterMixin
class DeliveryRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate): class DeliveryRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin):
""" """
Delivery Rule object make sure an Delivery in the simulation Delivery Rule object make sure an Delivery in the simulation
is consistent with the real delivery is consistent with the real delivery
......
...@@ -29,12 +29,11 @@ ...@@ -29,12 +29,11 @@
import zope.interface import zope.interface
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, interfaces from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.Core.Predicate import Predicate
from Products.ERP5.mixin.rule import RuleMixin, MovementGeneratorMixin from Products.ERP5.mixin.rule import RuleMixin, MovementGeneratorMixin
from Products.ERP5.mixin.movement_collection_updater import \ from Products.ERP5.mixin.movement_collection_updater import \
MovementCollectionUpdaterMixin MovementCollectionUpdaterMixin
class DeliverySimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate): class DeliverySimulationRule(RuleMixin, MovementCollectionUpdaterMixin):
""" """
Delivery Rule object make sure an Delivery in the simulation Delivery Rule object make sure an Delivery in the simulation
is consistent with the real delivery is consistent with the real delivery
......
...@@ -31,12 +31,11 @@ ...@@ -31,12 +31,11 @@
import zope.interface import zope.interface
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, interfaces from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.Core.Predicate import Predicate
from Products.ERP5.mixin.rule import RuleMixin, MovementGeneratorMixin from Products.ERP5.mixin.rule import RuleMixin, MovementGeneratorMixin
from Products.ERP5.mixin.movement_collection_updater import \ from Products.ERP5.mixin.movement_collection_updater import \
MovementCollectionUpdaterMixin MovementCollectionUpdaterMixin
class InvoiceRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate): class InvoiceRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin):
""" """
""" """
# CMF Type Definition # CMF Type Definition
......
...@@ -29,12 +29,11 @@ ...@@ -29,12 +29,11 @@
import zope.interface import zope.interface
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, interfaces from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.Core.Predicate import Predicate
from Products.ERP5.mixin.rule import RuleMixin, MovementGeneratorMixin from Products.ERP5.mixin.rule import RuleMixin, MovementGeneratorMixin
from Products.ERP5.mixin.movement_collection_updater import \ from Products.ERP5.mixin.movement_collection_updater import \
MovementCollectionUpdaterMixin MovementCollectionUpdaterMixin
class InvoiceSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate): class InvoiceSimulationRule(RuleMixin, MovementCollectionUpdaterMixin):
""" """
Invoicing Rule expand simulation created by a order or delivery rule. Invoicing Rule expand simulation created by a order or delivery rule.
""" """
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
import zope.interface import zope.interface
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, interfaces from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.Core.Predicate import Predicate
from Products.ERP5.mixin.rule import RuleMixin, MovementGeneratorMixin from Products.ERP5.mixin.rule import RuleMixin, MovementGeneratorMixin
from Products.ERP5.mixin.movement_collection_updater import \ from Products.ERP5.mixin.movement_collection_updater import \
MovementCollectionUpdaterMixin MovementCollectionUpdaterMixin
...@@ -37,7 +36,7 @@ from Products.ERP5.Document.PredicateMatrix import PredicateMatrix ...@@ -37,7 +36,7 @@ from Products.ERP5.Document.PredicateMatrix import PredicateMatrix
class InvoiceTransactionSimulationRule(RuleMixin, class InvoiceTransactionSimulationRule(RuleMixin,
MovementCollectionUpdaterMixin, Predicate, PredicateMatrix): MovementCollectionUpdaterMixin, PredicateMatrix):
""" """
Invoice Transaction Rule object generates accounting movements for Invoice Transaction Rule object generates accounting movements for
each invoice movement based on category membership and other each invoice movement based on category membership and other
......
...@@ -29,12 +29,11 @@ ...@@ -29,12 +29,11 @@
import zope.interface import zope.interface
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, interfaces from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.Core.Predicate import Predicate
from Products.ERP5.mixin.rule import RuleMixin, MovementGeneratorMixin from Products.ERP5.mixin.rule import RuleMixin, MovementGeneratorMixin
from Products.ERP5.mixin.movement_collection_updater import \ from Products.ERP5.mixin.movement_collection_updater import \
MovementCollectionUpdaterMixin MovementCollectionUpdaterMixin
class OrderRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate): class OrderRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin):
""" """
Order Rule object make sure an Order in the simulation Order Rule object make sure an Order in the simulation
is consistent with the real order is consistent with the real order
......
...@@ -29,12 +29,11 @@ ...@@ -29,12 +29,11 @@
import zope.interface import zope.interface
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, interfaces from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.Core.Predicate import Predicate
from Products.ERP5.mixin.rule import RuleMixin, MovementGeneratorMixin from Products.ERP5.mixin.rule import RuleMixin, MovementGeneratorMixin
from Products.ERP5.mixin.movement_collection_updater import \ from Products.ERP5.mixin.movement_collection_updater import \
MovementCollectionUpdaterMixin MovementCollectionUpdaterMixin
class PaymentSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate): class PaymentSimulationRule(RuleMixin, MovementCollectionUpdaterMixin):
""" """
Payment Rule generates payment simulation movement from invoice Payment Rule generates payment simulation movement from invoice
transaction simulation movements. transaction simulation movements.
......
...@@ -30,12 +30,11 @@ import zope.interface ...@@ -30,12 +30,11 @@ import zope.interface
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Acquisition import aq_base from Acquisition import aq_base
from Products.ERP5Type import Permissions, PropertySheet, interfaces from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.Core.Predicate import Predicate
from Products.ERP5.mixin.rule import RuleMixin, MovementGeneratorMixin from Products.ERP5.mixin.rule import RuleMixin, MovementGeneratorMixin
from Products.ERP5.mixin.movement_collection_updater import \ from Products.ERP5.mixin.movement_collection_updater import \
MovementCollectionUpdaterMixin MovementCollectionUpdaterMixin
class TradeModelSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate): class TradeModelSimulationRule(RuleMixin, MovementCollectionUpdaterMixin):
""" """
Rule for Trade Model Rule for Trade Model
""" """
......
...@@ -142,7 +142,7 @@ class MovementGeneratorMixin: ...@@ -142,7 +142,7 @@ class MovementGeneratorMixin:
# and potentially use trade phase for that.... as a way to filter out # and potentially use trade phase for that.... as a way to filter out
class RuleMixin: class RuleMixin(Predicate):
""" """
Provides generic methods and helper methods to implement Provides generic methods and helper methods to implement
IRule and IMovementCollectionUpdater. IRule and IMovementCollectionUpdater.
...@@ -186,19 +186,18 @@ class RuleMixin: ...@@ -186,19 +186,18 @@ class RuleMixin:
activate_kw=activate_kw) activate_kw=activate_kw)
return context.get(id) return context.get(id)
def test(self, *args, **kw): if 0: # XXX-JPS - if people are stupid enough not to configfure predicates,
# it is not our role to be clever for them
# Rules have a workflow - make sure applicable rule system works
# if you wish, add a test here on workflow state to prevent using
# rules which are no longer applicable
def test(self, *args, **kw):
""" """
If no test method is defined, return False, to prevent infinite loop If no test method is defined, return False, to prevent infinite loop
XXX-JPS - I do not understand why
""" """
#if not self.getTestMethodId(): if not self.getTestMethodId():
# return False # XXX-JPS - if people are stupid enough not to configfure predicates, return False
# it is not our role to be clever for them return super(RuleMixin, self).test(*args, **kw)
# Rules have a workflow - make sure applicable rule system works
# if you wish, add a test here on workflow state to prevent using
# rules which are no longer applicable
return Predicate.test(self, *args, **kw)
def expand(self, applied_rule, **kw): def expand(self, applied_rule, **kw):
""" """
......
...@@ -32,36 +32,49 @@ import transaction ...@@ -32,36 +32,49 @@ import transaction
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import createZODBPythonScript from Products.ERP5Type.tests.utils import createZODBPythonScript
from Products.ERP5.tests.testOrder import TestOrderMixin from Products.ERP5.tests.testOrder import TestOrderMixin
from Products.ERP5.tests.utils import newSimulationExpectedFailure
class TestRuleMixin(TestOrderMixin): class TestRuleMixin(TestOrderMixin):
""" """
Test basic rule behaviours Test basic rule behaviours
""" """
def createRule(self, base_reference, version, **kw):
rule = super(TestRuleMixin, self).getRule(reference=base_reference,
version='<testRule.')
assert rule.getValidationState() == 'draft'
parent = rule.getParentValue()
rule, = parent.manage_pasteObjects(
parent.manage_copyObjects(ids=rule.getId()))
rule = parent[rule['new_id']]
rule._edit(version='testRule.' + version, **kw)
return rule
def getRule(self, reference):
rule = super(TestRuleMixin, self).getRule(reference=reference)
assert rule.getVersion().startswith('testRule.')
return rule
def afterSetUp(self): def afterSetUp(self):
# delete rules # delete rules
self.getRuleTool().manage_delObjects( rule_tool = self.portal.portal_rules
ids=list(list(self.getRuleTool().objectIds()))) rule_tool.manage_delObjects(ids=[x.getId() for x in rule_tool.objectValues()
if x.getVersion().startswith('testRule.')])
# recreate rules # recreate rules
self.getRuleTool().newContent(portal_type="Order Rule", self.createRule('default_order_rule', '1')
id='default_order_rule', self.createRule('default_delivery_rule', '1')
reference='default_order_rule', version='1') transaction.commit()
delivery_rule = self.getRuleTool().newContent(portal_type="Delivery Rule", self.tic()
id='default_delivery_rule',
reference='default_delivery_rule', version='1')
# create packing list if necessary # create packing list if necessary
pl_module = self.getPortal().getDefaultModule( pl_module = self.portal.getDefaultModule(self.packing_list_portal_type)
self.packing_list_portal_type)
if pl_module.objectCount() == 0: if pl_module.objectCount() == 0:
# at least one default_delivery_rule should be validated here to # at least one default_delivery_rule should be validated here to
# confirm Sale Packing List # confirm Sale Packing List
delivery_rule = self.getRule('default_delivery_rule')
delivery_rule.validate() delivery_rule.validate()
self.pl = self.createPackingList() self.pl = self.createPackingList()
delivery_rule.invalidate() delivery_rule.invalidate()
else: else:
self.pl = self.getPortal().getDefaultModule( self.pl = pl_module.objectValues()[0]
self.packing_list_portal_type).objectValues()[0]
#delete applied_rule #delete applied_rule
self.getSimulationTool().manage_delObjects( self.getSimulationTool().manage_delObjects(
ids=list(self.getSimulationTool().objectIds())) ids=list(self.getSimulationTool().objectIds()))
...@@ -71,8 +84,8 @@ class TestRuleMixin(TestOrderMixin): ...@@ -71,8 +84,8 @@ class TestRuleMixin(TestOrderMixin):
def beforeTearDown(self): def beforeTearDown(self):
for module in self.getRuleTool(), self.getSimulationTool(): module = self.getSimulationTool()
module.manage_delObjects(list(module.objectIds())) module.manage_delObjects(list(module.objectIds()))
transaction.commit() transaction.commit()
self.tic() self.tic()
...@@ -92,6 +105,7 @@ class TestRuleMixin(TestOrderMixin): ...@@ -92,6 +105,7 @@ class TestRuleMixin(TestOrderMixin):
pl_module = self.getPortal().getDefaultModule( pl_module = self.getPortal().getDefaultModule(
self.packing_list_portal_type) self.packing_list_portal_type)
pl = pl_module.newContent(portal_type=self.packing_list_portal_type, pl = pl_module.newContent(portal_type=self.packing_list_portal_type,
specialise=self.business_process,
source_section='group/a', destination_section='group/b') source_section='group/a', destination_section='group/b')
pl.newContent(portal_type=self.packing_list_line_portal_type, id='line', pl.newContent(portal_type=self.packing_list_line_portal_type, id='line',
quantity=1) quantity=1)
...@@ -109,15 +123,13 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -109,15 +123,13 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
run_all_test = 1 run_all_test = 1
quiet = 0 quiet = 0
@newSimulationExpectedFailure
def test_01_ValidatedRuleWithNoScript(self, quiet=quiet, run=run_all_test): def test_01_ValidatedRuleWithNoScript(self, quiet=quiet, run=run_all_test):
""" """
test that when a rule is validated, but has no script it will not apply test that when a rule is validated, but has no script it will not apply
""" """
if not run: return if not run: return
delivery_rule = self.getRuleTool().searchFolder( delivery_rule = self.getRule('default_delivery_rule')
reference='default_delivery_rule')[0]
delivery_rule.validate() delivery_rule.validate()
transaction.commit() transaction.commit()
self.tic() self.tic()
...@@ -126,7 +138,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -126,7 +138,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
validation_state="validated")[0][0], 1) validation_state="validated")[0][0], 1)
self.assertEquals(len(self.getRuleTool().searchRuleList(self.pl)), 0) self.assertEquals(len(self.getRuleTool().searchRuleList(self.pl)), 0)
@newSimulationExpectedFailure
def test_02_WrongTestMethod(self, quiet=quiet, run=run_all_test): def test_02_WrongTestMethod(self, quiet=quiet, run=run_all_test):
""" """
test that when a rule's test method returns False, it will not apply test that when a rule's test method returns False, it will not apply
...@@ -136,8 +147,7 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -136,8 +147,7 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
skin_folder = self.getPortal().portal_skins.custom skin_folder = self.getPortal().portal_skins.custom
skin = createZODBPythonScript(skin_folder, 'wrong_script', 'rule', skin = createZODBPythonScript(skin_folder, 'wrong_script', 'rule',
'return False') 'return False')
delivery_rule = self.getRuleTool().searchFolder( delivery_rule = self.getRule('default_delivery_rule')
reference='default_delivery_rule')[0]
delivery_rule.setTestMethodId('wrong_script') delivery_rule.setTestMethodId('wrong_script')
delivery_rule.validate() delivery_rule.validate()
transaction.commit() transaction.commit()
...@@ -147,7 +157,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -147,7 +157,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
validation_state="validated")[0][0], 1) validation_state="validated")[0][0], 1)
self.assertEquals(len(self.getRuleTool().searchRuleList(self.pl)), 0) self.assertEquals(len(self.getRuleTool().searchRuleList(self.pl)), 0)
@newSimulationExpectedFailure
def test_03_GoodTestMethod(self, quiet=quiet, run=run_all_test): def test_03_GoodTestMethod(self, quiet=quiet, run=run_all_test):
""" """
test that when a rule's test method returns True, it will apply test that when a rule's test method returns True, it will apply
...@@ -157,8 +166,7 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -157,8 +166,7 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
skin_folder = self.getPortal().portal_skins.custom skin_folder = self.getPortal().portal_skins.custom
skin = createZODBPythonScript(skin_folder, 'good_script', 'rule', skin = createZODBPythonScript(skin_folder, 'good_script', 'rule',
'return True') 'return True')
delivery_rule = self.getRuleTool().searchFolder( delivery_rule = self.getRule('default_delivery_rule')
reference='default_delivery_rule')[0]
delivery_rule.setTestMethodId('good_script') delivery_rule.setTestMethodId('good_script')
delivery_rule.validate() delivery_rule.validate()
transaction.commit() transaction.commit()
...@@ -168,7 +176,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -168,7 +176,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
validation_state="validated")[0][0], 1) validation_state="validated")[0][0], 1)
self.assertEquals(len(self.getRuleTool().searchRuleList(self.pl)), 1) self.assertEquals(len(self.getRuleTool().searchRuleList(self.pl)), 1)
@newSimulationExpectedFailure
def test_04_NotValidatedRule(self, quiet=quiet, run=run_all_test): def test_04_NotValidatedRule(self, quiet=quiet, run=run_all_test):
""" """
test that when a rule is not validated, it will not apply, even if it has test that when a rule is not validated, it will not apply, even if it has
...@@ -179,8 +186,7 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -179,8 +186,7 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
skin_folder = self.getPortal().portal_skins.custom skin_folder = self.getPortal().portal_skins.custom
skin = createZODBPythonScript(skin_folder, 'good_script', 'rule', skin = createZODBPythonScript(skin_folder, 'good_script', 'rule',
'return True') 'return True')
delivery_rule = self.getRuleTool().searchFolder( delivery_rule = self.getRule('default_delivery_rule')
reference='default_delivery_rule')[0]
delivery_rule.setTestMethodId('good_script') delivery_rule.setTestMethodId('good_script')
delivery_rule.validate() delivery_rule.validate()
delivery_rule.invalidate() delivery_rule.invalidate()
...@@ -191,7 +197,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -191,7 +197,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
validation_state="validated")[0][0], 0) validation_state="validated")[0][0], 0)
self.assertEquals(len(self.getRuleTool().searchRuleList(self.pl)), 0) self.assertEquals(len(self.getRuleTool().searchRuleList(self.pl)), 0)
@newSimulationExpectedFailure
def test_06_WrongDateRange(self, quiet=quiet, run=run_all_test): def test_06_WrongDateRange(self, quiet=quiet, run=run_all_test):
""" """
test that when a rule is validated but does not have correct date range, test that when a rule is validated but does not have correct date range,
...@@ -202,8 +207,7 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -202,8 +207,7 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
skin_folder = self.getPortal().portal_skins.custom skin_folder = self.getPortal().portal_skins.custom
skin = createZODBPythonScript(skin_folder, 'good_script', 'rule', skin = createZODBPythonScript(skin_folder, 'good_script', 'rule',
'return True') 'return True')
delivery_rule = self.getRuleTool().searchFolder( delivery_rule = self.getRule('default_delivery_rule')
reference='default_delivery_rule')[0]
delivery_rule.setTestMethodId('good_script') delivery_rule.setTestMethodId('good_script')
delivery_rule.setStartDateRangeMin('2007-06-01') delivery_rule.setStartDateRangeMin('2007-06-01')
delivery_rule.setStartDateRangeMax('2007-06-04') delivery_rule.setStartDateRangeMax('2007-06-04')
...@@ -215,7 +219,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -215,7 +219,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
validation_state="validated")[0][0], 1) validation_state="validated")[0][0], 1)
self.assertEquals(len(self.getRuleTool().searchRuleList(self.pl)), 0) self.assertEquals(len(self.getRuleTool().searchRuleList(self.pl)), 0)
@newSimulationExpectedFailure
def test_07_GoodDateRange(self, quiet=quiet, run=run_all_test): def test_07_GoodDateRange(self, quiet=quiet, run=run_all_test):
""" """
test that when a rule is validated and has a correct date range, it will test that when a rule is validated and has a correct date range, it will
...@@ -226,8 +229,7 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -226,8 +229,7 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
skin_folder = self.getPortal().portal_skins.custom skin_folder = self.getPortal().portal_skins.custom
skin = createZODBPythonScript(skin_folder, 'good_script', 'rule', skin = createZODBPythonScript(skin_folder, 'good_script', 'rule',
'return True') 'return True')
delivery_rule = self.getRuleTool().searchFolder( delivery_rule = self.getRule('default_delivery_rule')
reference='default_delivery_rule')[0]
delivery_rule.setTestMethodId('good_script') delivery_rule.setTestMethodId('good_script')
delivery_rule.setStartDateRangeMin('2007-06-01') delivery_rule.setStartDateRangeMin('2007-06-01')
delivery_rule.setStartDateRangeMax('2007-08-01') delivery_rule.setStartDateRangeMax('2007-08-01')
...@@ -239,7 +241,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -239,7 +241,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
validation_state="validated")[0][0], 1) validation_state="validated")[0][0], 1)
self.assertEquals(len(self.getRuleTool().searchRuleList(self.pl)), 1) self.assertEquals(len(self.getRuleTool().searchRuleList(self.pl)), 1)
@newSimulationExpectedFailure
def test_08_updateAppliedRule(self, quiet=quiet, run=run_all_test): def test_08_updateAppliedRule(self, quiet=quiet, run=run_all_test):
""" """
test that when updateAppliedRule is called, the rule with the correct test that when updateAppliedRule is called, the rule with the correct
...@@ -254,20 +255,16 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -254,20 +255,16 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
"return False") "return False")
# wrong reference # wrong reference
order_rule = self.getRuleTool().searchFolder( order_rule = self.getRule('default_order_rule')
reference='default_order_rule')[0]
order_rule.setTestMethodId('rule_script') order_rule.setTestMethodId('rule_script')
order_rule.validate() order_rule.validate()
delivery_rule_1 = self.getRuleTool().searchFolder( delivery_rule_1 = self.getRule('default_delivery_rule')
reference='default_delivery_rule')[0]
delivery_rule_1.setTestMethodId('rule_script') delivery_rule_1.setTestMethodId('rule_script')
delivery_rule_1.validate() delivery_rule_1.validate()
delivery_rule_2 = self.getRuleTool().newContent( delivery_rule_2 = self.createRule('default_delivery_rule', '2',
portal_type="Delivery Rule", reference='default_delivery_rule', test_method_id='rule_script')
version='2')
delivery_rule_2.setTestMethodId('rule_script')
delivery_rule_2.validate() delivery_rule_2.validate()
transaction.commit() transaction.commit()
self.tic() self.tic()
...@@ -283,7 +280,7 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -283,7 +280,7 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
ids=[self.pl.getCausalityRelatedId()]) ids=[self.pl.getCausalityRelatedId()])
# increase version of delivery_rule_1 # increase version of delivery_rule_1
delivery_rule_1.setVersion("3") delivery_rule_1.setVersion("testRule.3")
transaction.commit() transaction.commit()
self.tic() self.tic()
...@@ -294,7 +291,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -294,7 +291,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
self.assertEquals(self.pl.getCausalityRelatedValue().getSpecialise(), self.assertEquals(self.pl.getCausalityRelatedValue().getSpecialise(),
delivery_rule_1.getRelativeUrl()) delivery_rule_1.getRelativeUrl())
@newSimulationExpectedFailure
def test_09_expandTwoRules(self, quiet=quiet, run=run_all_test): def test_09_expandTwoRules(self, quiet=quiet, run=run_all_test):
""" """
test that when expand is called on a simulation movement, if two rules test that when expand is called on a simulation movement, if two rules
...@@ -313,20 +309,15 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -313,20 +309,15 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
skin = createZODBPythonScript(skin_folder, 'invoice_rule_script', 'rule', skin = createZODBPythonScript(skin_folder, 'invoice_rule_script', 'rule',
"return context.getParentValue().getSpecialiseReference() == 'default_delivery_rule'") "return context.getParentValue().getSpecialiseReference() == 'default_delivery_rule'")
delivery_rule = self.getRuleTool().searchFolder( delivery_rule = self.getRule('default_delivery_rule')
reference='default_delivery_rule')[0]
delivery_rule.validate() delivery_rule.validate()
invoicing_rule_1 = self.getRuleTool().newContent( invoicing_rule_1 = self.createRule('default_invoicing_rule', '1',
portal_type="Invoicing Rule", reference='default_invoicing_rule', test_method_id='invoice_rule_script')
version='1')
invoicing_rule_1.setTestMethodId('invoice_rule_script')
invoicing_rule_1.validate() invoicing_rule_1.validate()
invoicing_rule_2 = self.getRuleTool().newContent( invoicing_rule_2 = self.createRule('default_invoicing_rule', '2',
portal_type="Invoicing Rule", reference='default_invoicing_rule', test_method_id='invoice_rule_script')
version='2')
invoicing_rule_2.setTestMethodId('invoice_rule_script')
invoicing_rule_2.validate() invoicing_rule_2.validate()
# clear simulation # clear simulation
...@@ -354,7 +345,7 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -354,7 +345,7 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
# increase version of other rule, clean simulation and check again # increase version of other rule, clean simulation and check again
self.getSimulationTool().manage_delObjects( self.getSimulationTool().manage_delObjects(
ids=[self.pl.getCausalityRelatedId()]) ids=[self.pl.getCausalityRelatedId()])
invoicing_rule_1.setVersion('3') invoicing_rule_1.setVersion('testRule.3')
transaction.commit() transaction.commit()
self.tic() self.tic()
...@@ -374,7 +365,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -374,7 +365,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
self.assertEquals(applied_rule.getSpecialise(), self.assertEquals(applied_rule.getSpecialise(),
invoicing_rule_1.getRelativeUrl()) invoicing_rule_1.getRelativeUrl())
@newSimulationExpectedFailure
def test_10_expandAddsRule(self, quiet=quiet, run=run_all_test): def test_10_expandAddsRule(self, quiet=quiet, run=run_all_test):
""" """
test that if a rule didn't match previously, and does now, it should apply test that if a rule didn't match previously, and does now, it should apply
...@@ -393,15 +383,12 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -393,15 +383,12 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
skin = createZODBPythonScript(skin_folder, 'invoice_rule_script', 'rule', skin = createZODBPythonScript(skin_folder, 'invoice_rule_script', 'rule',
"return context.getParentValue().getSpecialiseReference() == 'default_delivery_rule'") "return context.getParentValue().getSpecialiseReference() == 'default_delivery_rule'")
delivery_rule = self.getRuleTool().searchFolder( delivery_rule = self.getRule('default_delivery_rule')
reference='default_delivery_rule')[0]
delivery_rule.validate() delivery_rule.validate()
# create rule with a wrong script # create rule with a wrong script
invoicing_rule_1 = self.getRuleTool().newContent( invoicing_rule_1 = self.createRule('default_invoicing_rule', '1',
portal_type="Invoicing Rule", reference='default_invoicing_rule', test_method_id='delivery_rule_script')
version='1')
invoicing_rule_1.setTestMethodId('delivery_rule_script')
invoicing_rule_1.validate() invoicing_rule_1.validate()
# clear simulation # clear simulation
...@@ -444,14 +431,13 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -444,14 +431,13 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
# add more invoicing_rule and test that nothing is changed # add more invoicing_rule and test that nothing is changed
## same reference, higher version ## same reference, higher version
invoicing_rule_n = self.getRuleTool().newContent( invoicing_rule_n = self.createRule('default_invoicing_rule', '2',
portal_type="Invoicing Rule", reference='default_invoicing_rule', test_method_id='invoice_rule_script')
version='2', test_method_id='invoice_rule_script')
invoicing_rule_n.validate() invoicing_rule_n.validate()
## different reference, higher version (but version shouldn't matter here) ## different reference, higher version (but version shouldn't matter here)
invoicing_rule_2 = self.getRuleTool().newContent( invoicing_rule_2 = self.createRule('default_invoicing_rule', '2',
portal_type="Invoicing Rule", reference='default_invoicing_rule_2', reference='default_invoicing_rule_2',
version='2', test_method_id='invoice_rule_script') test_method_id='invoice_rule_script')
invoicing_rule_2.validate() invoicing_rule_2.validate()
transaction.commit() transaction.commit()
self.tic() self.tic()
...@@ -477,7 +463,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -477,7 +463,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
invoicing_rule_2.getRelativeUrl()) invoicing_rule_2.getRelativeUrl())
@newSimulationExpectedFailure
def test_11_expandRemovesRule(self, quiet=quiet, run=run_all_test): def test_11_expandRemovesRule(self, quiet=quiet, run=run_all_test):
""" """
test that if a rule matched previously and does not anymore, it should be test that if a rule matched previously and does not anymore, it should be
...@@ -495,14 +480,11 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -495,14 +480,11 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
skin = createZODBPythonScript(skin_folder, 'invoice_rule_script', 'rule', skin = createZODBPythonScript(skin_folder, 'invoice_rule_script', 'rule',
"return context.getParentValue().getSpecialiseReference() == 'default_delivery_rule'") "return context.getParentValue().getSpecialiseReference() == 'default_delivery_rule'")
delivery_rule = self.getRuleTool().searchFolder( delivery_rule = self.getRule('default_delivery_rule')
reference='default_delivery_rule')[0]
delivery_rule.validate() delivery_rule.validate()
invoicing_rule_1 = self.getRuleTool().newContent( invoicing_rule_1 = self.createRule('default_invoicing_rule', '1',
portal_type="Invoicing Rule", reference='default_invoicing_rule', test_method_id='invoice_rule_script')
version='1')
invoicing_rule_1.setTestMethodId('invoice_rule_script')
invoicing_rule_1.validate() invoicing_rule_1.validate()
# clear simulation # clear simulation
...@@ -608,7 +590,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -608,7 +590,6 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
sub_movement = applied_rule.objectValues()[0] sub_movement = applied_rule.objectValues()[0]
self.assertEquals(sub_movement.getDelivery(), self.pl.line.getRelativeUrl()) self.assertEquals(sub_movement.getDelivery(), self.pl.line.getRelativeUrl())
@newSimulationExpectedFailure
def test_12_expandReplacesRule(self, quiet=quiet, run=run_all_test): def test_12_expandReplacesRule(self, quiet=quiet, run=run_all_test):
""" """
test that if a rule matched previously and does not anymore, and another test that if a rule matched previously and does not anymore, and another
...@@ -627,20 +608,15 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) : ...@@ -627,20 +608,15 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
skin = createZODBPythonScript(skin_folder, 'invoice_rule_script', 'rule', skin = createZODBPythonScript(skin_folder, 'invoice_rule_script', 'rule',
"return context.getParentValue().getSpecialiseReference() == 'default_delivery_rule'") "return context.getParentValue().getSpecialiseReference() == 'default_delivery_rule'")
delivery_rule = self.getRuleTool().searchFolder( delivery_rule = self.getRule('default_delivery_rule')
reference='default_delivery_rule')[0]
delivery_rule.validate() delivery_rule.validate()
invoicing_rule_1 = self.getRuleTool().newContent( invoicing_rule_1 = self.createRule('default_invoicing_rule', '1',
portal_type="Invoicing Rule", reference='default_invoicing_rule', test_method_id='invoice_rule_script')
version='1')
invoicing_rule_1.setTestMethodId('invoice_rule_script')
invoicing_rule_1.validate() invoicing_rule_1.validate()
invoicing_rule_2 = self.getRuleTool().newContent( invoicing_rule_2 = self.createRule('default_invoicing_rule', '2',
portal_type="Invoicing Rule", reference='default_invoicing_rule', test_method_id='invoice_rule_script')
version='2')
invoicing_rule_2.setTestMethodId('invoice_rule_script')
invoicing_rule_2.validate() invoicing_rule_2.validate()
# clear simulation # clear simulation
...@@ -711,4 +687,3 @@ def test_suite(): ...@@ -711,4 +687,3 @@ def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestRule)) suite.addTest(unittest.makeSuite(TestRule))
return suite return suite
...@@ -57,6 +57,7 @@ class TestOrderMixin(SubcontentReindexingWrapper): ...@@ -57,6 +57,7 @@ class TestOrderMixin(SubcontentReindexingWrapper):
packing_list_cell_portal_type = 'Sale Packing List Cell' packing_list_cell_portal_type = 'Sale Packing List Cell'
delivery_builder_id = 'sale_packing_list_builder' delivery_builder_id = 'sale_packing_list_builder'
size_list = ['Baby','Child/32','Child/34','Man','Woman'] size_list = ['Baby','Child/32','Child/34','Man','Woman']
business_process = None
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
""" """
......
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