Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sebastien Robin
erp5
Commits
882028a4
Commit
882028a4
authored
Oct 13, 2011
by
Leonardo Rochael Almeida
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More rule tests
parent
2f881b06
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
3 deletions
+58
-3
product/ERP5/tests/testRule.py
product/ERP5/tests/testRule.py
+58
-3
No files found.
product/ERP5/tests/testRule.py
View file @
882028a4
...
...
@@ -258,7 +258,7 @@ class TestRule(TestRuleMixin, ERP5TypeTestCase) :
'return True'
)
delivery_rule
=
self
.
getRule
(
'default_delivery_rule'
)
delivery_rule
.
setTestMethodId
(
'good_script'
)
# but
add a predicate building script that only matches
on
# but
add a predicate building script that only matches
on
# Simulation Movements, to affect all rules
createZODBPythonScript
(
skin_folder
,
'RuleMixin_asPredicate'
,
''
,
"""
...
...
@@ -290,12 +290,67 @@ return context.generatePredicate(
self
.
assertEqual
(
len
(
self
.
getRuleTool
().
searchRuleList
(
self
.
pl
)),
1
)
self
.
assertEqual
(
len
(
self
.
getRuleTool
().
searchRuleList
(
self
.
sm
)),
0
)
# Note that we added a range criterion above, which means that if
# the packing list no longer falls within the range
:
# the packing list no longer falls within the range
...
self
.
pl
.
setStartDate
(
self
.
pl
.
getStartDate
()
-
1
)
transaction
.
commit
()
self
.
tic
()
# the rule no longer matches the packing list:
#
... then
the rule no longer matches the packing list:
self
.
assertEqual
(
len
(
self
.
getRuleTool
().
searchRuleList
(
self
.
pl
)),
0
)
# But if we push back the date on the criterion...
predicate_script
.
write
(
"""
return context.generatePredicate(
identity_criterion=dict(portal_type=('Sale Packing List',)),
range_criterion=dict(start_date=(%r, None)),
)
"""
%
self
.
pl
.
getStartDate
())
delivery_rule
.
reindexObject
()
transaction
.
commit
()
self
.
tic
()
# ... it will match again
self
.
assertEqual
(
len
(
self
.
getRuleTool
().
searchRuleList
(
self
.
pl
)),
1
)
def
test_071_empty_rule_category_matching
(
self
):
"""
test that a category criteria on a rule that doesn't have that category
allows the rule to match contexts with and without that category
"""
skin_folder
=
self
.
getPortal
().
portal_skins
.
custom
rule_tool
=
self
.
getRuleTool
()
# add an always-matching predicate test script to the rule
createZODBPythonScript
(
skin_folder
,
'good_script'
,
'rule'
,
'return True'
)
delivery_rule
=
self
.
getRule
(
'default_delivery_rule'
)
delivery_rule
.
setTestMethodId
(
'good_script'
)
# and add a predicate building script that only matches on
# Simulation Movements, to affect all rules
createZODBPythonScript
(
skin_folder
,
'RuleMixin_asPredicate'
,
''
,
"""
return context.generatePredicate(
identity_criterion=dict(portal_type=(context.movement_type,)),
membership_criterion_base_category_list=('trade_phase',),
)
"""
)
# and validate it, which will indirectly reindex the predicate.
delivery_rule
.
validate
()
transaction
.
commit
()
self
.
tic
()
# Now since the rule has a trade_phase
self
.
assertEqual
(
delivery_rule
.
getTradePhase
(),
'default/delivery'
)
# ...then it won't match the Simulation Movement
self
.
assertEqual
(
len
(
rule_tool
.
searchRuleList
(
self
.
sm
)),
0
)
# unless it gets a trade_phase itself
self
.
sm
.
setTradePhase
(
'default/delivery'
)
self
.
stepTic
()
self
.
assertEqual
(
len
(
rule_tool
.
searchRuleList
(
self
.
sm
)),
1
)
# But if the rule itself has no trade_phase...
delivery_rule
.
setTradePhase
(
None
)
self
.
stepTic
()
# then it should match the simulation movement with or without
# trade_phase
self
.
assertEqual
(
len
(
rule_tool
.
searchRuleList
(
self
.
sm
)),
1
)
self
.
sm
.
setTradePhase
(
None
)
self
.
stepTic
()
self
.
assertEqual
(
len
(
rule_tool
.
searchRuleList
(
self
.
sm
)),
1
)
def
test_08_updateAppliedRule
(
self
,
quiet
=
quiet
,
run
=
run_all_test
):
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment