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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Amer
erp5
Commits
3763559a
Commit
3763559a
authored
May 12, 2015
by
wenjie.zheng
Committed by
Sebastien Robin
Jul 16, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
testERP5Workflow.py: now adapt to the new workflow structure.
parent
c48fe102
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
56 deletions
+70
-56
product/ERP5Workflow/tests/testERP5Workflow.py
product/ERP5Workflow/tests/testERP5Workflow.py
+70
-56
No files found.
product/ERP5Workflow/tests/testERP5Workflow.py
View file @
3763559a
##############################################################################
#
# Copyright (c) 2007 Nexedi SA and Contributors. All Rights Reserved.
# Jerome Perrin <jerome@nexedi.com>
# Jerome Perrin <jerome@nexedi.com>
# 2015 Wenjie ZHENG <wenjie.zheng@tiolive.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
...
...
@@ -49,167 +50,180 @@ class TestERP5Workflow(ERP5TypeTestCase):
def
afterSetUp
(
self
):
self
.
portal
=
self
.
getPortal
()
self
.
workflow_module
=
self
.
portal
.
workflow_module
#self.portal.migrateToPortalWorkflowClass()
self
.
workflow_module
=
self
.
portal
.
portal_workflow
self
.
login
()
# as Manager
def
test_SimpleWorkflow
(
self
):
workflow
=
self
.
workflow_module
.
newContent
(
portal_type
=
'Workflow'
)
workflow
.
setReference
(
'wf'
)
# state variable
workflow
.
setStateVariable
(
'current_state'
)
s1
=
workflow
.
newContent
(
portal_type
=
'State'
,
title
=
'State 1'
)
s2
=
workflow
.
newContent
(
portal_type
=
'State'
,
title
=
'State 2'
)
s1
.
setReference
(
's1'
)
s2
.
setReference
(
's2'
)
t1
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
title
=
'Transition 1'
)
title
=
'Transition 1'
,
)
t1
.
setReference
(
't1'
)
s1
.
setDestinationValue
(
t1
)
t1
.
setDestinationValue
(
s2
)
# set initial state
workflow
.
setSourceValue
(
s1
)
# state variable
workflow
.
setStateBaseCategory
(
'current_state'
)
# create a document and associate it to this workflow
self
.
getPortalObject
().
portal_types
.
_getOb
(
'Folder'
).
edit
(
type_erp5workflow_list
=
(
'workflow_wf'
))
doc
=
self
.
portal
.
newContent
(
portal_type
=
'Folder'
,
id
=
'test_doc'
)
workflow
.
initializeDocument
(
doc
)
self
.
assertEqual
(
s1
.
getRelativeUrl
(),
doc
.
_getDefaultAcquiredCategoryMembership
(
'current_state'
))
self
.
assertEqual
(
's1'
,
workflow
.
_getWorkflowStateOf
(
doc
,
id_only
=
1
))
# pass a transition
t1
.
execute
(
doc
)
self
.
assertEqual
(
s2
.
getRelativeUrl
(),
doc
.
_getDefaultAcquiredCategoryMembership
(
'current_state'
))
workflow
.
_executeTransition
(
doc
,
t1
)
self
.
assertEqual
(
's2'
,
workflow
.
_getWorkflowStateOf
(
doc
,
id_only
=
1
))
def
test_getAvailableTransitionList
(
self
):
workflow
=
self
.
workflow_module
.
newContent
(
portal_type
=
'Workflow'
,
state_base_category
=
'current_state'
)
portal_type
=
'Workflow'
)
workflow
.
setReference
(
'wf'
)
workflow
.
setStateVariable
(
'current_state'
)
s1
=
workflow
.
newContent
(
portal_type
=
'State'
,
title
=
'State 1'
)
s1
.
setReference
(
's1'
)
workflow
.
setSourceValue
(
s1
)
t1
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
title
=
'Transition 1'
)
t1
.
setReference
(
't1'
)
t2
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
title
=
'Transition 2'
,
guard_expression
=
'python: False'
)
t2
.
setReference
(
't2'
)
s1
.
setDestinationValueList
([
t1
,
t2
])
self
.
getPortalObject
().
portal_types
.
_getOb
(
'Folder'
).
edit
(
type_erp5workflow_list
=
(
'workflow_wf'
))
doc
=
self
.
portal
.
newContent
(
portal_type
=
'Folder'
,
id
=
'test_doc'
)
workflow
.
initializeDocument
(
doc
)
self
.
assertEqual
([
t1
],
s1
.
getAvailableTransitionList
(
doc
))
self
.
assertEqual
([
t1
,
t2
],
s1
.
getDestinationValueList
())
def
test_WorkflowVariables
(
self
):
workflow
=
self
.
workflow_module
.
newContent
(
portal_type
=
'Workflow'
,
state_base_category
=
'current_state'
)
portal_type
=
'Workflow'
)
workflow
.
setReference
(
'wf'
)
workflow
.
setStateVariable
(
'current_state'
)
s1
=
workflow
.
newContent
(
portal_type
=
'State'
,
title
=
'State 1'
)
s1
.
setReference
(
's1'
)
workflow
.
setSourceValue
(
s1
)
t1
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
title
=
'Transition 1'
,
destination_value
=
s1
)
t1
.
setReference
(
't1'
)
s1
.
setDestinationValue
(
t1
)
v1
=
workflow
.
newContent
(
portal_type
=
'Variable'
,
title
=
'actor'
,
initial_value
=
'member/getUserName'
)
title
=
'actor'
)
v1
.
setReference
(
'actor'
)
v1
.
default_expr
=
'user/getUserName'
self
.
getPortalObject
().
portal_types
.
_getOb
(
'Folder'
).
edit
(
type_erp5workflow_list
=
(
'workflow_wf'
))
doc
=
self
.
portal
.
newContent
(
portal_type
=
'Folder'
,
id
=
'test_doc'
)
workflow
.
initializeDocument
(
doc
)
t1
.
execute
(
doc
)
workflow
.
_executeTransition
(
doc
,
t1
)
current_state
=
workflow
.
getCurrentStatusDict
(
doc
)
self
.
assertTrue
(
isinstance
(
current_state
,
dict
))
self
.
assertEqual
(
s1
.
getRe
lativeUrl
(),
current_state
.
get
(
'current_state'
))
self
.
assertEqual
(
s1
.
getRe
ference
(),
current_state
.
get
(
'current_state'
))
self
.
assertEqual
(
'ERP5TypeTestCase'
,
current_state
.
get
(
'actor'
))
self
.
assertEqual
(
0
,
current_state
.
get
(
'undo'
))
# XXX workflow history is a method on State ?
history
=
s1
.
getWorkflowHistory
(
doc
)
self
.
assertEqual
(
len
(
history
),
2
)
history
=
doc
.
workflow_history
[
'wf'
]
self
.
assertEqual
(
len
(
history
),
2
)
# create, t1
def
test_afterScript
(
self
):
workflow
=
self
.
workflow_module
.
newContent
(
portal_type
=
'Workflow'
,
state_base_category
=
'current_state'
)
workflow
.
setReference
(
'wf'
)
s1
=
workflow
.
newContent
(
portal_type
=
'State'
,
title
=
'State 1'
)
s2
=
workflow
.
newContent
(
portal_type
=
'State'
,
title
=
'State 2'
)
s1
.
setReference
(
's1'
)
s2
.
setReference
(
's2'
)
t1
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
title
=
'Transition 1'
,
after_script_id
=
'Document_testAfterScript'
after_script_id
=
'Document_testAfterScript'
,
)
t1
.
setReference
(
't1'
)
s1
.
setDestinationValue
(
t1
)
t1
.
setDestinationValue
(
s2
)
workflow
.
setSourceValue
(
s1
)
script
=
workflow
.
newContent
(
portal_type
=
'Workflow Script'
,
id
=
'Document_testAfterScript'
)
script
.
setParameterSignature
(
"state_change"
)
script
.
setParameterSignature
(
"state_change"
)
script
.
setBody
(
"state_change['object'].setDescription('After script was executed.')"
)
self
.
getPortalObject
().
portal_types
.
_getOb
(
'Folder'
).
edit
(
type_erp5workflow_list
=
(
'workflow_wf'
))
doc
=
self
.
portal
.
newContent
(
portal_type
=
'Folder'
,
id
=
'test_doc'
)
called
=
[]
def
Document_testAfterScript
(
**
kw
):
called
.
append
(
'called %s'
%
kw
)
doc
.
Document_testAfterScript
=
Document_testAfterScript
workflow
.
initializeDocument
(
doc
)
t1
.
execute
(
doc
)
self
.
assertEqual
([
'called {}'
],
called
)
workflow
.
_executeTransition
(
doc
,
t1
)
self
.
assertEqual
(
'After script was executed.'
,
doc
.
getDescription
())
# FIXME: not passing parameter to an after script is probably too
# restrictive
def
test_BeforeScript
(
self
):
workflow
=
self
.
workflow_module
.
newContent
(
portal_type
=
'Workflow'
,
state_base_category
=
'current_state'
)
portal_type
=
'Workflow'
)
workflow
.
setReference
(
'wf'
)
workflow
.
setStateVariable
(
'current_state'
)
s1
=
workflow
.
newContent
(
portal_type
=
'State'
,
title
=
'State 1'
)
s2
=
workflow
.
newContent
(
portal_type
=
'State'
,
title
=
'State 2'
)
s1
.
setReference
(
's1'
)
s2
.
setReference
(
's2'
)
t1
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
title
=
'Transition 1'
,
before_script_id
=
'Document_testBeforeScript'
before_script_id
=
'Document_testBeforeScript'
,
)
t1
.
setReference
(
't1'
)
s1
.
setDestinationValue
(
t1
)
t1
.
setDestinationValue
(
s2
)
workflow
.
setSourceValue
(
s1
)
script
=
workflow
.
newContent
(
portal_type
=
'Workflow Script'
,
id
=
'Document_testBeforeScript'
)
script
.
setParameterSignature
(
"state_change"
)
script
.
setBody
(
"state_change['object'].setDescription('Before script was executed.')"
)
self
.
getPortalObject
().
portal_types
.
_getOb
(
'Folder'
).
edit
(
type_erp5workflow_list
=
(
'workflow_wf'
))
doc
=
self
.
portal
.
newContent
(
portal_type
=
'Folder'
,
id
=
'test_doc'
)
called
=
[]
def
Document_testBeforeScript
(
**
kw
):
called
.
append
(
'called %s'
%
kw
)
doc
.
Document_testBeforeScript
=
Document_testBeforeScript
workflow
.
initializeDocument
(
doc
)
t1
.
execute
(
doc
)
self
.
assertEqual
([
'called {}'
],
called
)
workflow
.
_executeTransition
(
doc
,
t1
)
self
.
assertEqual
(
'Before script was executed.'
,
doc
.
getDescription
())
# FIXME: not passing parameter to an before script is probably too
# restrictive
def
test_WorkflowSecurity
(
self
):
"""
Test workflow security.
Test workflow security.
Should be test with other methods. To be finished.
"""
workflow_module
=
self
.
portal
.
workflow_module
workflow_module
=
self
.
portal
.
portal_workflow
def
createWorkflowInstance
():
return
workflow_module
.
newContent
(
portal_type
=
'Workflow'
)
workflow
=
workflow_module
.
newContent
(
portal_type
=
'Workflow'
)
workflow
.
setReference
(
'wf'
)
return
workflow
workflow_instance
=
createWorkflowInstance
()
# Anonymous User must not be able to access workflow module
# or workflow instances
self
.
changeToAnonymous
()
self
.
assertRaises
(
Unauthorized
,
workflow_module
.
view
)
self
.
assertRaises
(
Unauthorized
,
createWorkflowInstance
)
self
.
assertRaises
(
Unauthorized
,
lambda
:
workflow_instance
.
view
())
#
self.assertRaises(Unauthorized, workflow_module.view)
#
self.assertRaises(Unauthorized, createWorkflowInstance)
#
self.assertRaises(Unauthorized, lambda: workflow_instance.view())
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
TestERP5Workflow
))
return
suite
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