author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 21 Dec 2009 19:20:45 +0100 | |
changeset 4157 | f7830377b215 |
parent 4030 | 6cfe4faddf8c |
child 4644 | 021035b9a7ab |
permissions | -rw-r--r-- |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
1 |
from cubicweb.devtools.testlib import CubicWebTC |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
2 |
from cubicweb import ValidationError |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
3 |
|
2992
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
4 |
def add_wf(self, etype, name=None, default=False): |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
5 |
if name is None: |
2992
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
6 |
name = etype |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
7 |
wf = self.execute('INSERT Workflow X: X name %(n)s', {'n': unicode(name)}).get_entity(0, 0) |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
8 |
self.execute('SET WF workflow_of ET WHERE WF eid %(wf)s, ET name %(et)s', |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
9 |
{'wf': wf.eid, 'et': etype}) |
2992
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
10 |
if default: |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
11 |
self.execute('SET ET default_workflow WF WHERE WF eid %(wf)s, ET name %(et)s', |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
12 |
{'wf': wf.eid, 'et': etype}) |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
13 |
return wf |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
14 |
|
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
15 |
def parse_hist(wfhist): |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
16 |
return [(ti.previous_state.name, ti.new_state.name, |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
17 |
ti.transition and ti.transition.name, ti.comment) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
18 |
for ti in wfhist] |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
19 |
|
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
20 |
|
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
21 |
class WorkflowBuildingTC(CubicWebTC): |
2939
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
22 |
|
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
23 |
def test_wf_construction(self): |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
24 |
wf = add_wf(self, 'Company') |
2939
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
25 |
foo = wf.add_state(u'foo', initial=True) |
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
26 |
bar = wf.add_state(u'bar') |
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
27 |
self.assertEquals(wf.state_by_name('bar').eid, bar.eid) |
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
28 |
self.assertEquals(wf.state_by_name('barrr'), None) |
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
29 |
baz = wf.add_transition(u'baz', (foo,), bar, ('managers',)) |
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
30 |
self.assertEquals(wf.transition_by_name('baz').eid, baz.eid) |
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
31 |
self.assertEquals(len(baz.require_group), 1) |
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
32 |
self.assertEquals(baz.require_group[0].name, 'managers') |
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
33 |
|
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
34 |
def test_duplicated_state(self): |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
35 |
wf = add_wf(self, 'Company') |
2939
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
36 |
wf.add_state(u'foo', initial=True) |
2979
94277323239d
test two different wfs may have a state of the same name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2977
diff
changeset
|
37 |
self.commit() |
2939
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
38 |
wf.add_state(u'foo') |
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
39 |
ex = self.assertRaises(ValidationError, self.commit) |
3966
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
40 |
self.assertEquals(ex.errors, {'name': 'workflow already have a state of that name'}) |
2979
94277323239d
test two different wfs may have a state of the same name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2977
diff
changeset
|
41 |
# no pb if not in the same workflow |
94277323239d
test two different wfs may have a state of the same name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2977
diff
changeset
|
42 |
wf2 = add_wf(self, 'Company') |
94277323239d
test two different wfs may have a state of the same name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2977
diff
changeset
|
43 |
foo = wf2.add_state(u'foo', initial=True) |
94277323239d
test two different wfs may have a state of the same name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2977
diff
changeset
|
44 |
self.commit() |
3966
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
45 |
# gnark gnark |
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
46 |
bar = wf.add_state(u'bar') |
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
47 |
self.commit() |
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
48 |
bar.set_attributes(name=u'foo') |
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
49 |
ex = self.assertRaises(ValidationError, self.commit) |
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
50 |
self.assertEquals(ex.errors, {'name': 'workflow already have a state of that name'}) |
2939
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
51 |
|
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
52 |
def test_duplicated_transition(self): |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
53 |
wf = add_wf(self, 'Company') |
2939
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
54 |
foo = wf.add_state(u'foo', initial=True) |
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
55 |
bar = wf.add_state(u'bar') |
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
56 |
wf.add_transition(u'baz', (foo,), bar, ('managers',)) |
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
57 |
wf.add_transition(u'baz', (bar,), foo) |
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
58 |
ex = self.assertRaises(ValidationError, self.commit) |
3966
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
59 |
self.assertEquals(ex.errors, {'name': 'workflow already have a transition of that name'}) |
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
60 |
# no pb if not in the same workflow |
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
61 |
wf2 = add_wf(self, 'Company') |
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
62 |
foo = wf.add_state(u'foo', initial=True) |
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
63 |
bar = wf.add_state(u'bar') |
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
64 |
wf.add_transition(u'baz', (foo,), bar, ('managers',)) |
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
65 |
self.commit() |
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
66 |
# gnark gnark |
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
67 |
biz = wf.add_transition(u'biz', (bar,), foo) |
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
68 |
self.commit() |
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
69 |
biz.set_attributes(name=u'baz') |
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
70 |
ex = self.assertRaises(ValidationError, self.commit) |
f742c525b7b4
fix workflow consistency: check state/transition name uniqness in the wf when state/transition name is modified ; use the new msg argument of rql constraints to have a nicer error message on failure
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3879
diff
changeset
|
71 |
self.assertEquals(ex.errors, {'name': 'workflow already have a transition of that name'}) |
2939
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
72 |
|
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
73 |
|
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
74 |
class WorkflowTC(CubicWebTC): |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
75 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
76 |
def setup_database(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
77 |
rschema = self.schema['in_state'] |
4024
6a14cff373c3
more api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
78 |
for rdef in rschema.rdefs.values(): |
6a14cff373c3
more api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
79 |
self.assertEquals(rdef.cardinality, '1*') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
80 |
self.member = self.create_user('member') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
81 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
82 |
def test_workflow_base(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
83 |
e = self.create_user('toto') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
84 |
self.assertEquals(e.state, 'activated') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
85 |
e.change_state('deactivated', u'deactivate 1') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
86 |
self.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
87 |
e.change_state('activated', u'activate 1') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
88 |
self.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
89 |
e.change_state('deactivated', u'deactivate 2') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
90 |
self.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
91 |
e.clear_related_cache('wf_info_for', 'object') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
92 |
self.assertEquals([tr.comment for tr in e.reverse_wf_info_for], |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
93 |
['deactivate 1', 'activate 1', 'deactivate 2']) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
94 |
self.assertEquals(e.latest_trinfo().comment, 'deactivate 2') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
95 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
96 |
def test_possible_transitions(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
97 |
user = self.entity('CWUser X') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
98 |
trs = list(user.possible_transitions()) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
99 |
self.assertEquals(len(trs), 1) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
100 |
self.assertEquals(trs[0].name, u'deactivate') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
101 |
self.assertEquals(trs[0].destination().name, u'deactivated') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
102 |
# test a std user get no possible transition |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
103 |
cnx = self.login('member') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
104 |
# fetch the entity using the new session |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
105 |
trs = list(cnx.user().possible_transitions()) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
106 |
self.assertEquals(len(trs), 0) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
107 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
108 |
def _test_manager_deactivate(self, user): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
109 |
user.clear_related_cache('in_state', 'subject') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
110 |
self.assertEquals(len(user.in_state), 1) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
111 |
self.assertEquals(user.state, 'deactivated') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
112 |
trinfo = user.latest_trinfo() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
113 |
self.assertEquals(trinfo.previous_state.name, 'activated') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
114 |
self.assertEquals(trinfo.new_state.name, 'deactivated') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
115 |
self.assertEquals(trinfo.comment, 'deactivate user') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
116 |
self.assertEquals(trinfo.comment_format, 'text/plain') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
117 |
return trinfo |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
118 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
119 |
def test_change_state(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
120 |
user = self.user() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
121 |
user.change_state('deactivated', comment=u'deactivate user') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
122 |
trinfo = self._test_manager_deactivate(user) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
123 |
self.assertEquals(trinfo.transition, None) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
124 |
|
2983
b458631fe347
[wf] test in_state consistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2982
diff
changeset
|
125 |
def test_set_in_state_bad_wf(self): |
b458631fe347
[wf] test in_state consistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2982
diff
changeset
|
126 |
wf = add_wf(self, 'CWUser') |
b458631fe347
[wf] test in_state consistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2982
diff
changeset
|
127 |
s = wf.add_state(u'foo', initial=True) |
b458631fe347
[wf] test in_state consistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2982
diff
changeset
|
128 |
self.commit() |
3024
bfaf056f1029
backport 3.5 step 2, backport wf changes in hooks/workflow.py
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3023
diff
changeset
|
129 |
ex = self.assertRaises(ValidationError, self.session.unsafe_execute, |
2983
b458631fe347
[wf] test in_state consistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2982
diff
changeset
|
130 |
'SET X in_state S WHERE X eid %(x)s, S eid %(s)s', |
b458631fe347
[wf] test in_state consistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2982
diff
changeset
|
131 |
{'x': self.user().eid, 's': s.eid}, 'x') |
b458631fe347
[wf] test in_state consistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2982
diff
changeset
|
132 |
self.assertEquals(ex.errors, {'in_state': "state doesn't belong to entity's workflow. " |
b458631fe347
[wf] test in_state consistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2982
diff
changeset
|
133 |
"You may want to set a custom workflow for this entity first."}) |
b458631fe347
[wf] test in_state consistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2982
diff
changeset
|
134 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
135 |
def test_fire_transition(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
136 |
user = self.user() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
137 |
user.fire_transition('deactivate', comment=u'deactivate user') |
2982
1768dbe8e9b3
[wf] need to clear cache here
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2979
diff
changeset
|
138 |
user.clear_all_caches() |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
139 |
self.assertEquals(user.state, 'deactivated') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
140 |
self._test_manager_deactivate(user) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
141 |
trinfo = self._test_manager_deactivate(user) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
142 |
self.assertEquals(trinfo.transition.name, 'deactivate') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
143 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
144 |
# XXX test managers can change state without matching transition |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
145 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
146 |
def _test_stduser_deactivate(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
147 |
ueid = self.member.eid |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
148 |
self.create_user('tutu') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
149 |
cnx = self.login('tutu') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
150 |
req = self.request() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
151 |
member = req.entity_from_eid(self.member.eid) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
152 |
ex = self.assertRaises(ValidationError, |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
153 |
member.fire_transition, 'deactivate') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
154 |
self.assertEquals(ex.errors, {'by_transition': "transition may not be fired"}) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
155 |
cnx.close() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
156 |
cnx = self.login('member') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
157 |
req = self.request() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
158 |
member = req.entity_from_eid(self.member.eid) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
159 |
member.fire_transition('deactivate') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
160 |
cnx.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
161 |
ex = self.assertRaises(ValidationError, |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
162 |
member.fire_transition, 'activate') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
163 |
self.assertEquals(ex.errors, {'by_transition': "transition may not be fired"}) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
164 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
165 |
def test_fire_transition_owned_by(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
166 |
self.execute('INSERT RQLExpression X: X exprtype "ERQLExpression", ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
167 |
'X expression "X owned_by U", T condition X ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
168 |
'WHERE T name "deactivate"') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
169 |
self._test_stduser_deactivate() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
170 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
171 |
def test_fire_transition_has_update_perm(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
172 |
self.execute('INSERT RQLExpression X: X exprtype "ERQLExpression", ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
173 |
'X expression "U has_update_permission X", T condition X ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
174 |
'WHERE T name "deactivate"') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
175 |
self._test_stduser_deactivate() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
176 |
|
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
177 |
def test_swf_base(self): |
2992
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
178 |
"""subworkflow |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
179 |
|
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
180 |
+-----------+ tr1 +-----------+ |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
181 |
| swfstate1 | ------>| swfstate2 | |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
182 |
+-----------+ +-----------+ |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
183 |
| tr2 +-----------+ |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
184 |
`------>| swfstate3 | |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
185 |
+-----------+ |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
186 |
|
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
187 |
main workflow |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
188 |
|
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
189 |
+--------+ swftr1 +--------+ |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
190 |
| state1 | -------[swfstate2]->| state2 | |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
191 |
+--------+ | +--------+ |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
192 |
| +--------+ |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
193 |
`-[swfstate3]-->| state3 | |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
194 |
+--------+ |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
195 |
""" |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
196 |
# sub-workflow |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
197 |
swf = add_wf(self, 'CWGroup', name='subworkflow') |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
198 |
swfstate1 = swf.add_state(u'swfstate1', initial=True) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
199 |
swfstate2 = swf.add_state(u'swfstate2') |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
200 |
swfstate3 = swf.add_state(u'swfstate3') |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
201 |
tr1 = swf.add_transition(u'tr1', (swfstate1,), swfstate2) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
202 |
tr2 = swf.add_transition(u'tr2', (swfstate1,), swfstate3) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
203 |
# main workflow |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
204 |
mwf = add_wf(self, 'CWGroup', name='main workflow', default=True) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
205 |
state1 = mwf.add_state(u'state1', initial=True) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
206 |
state2 = mwf.add_state(u'state2') |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
207 |
state3 = mwf.add_state(u'state3') |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
208 |
swftr1 = mwf.add_wftransition(u'swftr1', swf, state1, |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
209 |
[(swfstate2, state2), (swfstate3, state3)]) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
210 |
self.assertEquals(swftr1.destination().eid, swfstate1.eid) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
211 |
# workflows built, begin test |
4024
6a14cff373c3
more api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
212 |
self.group = self.request().create_entity('CWGroup', name=u'grp1') |
2992
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
213 |
self.commit() |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
214 |
self.assertEquals(self.group.current_state.eid, state1.eid) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
215 |
self.assertEquals(self.group.current_workflow.eid, mwf.eid) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
216 |
self.assertEquals(self.group.main_workflow.eid, mwf.eid) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
217 |
self.assertEquals(self.group.subworkflow_input_transition(), None) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
218 |
self.group.fire_transition('swftr1', u'go') |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
219 |
self.commit() |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
220 |
self.group.clear_all_caches() |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
221 |
self.assertEquals(self.group.current_state.eid, swfstate1.eid) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
222 |
self.assertEquals(self.group.current_workflow.eid, swf.eid) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
223 |
self.assertEquals(self.group.main_workflow.eid, mwf.eid) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
224 |
self.assertEquals(self.group.subworkflow_input_transition().eid, swftr1.eid) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
225 |
self.group.fire_transition('tr1', u'go') |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
226 |
self.commit() |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
227 |
self.group.clear_all_caches() |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
228 |
self.assertEquals(self.group.current_state.eid, state2.eid) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
229 |
self.assertEquals(self.group.current_workflow.eid, mwf.eid) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
230 |
self.assertEquals(self.group.main_workflow.eid, mwf.eid) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
231 |
self.assertEquals(self.group.subworkflow_input_transition(), None) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
232 |
# force back to swfstate1 is impossible since we can't any more find |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
233 |
# subworkflow input transition |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
234 |
ex = self.assertRaises(ValidationError, |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
235 |
self.group.change_state, swfstate1, u'gadget') |
4030
6cfe4faddf8c
remove debug print, fix error message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4028
diff
changeset
|
236 |
self.assertEquals(ex.errors, {'to_state': "state doesn't belong to entity's workflow"}) |
2992
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
237 |
self.rollback() |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
238 |
# force back to state1 |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
239 |
self.group.change_state('state1', u'gadget') |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
240 |
self.group.fire_transition('swftr1', u'au') |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
241 |
self.group.clear_all_caches() |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
242 |
self.group.fire_transition('tr2', u'chapeau') |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
243 |
self.commit() |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
244 |
self.group.clear_all_caches() |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
245 |
self.assertEquals(self.group.current_state.eid, state3.eid) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
246 |
self.assertEquals(self.group.current_workflow.eid, mwf.eid) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
247 |
self.assertEquals(self.group.main_workflow.eid, mwf.eid) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
248 |
self.assertListEquals(parse_hist(self.group.workflow_history), |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
249 |
[('state1', 'swfstate1', 'swftr1', 'go'), |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
250 |
('swfstate1', 'swfstate2', 'tr1', 'go'), |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
251 |
('swfstate2', 'state2', 'swftr1', 'exiting from subworkflow subworkflow'), |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
252 |
('state2', 'state1', None, 'gadget'), |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
253 |
('state1', 'swfstate1', 'swftr1', 'au'), |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
254 |
('swfstate1', 'swfstate3', 'tr2', 'chapeau'), |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
255 |
('swfstate3', 'state3', 'swftr1', 'exiting from subworkflow subworkflow'), |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
256 |
]) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
257 |
|
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
258 |
def test_swf_exit_consistency(self): |
2992
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
259 |
# sub-workflow |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
260 |
swf = add_wf(self, 'CWGroup', name='subworkflow') |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
261 |
swfstate1 = swf.add_state(u'swfstate1', initial=True) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
262 |
swfstate2 = swf.add_state(u'swfstate2') |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
263 |
tr1 = swf.add_transition(u'tr1', (swfstate1,), swfstate2) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
264 |
# main workflow |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
265 |
mwf = add_wf(self, 'CWGroup', name='main workflow', default=True) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
266 |
state1 = mwf.add_state(u'state1', initial=True) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
267 |
state2 = mwf.add_state(u'state2') |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
268 |
state3 = mwf.add_state(u'state3') |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
269 |
mwf.add_wftransition(u'swftr1', swf, state1, |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
270 |
[(swfstate2, state2), (swfstate2, state3)]) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
271 |
ex = self.assertRaises(ValidationError, self.commit) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
272 |
self.assertEquals(ex.errors, {'subworkflow_exit': u"can't have multiple exits on the same state"}) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
273 |
|
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
274 |
def test_swf_fire_in_a_row(self): |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
275 |
# sub-workflow |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
276 |
subwf = add_wf(self, 'CWGroup', name='subworkflow') |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
277 |
xsigning = subwf.add_state('xsigning', initial=True) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
278 |
xaborted = subwf.add_state('xaborted') |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
279 |
xsigned = subwf.add_state('xsigned') |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
280 |
xabort = subwf.add_transition('xabort', (xsigning,), xaborted) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
281 |
xsign = subwf.add_transition('xsign', (xsigning,), xsigning) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
282 |
xcomplete = subwf.add_transition('xcomplete', (xsigning,), xsigned, |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
283 |
type=u'auto') |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
284 |
# main workflow |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
285 |
twf = add_wf(self, 'CWGroup', name='mainwf', default=True) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
286 |
created = twf.add_state(_('created'), initial=True) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
287 |
identified = twf.add_state(_('identified')) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
288 |
released = twf.add_state(_('released')) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
289 |
closed = twf.add_state(_('closed')) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
290 |
twf.add_wftransition(_('identify'), subwf, (created,), |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
291 |
[(xsigned, identified), (xaborted, created)]) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
292 |
twf.add_wftransition(_('release'), subwf, (identified,), |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
293 |
[(xsigned, released), (xaborted, identified)]) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
294 |
twf.add_wftransition(_('close'), subwf, (released,), |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
295 |
[(xsigned, closed), (xaborted, released)]) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
296 |
self.commit() |
4024
6a14cff373c3
more api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
297 |
group = self.request().create_entity('CWGroup', name=u'grp1') |
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
298 |
self.commit() |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
299 |
for trans in ('identify', 'release', 'close'): |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
300 |
group.fire_transition(trans) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
301 |
self.commit() |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
302 |
|
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
303 |
|
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
304 |
def test_swf_magic_tr(self): |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
305 |
# sub-workflow |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
306 |
subwf = add_wf(self, 'CWGroup', name='subworkflow') |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
307 |
xsigning = subwf.add_state('xsigning', initial=True) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
308 |
xaborted = subwf.add_state('xaborted') |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
309 |
xsigned = subwf.add_state('xsigned') |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
310 |
xabort = subwf.add_transition('xabort', (xsigning,), xaborted) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
311 |
xsign = subwf.add_transition('xsign', (xsigning,), xsigned) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
312 |
# main workflow |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
313 |
twf = add_wf(self, 'CWGroup', name='mainwf', default=True) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
314 |
created = twf.add_state(_('created'), initial=True) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
315 |
identified = twf.add_state(_('identified')) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
316 |
released = twf.add_state(_('released')) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
317 |
twf.add_wftransition(_('identify'), subwf, created, |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
318 |
[(xaborted, None), (xsigned, identified)]) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
319 |
twf.add_wftransition(_('release'), subwf, identified, |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
320 |
[(xaborted, None)]) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
321 |
self.commit() |
4024
6a14cff373c3
more api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
322 |
group = self.request().create_entity('CWGroup', name=u'grp1') |
3628
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
323 |
self.commit() |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
324 |
for trans, nextstate in (('identify', 'xsigning'), |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
325 |
('xabort', 'created'), |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
326 |
('identify', 'xsigning'), |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
327 |
('xsign', 'identified'), |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
328 |
('release', 'xsigning'), |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
329 |
('xabort', 'identified') |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
330 |
): |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
331 |
group.fire_transition(trans) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
332 |
self.commit() |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
333 |
group.clear_all_caches() |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
334 |
self.assertEquals(group.state, nextstate) |
440931181322
[wf engine] support for subwf exit point with no destination state: go back to state from which we entered into the subworkflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3617
diff
changeset
|
335 |
|
2954
48507919b6e3
[wf] oops, BaseTransition.__init__ may be called for subclasses
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2949
diff
changeset
|
336 |
|
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
337 |
class CustomWorkflowTC(CubicWebTC): |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
338 |
|
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
339 |
def setup_database(self): |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
340 |
self.member = self.create_user('member') |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
341 |
|
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
342 |
def test_custom_wf_replace_state_no_history(self): |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
343 |
"""member in inital state with no previous history, state is simply |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
344 |
redirected when changing workflow |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
345 |
""" |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
346 |
wf = add_wf(self, 'CWUser') |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
347 |
wf.add_state('asleep', initial=True) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
348 |
self.execute('SET X custom_workflow WF WHERE X eid %(x)s, WF eid %(wf)s', |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
349 |
{'wf': wf.eid, 'x': self.member.eid}) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
350 |
self.member.clear_all_caches() |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
351 |
self.assertEquals(self.member.state, 'activated')# no change before commit |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
352 |
self.commit() |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
353 |
self.member.clear_all_caches() |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
354 |
self.assertEquals(self.member.current_workflow.eid, wf.eid) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
355 |
self.assertEquals(self.member.state, 'asleep') |
3587 | 356 |
self.assertEquals(self.member.workflow_history, ()) |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
357 |
|
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
358 |
def test_custom_wf_replace_state_keep_history(self): |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
359 |
"""member in inital state with some history, state is redirected and |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
360 |
state change is recorded to history |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
361 |
""" |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
362 |
self.member.fire_transition('deactivate') |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
363 |
self.member.fire_transition('activate') |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
364 |
wf = add_wf(self, 'CWUser') |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
365 |
wf.add_state('asleep', initial=True) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
366 |
self.execute('SET X custom_workflow WF WHERE X eid %(x)s, WF eid %(wf)s', |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
367 |
{'wf': wf.eid, 'x': self.member.eid}) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
368 |
self.commit() |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
369 |
self.member.clear_all_caches() |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
370 |
self.assertEquals(self.member.current_workflow.eid, wf.eid) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
371 |
self.assertEquals(self.member.state, 'asleep') |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
372 |
self.assertEquals(parse_hist(self.member.workflow_history), |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
373 |
[('activated', 'deactivated', 'deactivate', None), |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
374 |
('deactivated', 'activated', 'activate', None), |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
375 |
('activated', 'asleep', None, 'workflow changed to "CWUser"')]) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
376 |
|
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
377 |
def test_custom_wf_no_initial_state(self): |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
378 |
"""try to set a custom workflow which has no initial state""" |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
379 |
self.member.fire_transition('deactivate') |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
380 |
wf = add_wf(self, 'CWUser') |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
381 |
wf.add_state('asleep') |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
382 |
self.execute('SET X custom_workflow WF WHERE X eid %(x)s, WF eid %(wf)s', |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
383 |
{'wf': wf.eid, 'x': self.member.eid}) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
384 |
ex = self.assertRaises(ValidationError, self.commit) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
385 |
self.assertEquals(ex.errors, {'custom_workflow': u'workflow has no initial state'}) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
386 |
|
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
387 |
def test_custom_wf_bad_etype(self): |
2985 | 388 |
"""try to set a custom workflow which doesn't apply to entity type""" |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
389 |
wf = add_wf(self, 'Company') |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
390 |
wf.add_state('asleep', initial=True) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
391 |
self.execute('SET X custom_workflow WF WHERE X eid %(x)s, WF eid %(wf)s', |
4028
062beb946b7c
missing cache key
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4024
diff
changeset
|
392 |
{'wf': wf.eid, 'x': self.member.eid}, 'x') |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
393 |
ex = self.assertRaises(ValidationError, self.commit) |
3983
e2dc12753436
nicer error message on rql constraints
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3966
diff
changeset
|
394 |
self.assertEquals(ex.errors, {'custom_workflow': 'workflow isn\'t a workflow for this type'}) |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
395 |
|
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
396 |
def test_del_custom_wf(self): |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
397 |
"""member in some state shared by the new workflow, nothing has to be |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
398 |
done |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
399 |
""" |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
400 |
self.member.fire_transition('deactivate') |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
401 |
wf = add_wf(self, 'CWUser') |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
402 |
wf.add_state('asleep', initial=True) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
403 |
self.execute('SET X custom_workflow WF WHERE X eid %(x)s, WF eid %(wf)s', |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
404 |
{'wf': wf.eid, 'x': self.member.eid}) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
405 |
self.commit() |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
406 |
self.execute('DELETE X custom_workflow WF WHERE X eid %(x)s, WF eid %(wf)s', |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
407 |
{'wf': wf.eid, 'x': self.member.eid}) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
408 |
self.member.clear_all_caches() |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
409 |
self.assertEquals(self.member.state, 'asleep')# no change before commit |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
410 |
self.commit() |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
411 |
self.member.clear_all_caches() |
3206
5a51ac97f1d3
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2992
diff
changeset
|
412 |
self.assertEquals(self.member.current_workflow.name, "default user workflow") |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
413 |
self.assertEquals(self.member.state, 'activated') |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
414 |
self.assertEquals(parse_hist(self.member.workflow_history), |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
415 |
[('activated', 'deactivated', 'deactivate', None), |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
416 |
('deactivated', 'asleep', None, 'workflow changed to "CWUser"'), |
3206
5a51ac97f1d3
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2992
diff
changeset
|
417 |
('asleep', 'activated', None, 'workflow changed to "default user workflow"'),]) |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
418 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
419 |
|
3536 | 420 |
class AutoTransitionTC(CubicWebTC): |
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
421 |
|
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
422 |
def setup_database(self): |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
423 |
self.wf = add_wf(self, 'CWUser') |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
424 |
asleep = self.wf.add_state('asleep', initial=True) |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
425 |
dead = self.wf.add_state('dead') |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
426 |
self.wf.add_transition('rest', asleep, asleep) |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
427 |
self.wf.add_transition('sick', asleep, dead, type=u'auto', |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
428 |
conditions=({'expr': u'U surname "toto"', |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
429 |
'mainvars': u'U'},)) |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
430 |
|
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
431 |
def test_auto_transition_fired(self): |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
432 |
user = self.create_user('member') |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
433 |
self.execute('SET X custom_workflow WF WHERE X eid %(x)s, WF eid %(wf)s', |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
434 |
{'wf': self.wf.eid, 'x': user.eid}) |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
435 |
self.commit() |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
436 |
user.clear_all_caches() |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
437 |
self.assertEquals(user.state, 'asleep') |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
438 |
self.assertEquals([t.name for t in user.possible_transitions()], |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
439 |
['rest']) |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
440 |
user.fire_transition('rest') |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
441 |
self.commit() |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
442 |
user.clear_all_caches() |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
443 |
self.assertEquals(user.state, 'asleep') |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
444 |
self.assertEquals([t.name for t in user.possible_transitions()], |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
445 |
['rest']) |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
446 |
self.assertEquals(parse_hist(user.workflow_history), |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
447 |
[('asleep', 'asleep', 'rest', None)]) |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
448 |
self.request().user.set_attributes(surname=u'toto') # fulfill condition |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
449 |
self.commit() |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
450 |
user.fire_transition('rest') |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
451 |
self.commit() |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
452 |
user.clear_all_caches() |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
453 |
self.assertEquals(user.state, 'dead') |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
454 |
self.assertEquals(parse_hist(user.workflow_history), |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
455 |
[('asleep', 'asleep', 'rest', None), |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
456 |
('asleep', 'asleep', 'rest', None), |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
457 |
('asleep', 'dead', 'sick', None),]) |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
458 |
|
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
459 |
|
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
460 |
class WorkflowHooksTC(CubicWebTC): |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
461 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
462 |
def setUp(self): |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
463 |
CubicWebTC.setUp(self) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
464 |
self.wf = self.session.user.current_workflow |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
465 |
self.session.set_pool() |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
466 |
self.s_activated = self.wf.state_by_name('activated').eid |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
467 |
self.s_deactivated = self.wf.state_by_name('deactivated').eid |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
468 |
self.s_dummy = self.wf.add_state(u'dummy').eid |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
469 |
self.wf.add_transition(u'dummy', (self.s_deactivated,), self.s_dummy) |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
470 |
ueid = self.create_user('stduser', commit=False).eid |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
471 |
# test initial state is set |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
472 |
rset = self.execute('Any N WHERE S name N, X in_state S, X eid %(x)s', |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
473 |
{'x' : ueid}) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
474 |
self.failIf(rset, rset.rows) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
475 |
self.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
476 |
initialstate = self.execute('Any N WHERE S name N, X in_state S, X eid %(x)s', |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
477 |
{'x' : ueid})[0][0] |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
478 |
self.assertEquals(initialstate, u'activated') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
479 |
# give access to users group on the user's wf transitions |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
480 |
# so we can test wf enforcing on euser (managers don't have anymore this |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
481 |
# enforcement |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
482 |
self.execute('SET X require_group G ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
483 |
'WHERE G name "users", X transition_of WF, WF eid %(wf)s', |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
484 |
{'wf': self.wf.eid}) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
485 |
self.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
486 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
487 |
# XXX currently, we've to rely on hooks to set initial state, or to use unsafe_execute |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
488 |
# def test_initial_state(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
489 |
# cnx = self.login('stduser') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
490 |
# cu = cnx.cursor() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
491 |
# self.assertRaises(ValidationError, cu.execute, |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
492 |
# 'INSERT CWUser X: X login "badaboum", X upassword %(pwd)s, ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
493 |
# 'X in_state S WHERE S name "deactivated"', {'pwd': 'oops'}) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
494 |
# cnx.close() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
495 |
# # though managers can do whatever he want |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
496 |
# self.execute('INSERT CWUser X: X login "badaboum", X upassword %(pwd)s, ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
497 |
# 'X in_state S, X in_group G WHERE S name "deactivated", G name "users"', {'pwd': 'oops'}) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
498 |
# self.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
499 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
500 |
# test that the workflow is correctly enforced |
3879 | 501 |
|
502 |
def _cleanup_msg(self, msg): |
|
503 |
"""remove the variable part of one specific error message""" |
|
504 |
lmsg = msg.split() |
|
505 |
lmsg.pop(1) |
|
506 |
lmsg.pop() |
|
507 |
return ' '.join(lmsg) |
|
508 |
||
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
509 |
def test_transition_checking1(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
510 |
cnx = self.login('stduser') |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
511 |
user = cnx.user(self.session) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
512 |
ex = self.assertRaises(ValidationError, |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
513 |
user.fire_transition, 'activate') |
3879 | 514 |
self.assertEquals(self._cleanup_msg(ex.errors['by_transition']), |
515 |
u"transition isn't allowed from") |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
516 |
cnx.close() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
517 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
518 |
def test_transition_checking2(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
519 |
cnx = self.login('stduser') |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
520 |
user = cnx.user(self.session) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
521 |
ex = self.assertRaises(ValidationError, |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
522 |
user.fire_transition, 'dummy') |
3879 | 523 |
self.assertEquals(self._cleanup_msg(ex.errors['by_transition']), |
524 |
u"transition isn't allowed from") |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
525 |
cnx.close() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
526 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
527 |
def test_transition_checking3(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
528 |
cnx = self.login('stduser') |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
529 |
session = self.session |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
530 |
user = cnx.user(session) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
531 |
user.fire_transition('deactivate') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
532 |
cnx.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
533 |
session.set_pool() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
534 |
ex = self.assertRaises(ValidationError, |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
535 |
user.fire_transition, 'deactivate') |
3879 | 536 |
self.assertEquals(self._cleanup_msg(ex.errors['by_transition']), |
537 |
u"transition isn't allowed from") |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
538 |
# get back now |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
539 |
user.fire_transition('activate') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
540 |
cnx.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
541 |
cnx.close() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
542 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
543 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
544 |
if __name__ == '__main__': |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
545 |
from logilab.common.testlib import unittest_main |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
546 |
unittest_main() |