author | Julien Cristau <julien.cristau@logilab.fr> |
Fri, 04 Apr 2014 10:46:53 +0200 | |
changeset 9604 | eba0e1b033ab |
parent 9582 | 46ed25d38fe2 |
child 9752 | 5df3ac51a91a |
permissions | -rw-r--r-- |
8559
8db29e17dd33
[workflow test] don't use session.user, subject to internal changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
1 |
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5056
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5056
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5056
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5056
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5056
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5056
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5056
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5056
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5056
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5056
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5056
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5056
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5056
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5056
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5056
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
18 |
|
6868
2d40f3c48f31
[tests] use migration api to create workflow
Julien Jehannet <julien@smaf.org>
parents:
6796
diff
changeset
|
19 |
from cubicweb import ValidationError |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
20 |
from cubicweb.devtools.testlib import CubicWebTC |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
21 |
|
6868
2d40f3c48f31
[tests] use migration api to create workflow
Julien Jehannet <julien@smaf.org>
parents:
6796
diff
changeset
|
22 |
|
2992
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
23 |
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
|
24 |
if name is None: |
2992
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
25 |
name = etype |
6868
2d40f3c48f31
[tests] use migration api to create workflow
Julien Jehannet <julien@smaf.org>
parents:
6796
diff
changeset
|
26 |
return self.shell().add_workflow(name, etype, default=default, |
2d40f3c48f31
[tests] use migration api to create workflow
Julien Jehannet <julien@smaf.org>
parents:
6796
diff
changeset
|
27 |
ensure_workflowable=False) |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
28 |
|
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
29 |
def parse_hist(wfhist): |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
30 |
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
|
31 |
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
|
32 |
for ti in wfhist] |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
33 |
|
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
34 |
|
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
35 |
class WorkflowBuildingTC(CubicWebTC): |
2939
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
36 |
|
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
37 |
def test_wf_construction(self): |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
38 |
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
|
39 |
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
|
40 |
bar = wf.add_state(u'bar') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
41 |
self.assertEqual(wf.state_by_name('bar').eid, bar.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
42 |
self.assertEqual(wf.state_by_name('barrr'), None) |
2939
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
43 |
baz = wf.add_transition(u'baz', (foo,), bar, ('managers',)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
44 |
self.assertEqual(wf.transition_by_name('baz').eid, baz.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
45 |
self.assertEqual(len(baz.require_group), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
46 |
self.assertEqual(baz.require_group[0].name, 'managers') |
2939
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
47 |
|
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
48 |
def test_duplicated_state(self): |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
49 |
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
|
50 |
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
|
51 |
self.commit() |
2939
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
52 |
wf.add_state(u'foo') |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
53 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
54 |
self.commit() |
8659
cd9fddc21361
[entities] fix test failures introduced by fixes in workflow related message strings (completes 9bb93efa1952)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7791
diff
changeset
|
55 |
self.assertEqual({'name-subject': 'workflow already has a state of that name'}, |
cd9fddc21361
[entities] fix test failures introduced by fixes in workflow related message strings (completes 9bb93efa1952)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7791
diff
changeset
|
56 |
cm.exception.errors) |
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
|
57 |
# 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
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
# 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
|
62 |
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
|
63 |
self.commit() |
8483
4ba11607d84a
[entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
64 |
bar.cw_set(name=u'foo') |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
65 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
66 |
self.commit() |
8659
cd9fddc21361
[entities] fix test failures introduced by fixes in workflow related message strings (completes 9bb93efa1952)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7791
diff
changeset
|
67 |
self.assertEqual({'name-subject': 'workflow already has a state of that name'}, |
cd9fddc21361
[entities] fix test failures introduced by fixes in workflow related message strings (completes 9bb93efa1952)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
7791
diff
changeset
|
68 |
cm.exception.errors) |
2939
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
69 |
|
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
70 |
def test_duplicated_transition(self): |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
71 |
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
|
72 |
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
|
73 |
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
|
74 |
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
|
75 |
wf.add_transition(u'baz', (bar,), foo) |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
76 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
77 |
self.commit() |
9242
564bdd4dbf8f
fix typos in workflow constraint error messages
David Douard <david.douard@logilab.fr>
parents:
8696
diff
changeset
|
78 |
self.assertEqual(cm.exception.errors, {'name-subject': 'workflow already has a transition of that name'}) |
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
|
79 |
# 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
|
80 |
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
|
81 |
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
|
82 |
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
|
83 |
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
|
84 |
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
|
85 |
# 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
|
86 |
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
|
87 |
self.commit() |
8483
4ba11607d84a
[entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
88 |
biz.cw_set(name=u'baz') |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
89 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
90 |
self.commit() |
9242
564bdd4dbf8f
fix typos in workflow constraint error messages
David Douard <david.douard@logilab.fr>
parents:
8696
diff
changeset
|
91 |
self.assertEqual(cm.exception.errors, {'name-subject': 'workflow already has 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
|
92 |
|
a613cc003ab7
make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
93 |
|
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
94 |
class WorkflowTC(CubicWebTC): |
2920
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 setup_database(self): |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7072
diff
changeset
|
97 |
req = self.request() |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
98 |
rschema = self.schema['in_state'] |
8696
0bb18407c053
[toward py3k] rewrite dict.keys() and dict.values() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8694
diff
changeset
|
99 |
for rdef in rschema.rdefs.itervalues(): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
100 |
self.assertEqual(rdef.cardinality, '1*') |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7072
diff
changeset
|
101 |
self.member = self.create_user(req, 'member') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
102 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
103 |
def test_workflow_base(self): |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7072
diff
changeset
|
104 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7072
diff
changeset
|
105 |
e = self.create_user(req, 'toto') |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
106 |
iworkflowable = e.cw_adapt_to('IWorkflowable') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
107 |
self.assertEqual(iworkflowable.state, 'activated') |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
108 |
iworkflowable.change_state('deactivated', u'deactivate 1') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
109 |
self.commit() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
110 |
iworkflowable.change_state('activated', u'activate 1') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
111 |
self.commit() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
112 |
iworkflowable.change_state('deactivated', u'deactivate 2') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
113 |
self.commit() |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
114 |
e.cw_clear_relation_cache('wf_info_for', 'object') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
115 |
self.assertEqual([tr.comment for tr in e.reverse_wf_info_for], |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
116 |
['deactivate 1', 'activate 1', 'deactivate 2']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
117 |
self.assertEqual(iworkflowable.latest_trinfo().comment, 'deactivate 2') |
2920
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_possible_transitions(self): |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5056
diff
changeset
|
120 |
user = self.execute('CWUser X').get_entity(0, 0) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
121 |
iworkflowable = user.cw_adapt_to('IWorkflowable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
122 |
trs = list(iworkflowable.possible_transitions()) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
123 |
self.assertEqual(len(trs), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
124 |
self.assertEqual(trs[0].name, u'deactivate') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
125 |
self.assertEqual(trs[0].destination(None).name, u'deactivated') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
126 |
# test a std user get no possible transition |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
127 |
cnx = self.login('member') |
8559
8db29e17dd33
[workflow test] don't use session.user, subject to internal changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
128 |
req = self.request() |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
129 |
# fetch the entity using the new session |
8559
8db29e17dd33
[workflow test] don't use session.user, subject to internal changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
130 |
trs = list(req.user.cw_adapt_to('IWorkflowable').possible_transitions()) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
131 |
self.assertEqual(len(trs), 0) |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6868
diff
changeset
|
132 |
cnx.close() |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
133 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
134 |
def _test_manager_deactivate(self, user): |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
135 |
iworkflowable = user.cw_adapt_to('IWorkflowable') |
5557
1a534c596bff
[entity] continue cleanup of Entity/AnyEntity namespace
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
136 |
user.cw_clear_relation_cache('in_state', 'subject') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
137 |
self.assertEqual(len(user.in_state), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
138 |
self.assertEqual(iworkflowable.state, 'deactivated') |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
139 |
trinfo = iworkflowable.latest_trinfo() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
140 |
self.assertEqual(trinfo.previous_state.name, 'activated') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
141 |
self.assertEqual(trinfo.new_state.name, 'deactivated') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
142 |
self.assertEqual(trinfo.comment, 'deactivate user') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
143 |
self.assertEqual(trinfo.comment_format, 'text/plain') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
144 |
return trinfo |
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_change_state(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
147 |
user = self.user() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
148 |
iworkflowable = user.cw_adapt_to('IWorkflowable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
149 |
iworkflowable.change_state('deactivated', comment=u'deactivate user') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
150 |
trinfo = self._test_manager_deactivate(user) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
151 |
self.assertEqual(trinfo.transition, None) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
152 |
|
2983
b458631fe347
[wf] test in_state consistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2982
diff
changeset
|
153 |
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
|
154 |
wf = add_wf(self, 'CWUser') |
b458631fe347
[wf] test in_state consistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2982
diff
changeset
|
155 |
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
|
156 |
self.commit() |
8562
0d2fb4604265
[session] fix arguments default value and promote usage of security_enabled as session method. Closes #2481820
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8559
diff
changeset
|
157 |
with self.session.security_enabled(write=False): |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
158 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
159 |
self.session.execute('SET X in_state S WHERE X eid %(x)s, S eid %(s)s', |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
160 |
{'x': self.user().eid, 's': s.eid}) |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
161 |
self.assertEqual(cm.exception.errors, {'in_state-subject': "state doesn't belong to entity's workflow. " |
2983
b458631fe347
[wf] test in_state consistency
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2982
diff
changeset
|
162 |
"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
|
163 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
164 |
def test_fire_transition(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
165 |
user = self.user() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
166 |
iworkflowable = user.cw_adapt_to('IWorkflowable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
167 |
iworkflowable.fire_transition('deactivate', comment=u'deactivate user') |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
168 |
user.cw_clear_all_caches() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
169 |
self.assertEqual(iworkflowable.state, 'deactivated') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
170 |
self._test_manager_deactivate(user) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
171 |
trinfo = self._test_manager_deactivate(user) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
172 |
self.assertEqual(trinfo.transition.name, 'deactivate') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
173 |
|
4644
021035b9a7ab
introduce 'go back' transition: transition without destination state will go to the state we were coming from
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4030
diff
changeset
|
174 |
def test_goback_transition(self): |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7072
diff
changeset
|
175 |
req = self.request() |
8559
8db29e17dd33
[workflow test] don't use session.user, subject to internal changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
176 |
wf = req.user.cw_adapt_to('IWorkflowable').current_workflow |
4644
021035b9a7ab
introduce 'go back' transition: transition without destination state will go to the state we were coming from
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4030
diff
changeset
|
177 |
asleep = wf.add_state('asleep') |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
178 |
wf.add_transition('rest', (wf.state_by_name('activated'), |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
179 |
wf.state_by_name('deactivated')), |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
180 |
asleep) |
4644
021035b9a7ab
introduce 'go back' transition: transition without destination state will go to the state we were coming from
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4030
diff
changeset
|
181 |
wf.add_transition('wake up', asleep) |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7072
diff
changeset
|
182 |
user = self.create_user(req, 'stduser') |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
183 |
iworkflowable = user.cw_adapt_to('IWorkflowable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
184 |
iworkflowable.fire_transition('rest') |
4644
021035b9a7ab
introduce 'go back' transition: transition without destination state will go to the state we were coming from
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4030
diff
changeset
|
185 |
self.commit() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
186 |
iworkflowable.fire_transition('wake up') |
4644
021035b9a7ab
introduce 'go back' transition: transition without destination state will go to the state we were coming from
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4030
diff
changeset
|
187 |
self.commit() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
188 |
self.assertEqual(iworkflowable.state, 'activated') |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
189 |
iworkflowable.fire_transition('deactivate') |
4644
021035b9a7ab
introduce 'go back' transition: transition without destination state will go to the state we were coming from
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4030
diff
changeset
|
190 |
self.commit() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
191 |
iworkflowable.fire_transition('rest') |
4644
021035b9a7ab
introduce 'go back' transition: transition without destination state will go to the state we were coming from
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4030
diff
changeset
|
192 |
self.commit() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
193 |
iworkflowable.fire_transition('wake up') |
4644
021035b9a7ab
introduce 'go back' transition: transition without destination state will go to the state we were coming from
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4030
diff
changeset
|
194 |
self.commit() |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
195 |
user.cw_clear_all_caches() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
196 |
self.assertEqual(iworkflowable.state, 'deactivated') |
4644
021035b9a7ab
introduce 'go back' transition: transition without destination state will go to the state we were coming from
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4030
diff
changeset
|
197 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
198 |
# 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
|
199 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
200 |
def _test_stduser_deactivate(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
201 |
ueid = self.member.eid |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7072
diff
changeset
|
202 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7072
diff
changeset
|
203 |
self.create_user(req, 'tutu') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
204 |
cnx = self.login('tutu') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
205 |
req = self.request() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
206 |
iworkflowable = req.entity_from_eid(self.member.eid).cw_adapt_to('IWorkflowable') |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
207 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
208 |
iworkflowable.fire_transition('deactivate') |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
209 |
self.assertEqual(cm.exception.errors, {'by_transition-subject': "transition may not be fired"}) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
210 |
cnx.close() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
211 |
cnx = self.login('member') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
212 |
req = self.request() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
213 |
iworkflowable = req.entity_from_eid(self.member.eid).cw_adapt_to('IWorkflowable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
214 |
iworkflowable.fire_transition('deactivate') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
215 |
cnx.commit() |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
216 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
217 |
iworkflowable.fire_transition('activate') |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
218 |
self.assertEqual(cm.exception.errors, {'by_transition-subject': "transition may not be fired"}) |
7072
bcf96f2a4c5d
[test] properly close connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6868
diff
changeset
|
219 |
cnx.close() |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
220 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
221 |
def test_fire_transition_owned_by(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
222 |
self.execute('INSERT RQLExpression X: X exprtype "ERQLExpression", ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
223 |
'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
|
224 |
'WHERE T name "deactivate"') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
225 |
self._test_stduser_deactivate() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
226 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
227 |
def test_fire_transition_has_update_perm(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
228 |
self.execute('INSERT RQLExpression X: X exprtype "ERQLExpression", ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
229 |
'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
|
230 |
'WHERE T name "deactivate"') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
231 |
self._test_stduser_deactivate() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
232 |
|
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
|
233 |
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
|
234 |
"""subworkflow |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
235 |
|
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
236 |
+-----------+ tr1 +-----------+ |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
237 |
| swfstate1 | ------>| swfstate2 | |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
238 |
+-----------+ +-----------+ |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
239 |
| tr2 +-----------+ |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
240 |
`------>| swfstate3 | |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
241 |
+-----------+ |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
242 |
|
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
243 |
main workflow |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
244 |
|
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
245 |
+--------+ swftr1 +--------+ |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
246 |
| state1 | -------[swfstate2]->| state2 | |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
247 |
+--------+ | +--------+ |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
248 |
| +--------+ |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
249 |
`-[swfstate3]-->| state3 | |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
250 |
+--------+ |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
251 |
""" |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
252 |
# sub-workflow |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
253 |
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
|
254 |
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
|
255 |
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
|
256 |
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
|
257 |
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
|
258 |
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
|
259 |
# main workflow |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
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
|
264 |
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
|
265 |
[(swfstate2, state2), (swfstate3, state3)]) |
9582
46ed25d38fe2
Move entity cache from web.request.ConnectionCubicWebRequestBase to repoapi.ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents:
9242
diff
changeset
|
266 |
swf.cw_clear_all_caches() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
267 |
self.assertEqual(swftr1.destination(None).eid, swfstate1.eid) |
2992
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
268 |
# workflows built, begin test |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
269 |
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
|
270 |
self.commit() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
271 |
iworkflowable = group.cw_adapt_to('IWorkflowable') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
272 |
self.assertEqual(iworkflowable.current_state.eid, state1.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
273 |
self.assertEqual(iworkflowable.current_workflow.eid, mwf.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
274 |
self.assertEqual(iworkflowable.main_workflow.eid, mwf.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
275 |
self.assertEqual(iworkflowable.subworkflow_input_transition(), None) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
276 |
iworkflowable.fire_transition('swftr1', u'go') |
2992
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
277 |
self.commit() |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
278 |
group.cw_clear_all_caches() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
279 |
self.assertEqual(iworkflowable.current_state.eid, swfstate1.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
280 |
self.assertEqual(iworkflowable.current_workflow.eid, swf.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
281 |
self.assertEqual(iworkflowable.main_workflow.eid, mwf.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
282 |
self.assertEqual(iworkflowable.subworkflow_input_transition().eid, swftr1.eid) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
283 |
iworkflowable.fire_transition('tr1', u'go') |
2992
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
284 |
self.commit() |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
285 |
group.cw_clear_all_caches() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
286 |
self.assertEqual(iworkflowable.current_state.eid, state2.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
287 |
self.assertEqual(iworkflowable.current_workflow.eid, mwf.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
288 |
self.assertEqual(iworkflowable.main_workflow.eid, mwf.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
289 |
self.assertEqual(iworkflowable.subworkflow_input_transition(), None) |
2992
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
290 |
# 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
|
291 |
# subworkflow input transition |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
292 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
293 |
iworkflowable.change_state(swfstate1, u'gadget') |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
294 |
self.assertEqual(cm.exception.errors, {'to_state-subject': "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
|
295 |
self.rollback() |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
296 |
# force back to state1 |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
297 |
iworkflowable.change_state('state1', u'gadget') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
298 |
iworkflowable.fire_transition('swftr1', u'au') |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
299 |
group.cw_clear_all_caches() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
300 |
iworkflowable.fire_transition('tr2', u'chapeau') |
2992
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
301 |
self.commit() |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
302 |
group.cw_clear_all_caches() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
303 |
self.assertEqual(iworkflowable.current_state.eid, state3.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
304 |
self.assertEqual(iworkflowable.current_workflow.eid, mwf.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
305 |
self.assertEqual(iworkflowable.main_workflow.eid, mwf.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
306 |
self.assertListEqual(parse_hist(iworkflowable.workflow_history), |
2992
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
307 |
[('state1', 'swfstate1', 'swftr1', 'go'), |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
308 |
('swfstate1', 'swfstate2', 'tr1', 'go'), |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
309 |
('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
|
310 |
('state2', 'state1', None, 'gadget'), |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
311 |
('state1', 'swfstate1', 'swftr1', 'au'), |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
312 |
('swfstate1', 'swfstate3', 'tr2', 'chapeau'), |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
313 |
('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
|
314 |
]) |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
315 |
|
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
|
316 |
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
|
317 |
# sub-workflow |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
318 |
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
|
319 |
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
|
320 |
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
|
321 |
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
|
322 |
# main workflow |
a5b8bf107a1a
[wf] test and hooks for WorkflowTransition support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2985
diff
changeset
|
323 |
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
|
324 |
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
|
325 |
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
|
326 |
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
|
327 |
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
|
328 |
[(swfstate2, state2), (swfstate2, state3)]) |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
329 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
330 |
self.commit() |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
331 |
self.assertEqual(cm.exception.errors, {'subworkflow_exit-subject': 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
|
332 |
|
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
|
333 |
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
|
334 |
# 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
|
335 |
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
|
336 |
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
|
337 |
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
|
338 |
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
|
339 |
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
|
340 |
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
|
341 |
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
|
342 |
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
|
343 |
# 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
|
344 |
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
|
345 |
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
|
346 |
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
|
347 |
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
|
348 |
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
|
349 |
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
|
350 |
[(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
|
351 |
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
|
352 |
[(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
|
353 |
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
|
354 |
[(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
|
355 |
self.commit() |
4024
6a14cff373c3
more api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
356 |
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
|
357 |
self.commit() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
358 |
iworkflowable = group.cw_adapt_to('IWorkflowable') |
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
|
359 |
for trans in ('identify', 'release', 'close'): |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
360 |
iworkflowable.fire_transition(trans) |
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
|
361 |
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
|
362 |
|
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
|
363 |
|
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
|
364 |
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
|
365 |
# 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
|
366 |
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
|
367 |
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
|
368 |
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
|
369 |
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
|
370 |
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
|
371 |
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
|
372 |
# 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
|
373 |
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
|
374 |
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
|
375 |
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
|
376 |
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
|
377 |
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
|
378 |
[(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
|
379 |
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
|
380 |
[(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
|
381 |
self.commit() |
4024
6a14cff373c3
more api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
382 |
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
|
383 |
self.commit() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
384 |
iworkflowable = group.cw_adapt_to('IWorkflowable') |
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
|
385 |
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
|
386 |
('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
|
387 |
('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
|
388 |
('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
|
389 |
('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
|
390 |
('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
|
391 |
): |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
392 |
iworkflowable.fire_transition(trans) |
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
|
393 |
self.commit() |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
394 |
group.cw_clear_all_caches() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
395 |
self.assertEqual(iworkflowable.state, nextstate) |
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
|
396 |
|
2954
48507919b6e3
[wf] oops, BaseTransition.__init__ may be called for subclasses
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2949
diff
changeset
|
397 |
|
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
398 |
class CustomWorkflowTC(CubicWebTC): |
2949
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 |
def setup_database(self): |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7072
diff
changeset
|
401 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7072
diff
changeset
|
402 |
self.member = self.create_user(req, 'member') |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
403 |
|
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
404 |
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
|
405 |
"""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
|
406 |
redirected when changing workflow |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
407 |
""" |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
408 |
wf = add_wf(self, 'CWUser') |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
409 |
wf.add_state('asleep', initial=True) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
410 |
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
|
411 |
{'wf': wf.eid, 'x': self.member.eid}) |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
412 |
self.member.cw_clear_all_caches() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
413 |
iworkflowable = self.member.cw_adapt_to('IWorkflowable') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
414 |
self.assertEqual(iworkflowable.state, 'activated')# no change before commit |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
415 |
self.commit() |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
416 |
self.member.cw_clear_all_caches() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
417 |
self.assertEqual(iworkflowable.current_workflow.eid, wf.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
418 |
self.assertEqual(iworkflowable.state, 'asleep') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
419 |
self.assertEqual(iworkflowable.workflow_history, ()) |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
420 |
|
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
421 |
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
|
422 |
"""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
|
423 |
state change is recorded to history |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
424 |
""" |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
425 |
iworkflowable = self.member.cw_adapt_to('IWorkflowable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
426 |
iworkflowable.fire_transition('deactivate') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
427 |
iworkflowable.fire_transition('activate') |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
428 |
wf = add_wf(self, 'CWUser') |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
429 |
wf.add_state('asleep', initial=True) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
430 |
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
|
431 |
{'wf': wf.eid, 'x': self.member.eid}) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
432 |
self.commit() |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
433 |
self.member.cw_clear_all_caches() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
434 |
self.assertEqual(iworkflowable.current_workflow.eid, wf.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
435 |
self.assertEqual(iworkflowable.state, 'asleep') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
436 |
self.assertEqual(parse_hist(iworkflowable.workflow_history), |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
437 |
[('activated', 'deactivated', 'deactivate', None), |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
438 |
('deactivated', 'activated', 'activate', None), |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
439 |
('activated', 'asleep', None, 'workflow changed to "CWUser"')]) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
440 |
|
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
441 |
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
|
442 |
"""try to set a custom workflow which has no initial state""" |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
443 |
iworkflowable = self.member.cw_adapt_to('IWorkflowable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
444 |
iworkflowable.fire_transition('deactivate') |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
445 |
wf = add_wf(self, 'CWUser') |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
446 |
wf.add_state('asleep') |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
447 |
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
|
448 |
{'wf': wf.eid, 'x': self.member.eid}) |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
449 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
450 |
self.commit() |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
451 |
self.assertEqual(cm.exception.errors, {'custom_workflow-subject': u'workflow has no initial state'}) |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
452 |
|
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
453 |
def test_custom_wf_bad_etype(self): |
2985 | 454 |
"""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
|
455 |
wf = add_wf(self, 'Company') |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
456 |
wf.add_state('asleep', initial=True) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
457 |
self.execute('SET X custom_workflow WF WHERE X eid %(x)s, WF eid %(wf)s', |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5056
diff
changeset
|
458 |
{'wf': wf.eid, 'x': self.member.eid}) |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
459 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
460 |
self.commit() |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
461 |
self.assertEqual(cm.exception.errors, {'custom_workflow-subject': u"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
|
462 |
|
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
463 |
def test_del_custom_wf(self): |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
464 |
"""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
|
465 |
done |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
466 |
""" |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
467 |
iworkflowable = self.member.cw_adapt_to('IWorkflowable') |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
468 |
iworkflowable.fire_transition('deactivate') |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
469 |
wf = add_wf(self, 'CWUser') |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
470 |
wf.add_state('asleep', initial=True) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
471 |
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
|
472 |
{'wf': wf.eid, 'x': self.member.eid}) |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
473 |
self.commit() |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
474 |
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
|
475 |
{'wf': wf.eid, 'x': self.member.eid}) |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
476 |
self.member.cw_clear_all_caches() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
477 |
self.assertEqual(iworkflowable.state, 'asleep')# no change before commit |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
478 |
self.commit() |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
479 |
self.member.cw_clear_all_caches() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
480 |
self.assertEqual(iworkflowable.current_workflow.name, "default user workflow") |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
481 |
self.assertEqual(iworkflowable.state, 'activated') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
482 |
self.assertEqual(parse_hist(iworkflowable.workflow_history), |
2949
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
483 |
[('activated', 'deactivated', 'deactivate', None), |
a2aa2c51f3be
test and implements workflow changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2939
diff
changeset
|
484 |
('deactivated', 'asleep', None, 'workflow changed to "CWUser"'), |
3206
5a51ac97f1d3
tests update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2992
diff
changeset
|
485 |
('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
|
486 |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
487 |
|
3536 | 488 |
class AutoTransitionTC(CubicWebTC): |
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
489 |
|
5056
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
490 |
def setup_custom_wf(self): |
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
491 |
wf = add_wf(self, 'CWUser') |
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
492 |
asleep = wf.add_state('asleep', initial=True) |
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
493 |
dead = wf.add_state('dead') |
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
494 |
wf.add_transition('rest', asleep, asleep) |
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
495 |
wf.add_transition('sick', asleep, dead, type=u'auto', |
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
496 |
conditions=({'expr': u'X surname "toto"', |
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
497 |
'mainvars': u'X'},)) |
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
498 |
return wf |
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
499 |
|
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
500 |
def test_auto_transition_fired(self): |
5056
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
501 |
wf = self.setup_custom_wf() |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7072
diff
changeset
|
502 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7072
diff
changeset
|
503 |
user = self.create_user(req, 'member') |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
504 |
iworkflowable = user.cw_adapt_to('IWorkflowable') |
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
505 |
self.execute('SET X custom_workflow WF WHERE X eid %(x)s, WF eid %(wf)s', |
5056
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
506 |
{'wf': wf.eid, 'x': user.eid}) |
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
507 |
self.commit() |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
508 |
user.cw_clear_all_caches() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
509 |
self.assertEqual(iworkflowable.state, 'asleep') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
510 |
self.assertEqual([t.name for t in iworkflowable.possible_transitions()], |
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
511 |
['rest']) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
512 |
iworkflowable.fire_transition('rest') |
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
513 |
self.commit() |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
514 |
user.cw_clear_all_caches() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
515 |
self.assertEqual(iworkflowable.state, 'asleep') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
516 |
self.assertEqual([t.name for t in iworkflowable.possible_transitions()], |
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
517 |
['rest']) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
518 |
self.assertEqual(parse_hist(iworkflowable.workflow_history), |
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
519 |
[('asleep', 'asleep', 'rest', None)]) |
8483
4ba11607d84a
[entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
520 |
user.cw_set(surname=u'toto') # fulfill condition |
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
521 |
self.commit() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
522 |
iworkflowable.fire_transition('rest') |
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
523 |
self.commit() |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
524 |
user.cw_clear_all_caches() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
525 |
self.assertEqual(iworkflowable.state, 'dead') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
526 |
self.assertEqual(parse_hist(iworkflowable.workflow_history), |
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
527 |
[('asleep', 'asleep', 'rest', None), |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
528 |
('asleep', 'asleep', 'rest', None), |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
529 |
('asleep', 'dead', 'sick', None),]) |
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
530 |
|
5056
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
531 |
def test_auto_transition_custom_initial_state_fired(self): |
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
532 |
wf = self.setup_custom_wf() |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7072
diff
changeset
|
533 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7072
diff
changeset
|
534 |
user = self.create_user(req, 'member', surname=u'toto') |
5056
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
535 |
self.execute('SET X custom_workflow WF WHERE X eid %(x)s, WF eid %(wf)s', |
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
536 |
{'wf': wf.eid, 'x': user.eid}) |
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
537 |
self.commit() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
538 |
iworkflowable = user.cw_adapt_to('IWorkflowable') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
539 |
self.assertEqual(iworkflowable.state, 'dead') |
5056
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
540 |
|
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
541 |
def test_auto_transition_initial_state_fired(self): |
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
542 |
wf = self.execute('Any WF WHERE ET default_workflow WF, ' |
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
543 |
'ET name %(et)s', {'et': 'CWUser'}).get_entity(0, 0) |
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
544 |
dead = wf.add_state('dead') |
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
545 |
wf.add_transition('sick', wf.state_by_name('activated'), dead, |
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
546 |
type=u'auto', conditions=({'expr': u'X surname "toto"', |
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
547 |
'mainvars': u'X'},)) |
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
548 |
self.commit() |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7072
diff
changeset
|
549 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7072
diff
changeset
|
550 |
user = self.create_user(req, 'member', surname=u'toto') |
5056
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
551 |
self.commit() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
552 |
iworkflowable = user.cw_adapt_to('IWorkflowable') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
553 |
self.assertEqual(iworkflowable.state, 'dead') |
5056
5de07c77d73f
[workflow] support for automatic transition starting from the initial state
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
554 |
|
3528
77a69de16709
support for automatic transition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3206
diff
changeset
|
555 |
|
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2954
diff
changeset
|
556 |
class WorkflowHooksTC(CubicWebTC): |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
557 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
558 |
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
|
559 |
CubicWebTC.setUp(self) |
8559
8db29e17dd33
[workflow test] don't use session.user, subject to internal changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
560 |
req = self.request() |
8db29e17dd33
[workflow test] don't use session.user, subject to internal changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
561 |
self.wf = req.user.cw_adapt_to('IWorkflowable').current_workflow |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
562 |
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
|
563 |
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
|
564 |
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
|
565 |
self.wf.add_transition(u'dummy', (self.s_deactivated,), self.s_dummy) |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7072
diff
changeset
|
566 |
ueid = self.create_user(req, 'stduser', commit=False).eid |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
567 |
# test initial state is set |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
568 |
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
|
569 |
{'x' : ueid}) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
570 |
self.assertFalse(rset, rset.rows) |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
571 |
self.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
572 |
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
|
573 |
{'x' : ueid})[0][0] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5557
diff
changeset
|
574 |
self.assertEqual(initialstate, u'activated') |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
575 |
# 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
|
576 |
# 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
|
577 |
# enforcement |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
578 |
self.execute('SET X require_group G ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
579 |
'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
|
580 |
{'wf': self.wf.eid}) |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
581 |
self.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
582 |
|
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4644
diff
changeset
|
583 |
# XXX currently, we've to rely on hooks to set initial state, or to use execute |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
584 |
# def test_initial_state(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
585 |
# cnx = self.login('stduser') |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
586 |
# cu = cnx.cursor() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
587 |
# self.assertRaises(ValidationError, cu.execute, |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
588 |
# '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
|
589 |
# '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
|
590 |
# cnx.close() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
591 |
# # though managers can do whatever he want |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
592 |
# 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
|
593 |
# '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
|
594 |
# self.commit() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
595 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
596 |
# test that the workflow is correctly enforced |
3879 | 597 |
|
598 |
def _cleanup_msg(self, msg): |
|
599 |
"""remove the variable part of one specific error message""" |
|
600 |
lmsg = msg.split() |
|
601 |
lmsg.pop(1) |
|
602 |
lmsg.pop() |
|
603 |
return ' '.join(lmsg) |
|
604 |
||
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
605 |
def test_transition_checking1(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
606 |
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
|
607 |
user = cnx.user(self.session) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
608 |
iworkflowable = user.cw_adapt_to('IWorkflowable') |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
609 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
610 |
iworkflowable.fire_transition('activate') |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
611 |
self.assertEqual(self._cleanup_msg(cm.exception.errors['by_transition-subject']), |
3879 | 612 |
u"transition isn't allowed from") |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
613 |
cnx.close() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
614 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
615 |
def test_transition_checking2(self): |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
616 |
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
|
617 |
user = cnx.user(self.session) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5538
diff
changeset
|
618 |
iworkflowable = user.cw_adapt_to('IWorkflowable') |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
619 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
620 |
iworkflowable.fire_transition('dummy') |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
621 |
self.assertEqual(self._cleanup_msg(cm.exception.errors['by_transition-subject']), |
3879 | 622 |
u"transition isn't allowed from") |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
623 |
cnx.close() |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
624 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
625 |
def test_transition_checking3(self): |
8577
3f082de68802
[test] use session commit/rollback to be consistent with the test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8562
diff
changeset
|
626 |
with self.login('stduser') as cnx: |
3f082de68802
[test] use session commit/rollback to be consistent with the test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8562
diff
changeset
|
627 |
session = self.session |
8646
82c7c2e0f69f
[wf/test] fix tests broken by changes from another patch which have slipped there
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8577
diff
changeset
|
628 |
user = self.user() |
8577
3f082de68802
[test] use session commit/rollback to be consistent with the test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8562
diff
changeset
|
629 |
iworkflowable = user.cw_adapt_to('IWorkflowable') |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6410
diff
changeset
|
630 |
iworkflowable.fire_transition('deactivate') |
8577
3f082de68802
[test] use session commit/rollback to be consistent with the test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8562
diff
changeset
|
631 |
session.commit() |
3f082de68802
[test] use session commit/rollback to be consistent with the test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8562
diff
changeset
|
632 |
session.set_cnxset() |
3f082de68802
[test] use session commit/rollback to be consistent with the test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8562
diff
changeset
|
633 |
with self.assertRaises(ValidationError) as cm: |
3f082de68802
[test] use session commit/rollback to be consistent with the test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8562
diff
changeset
|
634 |
iworkflowable.fire_transition('deactivate') |
3f082de68802
[test] use session commit/rollback to be consistent with the test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8562
diff
changeset
|
635 |
self.assertEqual(self._cleanup_msg(cm.exception.errors['by_transition-subject']), |
3f082de68802
[test] use session commit/rollback to be consistent with the test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8562
diff
changeset
|
636 |
u"transition isn't allowed from") |
3f082de68802
[test] use session commit/rollback to be consistent with the test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8562
diff
changeset
|
637 |
session.rollback() |
3f082de68802
[test] use session commit/rollback to be consistent with the test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8562
diff
changeset
|
638 |
session.set_cnxset() |
3f082de68802
[test] use session commit/rollback to be consistent with the test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8562
diff
changeset
|
639 |
# get back now |
3f082de68802
[test] use session commit/rollback to be consistent with the test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8562
diff
changeset
|
640 |
iworkflowable.fire_transition('activate') |
3f082de68802
[test] use session commit/rollback to be consistent with the test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8562
diff
changeset
|
641 |
session.commit() |
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
642 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
643 |
|
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
644 |
if __name__ == '__main__': |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
645 |
from logilab.common.testlib import unittest_main |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
646 |
unittest_main() |