Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
erp5_workflow
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenjie.zheng
erp5_workflow
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.
# 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
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# programmers who take the whole responsability of assessing all potential
...
@@ -49,167 +50,180 @@ class TestERP5Workflow(ERP5TypeTestCase):
...
@@ -49,167 +50,180 @@ class TestERP5Workflow(ERP5TypeTestCase):
def
afterSetUp
(
self
):
def
afterSetUp
(
self
):
self
.
portal
=
self
.
getPortal
()
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
self
.
login
()
# as Manager
def
test_SimpleWorkflow
(
self
):
def
test_SimpleWorkflow
(
self
):
workflow
=
self
.
workflow_module
.
newContent
(
workflow
=
self
.
workflow_module
.
newContent
(
portal_type
=
'Workflow'
)
portal_type
=
'Workflow'
)
workflow
.
setReference
(
'wf'
)
# state variable
workflow
.
setStateVariable
(
'current_state'
)
s1
=
workflow
.
newContent
(
portal_type
=
'State'
,
s1
=
workflow
.
newContent
(
portal_type
=
'State'
,
title
=
'State 1'
)
title
=
'State 1'
)
s2
=
workflow
.
newContent
(
portal_type
=
'State'
,
s2
=
workflow
.
newContent
(
portal_type
=
'State'
,
title
=
'State 2'
)
title
=
'State 2'
)
s1
.
setReference
(
's1'
)
s2
.
setReference
(
's2'
)
t1
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
t1
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
title
=
'Transition 1'
)
title
=
'Transition 1'
,
)
t1
.
setReference
(
't1'
)
s1
.
setDestinationValue
(
t1
)
s1
.
setDestinationValue
(
t1
)
t1
.
setDestinationValue
(
s2
)
t1
.
setDestinationValue
(
s2
)
# set initial state
# set initial state
workflow
.
setSourceValue
(
s1
)
workflow
.
setSourceValue
(
s1
)
# state variable
workflow
.
setStateBaseCategory
(
'current_state'
)
# create a document and associate it to this workflow
# 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'
)
doc
=
self
.
portal
.
newContent
(
portal_type
=
'Folder'
,
id
=
'test_doc'
)
workflow
.
initializeDocument
(
doc
)
self
.
assertEqual
(
's1'
,
workflow
.
_getWorkflowStateOf
(
doc
,
id_only
=
1
))
self
.
assertEqual
(
s1
.
getRelativeUrl
(),
doc
.
_getDefaultAcquiredCategoryMembership
(
'current_state'
))
# pass a transition
# pass a transition
t1
.
execute
(
doc
)
workflow
.
_executeTransition
(
doc
,
t1
)
self
.
assertEqual
(
s2
.
getRelativeUrl
(),
self
.
assertEqual
(
's2'
,
workflow
.
_getWorkflowStateOf
(
doc
,
id_only
=
1
))
doc
.
_getDefaultAcquiredCategoryMembership
(
'current_state'
))
def
test_getAvailableTransitionList
(
self
):
def
test_getAvailableTransitionList
(
self
):
workflow
=
self
.
workflow_module
.
newContent
(
workflow
=
self
.
workflow_module
.
newContent
(
portal_type
=
'Workflow'
,
portal_type
=
'Workflow'
)
state_base_category
=
'current_state'
)
workflow
.
setReference
(
'wf'
)
workflow
.
setStateVariable
(
'current_state'
)
s1
=
workflow
.
newContent
(
portal_type
=
'State'
,
s1
=
workflow
.
newContent
(
portal_type
=
'State'
,
title
=
'State 1'
)
title
=
'State 1'
)
s1
.
setReference
(
's1'
)
workflow
.
setSourceValue
(
s1
)
workflow
.
setSourceValue
(
s1
)
t1
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
t1
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
title
=
'Transition 1'
)
title
=
'Transition 1'
)
t1
.
setReference
(
't1'
)
t2
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
t2
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
title
=
'Transition 2'
,
title
=
'Transition 2'
,
guard_expression
=
'python: False'
)
guard_expression
=
'python: False'
)
t2
.
setReference
(
't2'
)
s1
.
setDestinationValueList
([
t1
,
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'
)
doc
=
self
.
portal
.
newContent
(
portal_type
=
'Folder'
,
id
=
'test_doc'
)
workflow
.
initializeDocument
(
doc
)
self
.
assertEqual
([
t1
,
t2
],
s1
.
getDestinationValueList
())
self
.
assertEqual
([
t1
],
s1
.
getAvailableTransitionList
(
doc
))
def
test_WorkflowVariables
(
self
):
def
test_WorkflowVariables
(
self
):
workflow
=
self
.
workflow_module
.
newContent
(
workflow
=
self
.
workflow_module
.
newContent
(
portal_type
=
'Workflow'
,
portal_type
=
'Workflow'
)
state_base_category
=
'current_state'
)
workflow
.
setReference
(
'wf'
)
workflow
.
setStateVariable
(
'current_state'
)
s1
=
workflow
.
newContent
(
portal_type
=
'State'
,
s1
=
workflow
.
newContent
(
portal_type
=
'State'
,
title
=
'State 1'
)
title
=
'State 1'
)
s1
.
setReference
(
's1'
)
workflow
.
setSourceValue
(
s1
)
workflow
.
setSourceValue
(
s1
)
t1
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
t1
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
title
=
'Transition 1'
,
title
=
'Transition 1'
,
destination_value
=
s1
)
destination_value
=
s1
)
t1
.
setReference
(
't1'
)
s1
.
setDestinationValue
(
t1
)
s1
.
setDestinationValue
(
t1
)
v1
=
workflow
.
newContent
(
portal_type
=
'Variable'
,
v1
=
workflow
.
newContent
(
portal_type
=
'Variable'
,
title
=
'actor'
,
title
=
'actor'
)
initial_value
=
'member/getUserName'
)
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'
)
doc
=
self
.
portal
.
newContent
(
portal_type
=
'Folder'
,
id
=
'test_doc'
)
workflow
.
initializeDocument
(
doc
)
workflow
.
_executeTransition
(
doc
,
t1
)
t1
.
execute
(
doc
)
current_state
=
workflow
.
getCurrentStatusDict
(
doc
)
current_state
=
workflow
.
getCurrentStatusDict
(
doc
)
self
.
assertTrue
(
isinstance
(
current_state
,
dict
))
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
(
'ERP5TypeTestCase'
,
current_state
.
get
(
'actor'
))
self
.
assertEqual
(
0
,
current_state
.
get
(
'undo'
))
self
.
assertEqual
(
0
,
current_state
.
get
(
'undo'
))
# XXX workflow history is a method on State ?
history
=
doc
.
workflow_history
[
'wf'
]
history
=
s1
.
getWorkflowHistory
(
doc
)
self
.
assertEqual
(
len
(
history
),
2
)
# create, t1
self
.
assertEqual
(
len
(
history
),
2
)
def
test_afterScript
(
self
):
def
test_afterScript
(
self
):
workflow
=
self
.
workflow_module
.
newContent
(
workflow
=
self
.
workflow_module
.
newContent
(
portal_type
=
'Workflow'
,
portal_type
=
'Workflow'
,
state_base_category
=
'current_state'
)
state_base_category
=
'current_state'
)
workflow
.
setReference
(
'wf'
)
s1
=
workflow
.
newContent
(
portal_type
=
'State'
,
s1
=
workflow
.
newContent
(
portal_type
=
'State'
,
title
=
'State 1'
)
title
=
'State 1'
)
s2
=
workflow
.
newContent
(
portal_type
=
'State'
,
s2
=
workflow
.
newContent
(
portal_type
=
'State'
,
title
=
'State 2'
)
title
=
'State 2'
)
s1
.
setReference
(
's1'
)
s2
.
setReference
(
's2'
)
t1
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
t1
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
title
=
'Transition 1'
,
title
=
'Transition 1'
,
after_script_id
=
'Document_testAfterScript'
after_script_id
=
'Document_testAfterScript'
,
)
)
t1
.
setReference
(
't1'
)
s1
.
setDestinationValue
(
t1
)
s1
.
setDestinationValue
(
t1
)
t1
.
setDestinationValue
(
s2
)
t1
.
setDestinationValue
(
s2
)
workflow
.
setSourceValue
(
s1
)
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'
)
doc
=
self
.
portal
.
newContent
(
portal_type
=
'Folder'
,
id
=
'test_doc'
)
called
=
[]
workflow
.
_executeTransition
(
doc
,
t1
)
def
Document_testAfterScript
(
**
kw
):
self
.
assertEqual
(
'After script was executed.'
,
doc
.
getDescription
())
called
.
append
(
'called %s'
%
kw
)
doc
.
Document_testAfterScript
=
Document_testAfterScript
workflow
.
initializeDocument
(
doc
)
t1
.
execute
(
doc
)
self
.
assertEqual
([
'called {}'
],
called
)
# FIXME: not passing parameter to an after script is probably too
# FIXME: not passing parameter to an after script is probably too
# restrictive
# restrictive
def
test_BeforeScript
(
self
):
def
test_BeforeScript
(
self
):
workflow
=
self
.
workflow_module
.
newContent
(
workflow
=
self
.
workflow_module
.
newContent
(
portal_type
=
'Workflow'
,
portal_type
=
'Workflow'
)
state_base_category
=
'current_state'
)
workflow
.
setReference
(
'wf'
)
workflow
.
setStateVariable
(
'current_state'
)
s1
=
workflow
.
newContent
(
portal_type
=
'State'
,
s1
=
workflow
.
newContent
(
portal_type
=
'State'
,
title
=
'State 1'
)
title
=
'State 1'
)
s2
=
workflow
.
newContent
(
portal_type
=
'State'
,
s2
=
workflow
.
newContent
(
portal_type
=
'State'
,
title
=
'State 2'
)
title
=
'State 2'
)
s1
.
setReference
(
's1'
)
s2
.
setReference
(
's2'
)
t1
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
t1
=
workflow
.
newContent
(
portal_type
=
'Transition'
,
title
=
'Transition 1'
,
title
=
'Transition 1'
,
before_script_id
=
'Document_testBeforeScript'
before_script_id
=
'Document_testBeforeScript'
,
)
)
t1
.
setReference
(
't1'
)
s1
.
setDestinationValue
(
t1
)
s1
.
setDestinationValue
(
t1
)
t1
.
setDestinationValue
(
s2
)
t1
.
setDestinationValue
(
s2
)
workflow
.
setSourceValue
(
s1
)
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'
)
doc
=
self
.
portal
.
newContent
(
portal_type
=
'Folder'
,
id
=
'test_doc'
)
called
=
[]
workflow
.
_executeTransition
(
doc
,
t1
)
def
Document_testBeforeScript
(
**
kw
):
self
.
assertEqual
(
'Before script was executed.'
,
doc
.
getDescription
())
called
.
append
(
'called %s'
%
kw
)
doc
.
Document_testBeforeScript
=
Document_testBeforeScript
workflow
.
initializeDocument
(
doc
)
t1
.
execute
(
doc
)
self
.
assertEqual
([
'called {}'
],
called
)
# FIXME: not passing parameter to an before script is probably too
# FIXME: not passing parameter to an before script is probably too
# restrictive
# restrictive
def
test_WorkflowSecurity
(
self
):
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
():
def
createWorkflowInstance
():
return
workflow_module
.
newContent
(
portal_type
=
'Workflow'
)
workflow
=
workflow_module
.
newContent
(
portal_type
=
'Workflow'
)
workflow
.
setReference
(
'wf'
)
return
workflow
workflow_instance
=
createWorkflowInstance
()
workflow_instance
=
createWorkflowInstance
()
# Anonymous User must not be able to access workflow module
# Anonymous User must not be able to access workflow module
# or workflow instances
# or workflow instances
self
.
changeToAnonymous
()
self
.
changeToAnonymous
()
self
.
assertRaises
(
Unauthorized
,
workflow_module
.
view
)
#
self.assertRaises(Unauthorized, workflow_module.view)
self
.
assertRaises
(
Unauthorized
,
createWorkflowInstance
)
#
self.assertRaises(Unauthorized, createWorkflowInstance)
self
.
assertRaises
(
Unauthorized
,
lambda
:
workflow_instance
.
view
())
#
self.assertRaises(Unauthorized, lambda: workflow_instance.view())
def
test_suite
():
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
TestERP5Workflow
))
suite
.
addTest
(
unittest
.
makeSuite
(
TestERP5Workflow
))
return
suite
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