entities/test/unittest_wfobjs.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 20 Aug 2009 19:03:24 +0200
branch3.5
changeset 2939 a613cc003ab7
parent 2920 64322aa83a1d
child 2949 a2aa2c51f3be
permissions -rw-r--r--
make state/transition name unique within a workflow
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     1
from cubicweb.devtools.apptest import EnvBasedTC
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
from cubicweb import ValidationError
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
2939
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
     4
class WorkflowBuildingTC(EnvBasedTC):
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
     5
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
     6
    def test_wf_construction(self):
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
     7
        wf = self.execute('INSERT Workflow X: X name "test"').get_entity(0, 0)
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
     8
        self.execute('SET WF workflow_of ET WHERE ET name "Company"')
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
     9
        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
    10
        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
    11
        self.assertEquals(wf.state_by_name('bar').eid, bar.eid)
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    12
        self.assertEquals(wf.state_by_name('barrr'), None)
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    13
        baz = wf.add_transition(u'baz', (foo,), bar, ('managers',))
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    14
        self.assertEquals(wf.transition_by_name('baz').eid, baz.eid)
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    15
        self.assertEquals(len(baz.require_group), 1)
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    16
        self.assertEquals(baz.require_group[0].name, 'managers')
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    17
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    18
    def test_duplicated_state(self):
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    19
        wf = self.execute('INSERT Workflow X: X name "test"').get_entity(0, 0)
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    20
        self.execute('SET WF workflow_of ET WHERE ET name "Company"')
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    21
        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
    22
        wf.add_state(u'foo')
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    23
        ex = self.assertRaises(ValidationError, self.commit)
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    24
        # XXX enhance message
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    25
        self.assertEquals(ex.errors, {'state_of': 'unique constraint S name N, Y state_of O, Y name N failed'})
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    26
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    27
    def test_duplicated_transition(self):
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    28
        wf = self.execute('INSERT Workflow X: X name "test"').get_entity(0, 0)
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    29
        self.execute('SET WF workflow_of ET WHERE ET name "Company"')
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    30
        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
    31
        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
    32
        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
    33
        wf.add_transition(u'baz', (bar,), foo)
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    34
        ex = self.assertRaises(ValidationError, self.commit)
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    35
        # XXX enhance message
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    36
        self.assertEquals(ex.errors, {'transition_of': 'unique constraint S name N, Y transition_of O, Y name N failed'})
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    37
a613cc003ab7 make state/transition name unique within a workflow
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2920
diff changeset
    38
2920
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    39
class WorkflowTC(EnvBasedTC):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    40
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    41
    def setup_database(self):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    42
        rschema = self.schema['in_state']
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    43
        for x, y in rschema.iter_rdefs():
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    44
            self.assertEquals(rschema.rproperty(x, y, 'cardinality'), '1*')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    45
        self.member = self.create_user('member')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    46
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    47
    def test_workflow_base(self):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    48
        e = self.create_user('toto')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    49
        self.assertEquals(e.state, 'activated')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    50
        e.change_state('deactivated', u'deactivate 1')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    51
        self.commit()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    52
        e.change_state('activated', u'activate 1')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    53
        self.commit()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    54
        e.change_state('deactivated', u'deactivate 2')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    55
        self.commit()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    56
        e.clear_related_cache('wf_info_for', 'object')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    57
        self.assertEquals([tr.comment for tr in e.reverse_wf_info_for],
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    58
                          ['deactivate 1', 'activate 1', 'deactivate 2'])
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    59
        self.assertEquals(e.latest_trinfo().comment, 'deactivate 2')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    60
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    61
    def test_possible_transitions(self):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    62
        user = self.entity('CWUser X')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    63
        trs = list(user.possible_transitions())
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    64
        self.assertEquals(len(trs), 1)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    65
        self.assertEquals(trs[0].name, u'deactivate')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    66
        self.assertEquals(trs[0].destination().name, u'deactivated')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    67
        # test a std user get no possible transition
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    68
        cnx = self.login('member')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    69
        # fetch the entity using the new session
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    70
        trs = list(cnx.user().possible_transitions())
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    71
        self.assertEquals(len(trs), 0)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    72
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    73
    def _test_manager_deactivate(self, user):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    74
        user.clear_related_cache('in_state', 'subject')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    75
        self.assertEquals(len(user.in_state), 1)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    76
        self.assertEquals(user.state, 'deactivated')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    77
        trinfo = user.latest_trinfo()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    78
        self.assertEquals(trinfo.previous_state.name, 'activated')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    79
        self.assertEquals(trinfo.new_state.name, 'deactivated')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    80
        self.assertEquals(trinfo.comment, 'deactivate user')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    81
        self.assertEquals(trinfo.comment_format, 'text/plain')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    82
        return trinfo
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    83
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    84
    def test_change_state(self):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    85
        user = self.user()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    86
        user.change_state('deactivated', comment=u'deactivate user')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    87
        trinfo = self._test_manager_deactivate(user)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    88
        self.assertEquals(trinfo.transition, None)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    89
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    90
    def test_fire_transition(self):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    91
        user = self.user()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    92
        user.fire_transition('deactivate', comment=u'deactivate user')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    93
        self.assertEquals(user.state, 'deactivated')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    94
        self._test_manager_deactivate(user)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    95
        trinfo = self._test_manager_deactivate(user)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    96
        self.assertEquals(trinfo.transition.name, 'deactivate')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    97
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    98
    # 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
    99
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   100
    def _test_stduser_deactivate(self):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   101
        ueid = self.member.eid
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   102
        self.create_user('tutu')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   103
        cnx = self.login('tutu')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   104
        req = self.request()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   105
        member = req.entity_from_eid(self.member.eid)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   106
        ex = self.assertRaises(ValidationError,
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   107
                               member.fire_transition, 'deactivate')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   108
        self.assertEquals(ex.errors, {'by_transition': "transition may not be fired"})
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   109
        cnx.close()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   110
        cnx = self.login('member')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   111
        req = self.request()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   112
        member = req.entity_from_eid(self.member.eid)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   113
        member.fire_transition('deactivate')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   114
        cnx.commit()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   115
        ex = self.assertRaises(ValidationError,
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   116
                               member.fire_transition, 'activate')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   117
        self.assertEquals(ex.errors, {'by_transition': "transition may not be fired"})
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   118
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   119
    def test_fire_transition_owned_by(self):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   120
        self.execute('INSERT RQLExpression X: X exprtype "ERQLExpression", '
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   121
                     '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
   122
                     'WHERE T name "deactivate"')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   123
        self._test_stduser_deactivate()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   124
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   125
    def test_fire_transition_has_update_perm(self):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   126
        self.execute('INSERT RQLExpression X: X exprtype "ERQLExpression", '
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   127
                     '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
   128
                     'WHERE T name "deactivate"')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   129
        self._test_stduser_deactivate()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   130
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   131
    def _init_wf_with_shared_state_or_tr(self):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   132
        req = self.request()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   133
        etypes = dict(self.execute('Any N, ET WHERE ET is CWEType, ET name N'
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   134
                                   ', ET name IN ("CWGroup", "Bookmark")'))
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   135
        self.grpwf = req.create_entity('Workflow', ('workflow_of', 'ET'),
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   136
                                       ET=etypes['CWGroup'], name=u'group workflow')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   137
        self.bmkwf = req.execute('Any X WHERE X is Workflow, X workflow_of ET, ET name "Bookmark"').get_entity(0, 0)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   138
        self.state1 = self.grpwf.add_state(u'state1', initial=True)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   139
        self.execute('SET S state_of WF WHERE S eid %(s)s, WF eid %(wf)s',
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   140
                     {'s': self.state1.eid, 'wf': self.bmkwf.eid})
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   141
        self.execute('SET WF initial_state S WHERE S eid %(s)s, WF eid %(wf)s',
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   142
                     {'s': self.state1.eid, 'wf': self.bmkwf.eid})
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   143
        self.state2 = self.grpwf.add_state(u'state2')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   144
        self.group = self.add_entity('CWGroup', name=u't1')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   145
        self.bookmark = self.add_entity('Bookmark', title=u'111', path=u'/view')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   146
        # commit to link to the initial state
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   147
        self.commit()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   148
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   149
    def test_transitions_selection(self):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   150
        """
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   151
        ------------------------  tr1    -----------------
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   152
        | state1 (CWGroup, Bookmark) | ------> | state2 (CWGroup) |
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   153
        ------------------------         -----------------
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   154
                  |  tr2    ------------------
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   155
                  `------>  | state3 (Bookmark) |
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   156
                            ------------------
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   157
        """
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   158
        self._init_wf_with_shared_state_or_tr()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   159
        state3 = self.bmkwf.add_state(u'state3')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   160
        tr1 = self.grpwf.add_transition(u'tr1', (self.state1,), self.state2)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   161
        tr2 = self.bmkwf.add_transition(u'tr2', (self.state1,), state3)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   162
        transitions = list(self.group.possible_transitions())
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   163
        self.assertEquals(len(transitions), 1)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   164
        self.assertEquals(transitions[0].name, 'tr1')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   165
        transitions = list(self.bookmark.possible_transitions())
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   166
        self.assertEquals(len(transitions), 1)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   167
        self.assertEquals(transitions[0].name, 'tr2')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   168
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   169
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   170
    def test_transitions_selection2(self):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   171
        """
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   172
        ------------------------  tr1 (Bookmark)   -----------------------
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   173
        | state1 (CWGroup, Bookmark) | -------------> | state2 (CWGroup,Bookmark) |
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   174
        ------------------------                -----------------------
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   175
                  |  tr2 (CWGroup)                     |
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   176
                  `---------------------------------/
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   177
        """
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   178
        self._init_wf_with_shared_state_or_tr()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   179
        self.execute('SET S state_of WF WHERE S eid %(s)s, WF eid %(wf)s',
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   180
                     {'s': self.state2.eid, 'wf': self.bmkwf.eid})
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   181
        tr1 = self.bmkwf.add_transition(u'tr1', (self.state1,), self.state2)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   182
        tr2 = self.grpwf.add_transition(u'tr2', (self.state1,), self.state2)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   183
        transitions = list(self.group.possible_transitions())
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   184
        self.assertEquals(len(transitions), 1)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   185
        self.assertEquals(transitions[0].name, 'tr2')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   186
        transitions = list(self.bookmark.possible_transitions())
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   187
        self.assertEquals(len(transitions), 1)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   188
        self.assertEquals(transitions[0].name, 'tr1')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   189
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   190
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   191
from cubicweb.devtools.apptest import RepositoryBasedTC
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   192
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   193
class WorkflowHooksTC(RepositoryBasedTC):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   194
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   195
    def setUp(self):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   196
        RepositoryBasedTC.setUp(self)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   197
        self.wf = self.session.user.current_workflow
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   198
        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
   199
        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
   200
        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
   201
        self.wf.add_transition(u'dummy', (self.s_deactivated,), self.s_dummy)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   202
        ueid = self.create_user('stduser', commit=False)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   203
        # test initial state is set
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   204
        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
   205
                            {'x' : ueid})
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   206
        self.failIf(rset, rset.rows)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   207
        self.commit()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   208
        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
   209
                                    {'x' : ueid})[0][0]
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   210
        self.assertEquals(initialstate, u'activated')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   211
        # 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
   212
        # 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
   213
        # enforcement
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   214
        self.execute('SET X require_group G '
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   215
                     '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
   216
                     {'wf': self.wf.eid})
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   217
        self.commit()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   218
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   219
    def tearDown(self):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   220
        self.execute('DELETE X require_group G '
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   221
                     '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
   222
                     {'wf': self.wf.eid})
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   223
        self.commit()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   224
        RepositoryBasedTC.tearDown(self)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   225
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   226
    # XXX currently, we've to rely on hooks to set initial state, or to use unsafe_execute
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   227
    # def test_initial_state(self):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   228
    #     cnx = self.login('stduser')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   229
    #     cu = cnx.cursor()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   230
    #     self.assertRaises(ValidationError, cu.execute,
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   231
    #                       '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
   232
    #                       '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
   233
    #     cnx.close()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   234
    #     # though managers can do whatever he want
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   235
    #     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
   236
    #                  '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
   237
    #     self.commit()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   238
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   239
    # test that the workflow is correctly enforced
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   240
    def test_transition_checking1(self):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   241
        cnx = self.login('stduser')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   242
        user = cnx.user(self.current_session())
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   243
        ex = self.assertRaises(ValidationError,
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   244
                               user.fire_transition, 'activate')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   245
        self.assertEquals(ex.errors, {'by_transition': u"transition isn't allowed"})
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   246
        cnx.close()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   247
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   248
    def test_transition_checking2(self):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   249
        cnx = self.login('stduser')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   250
        user = cnx.user(self.current_session())
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   251
        assert user.state == 'activated'
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   252
        ex = self.assertRaises(ValidationError,
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   253
                               user.fire_transition, 'dummy')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   254
        self.assertEquals(ex.errors, {'by_transition': u"transition isn't allowed"})
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   255
        cnx.close()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   256
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   257
    def test_transition_checking3(self):
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   258
        cnx = self.login('stduser')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   259
        session = self.current_session()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   260
        user = cnx.user(session)
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   261
        user.fire_transition('deactivate')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   262
        cnx.commit()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   263
        session.set_pool()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   264
        ex = self.assertRaises(ValidationError,
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   265
                               user.fire_transition, 'deactivate')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   266
        self.assertEquals(ex.errors, {'by_transition': u"transition isn't allowed"})
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   267
        # get back now
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   268
        user.fire_transition('activate')
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   269
        cnx.commit()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   270
        cnx.close()
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   271
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   272
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   273
if __name__ == '__main__':
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   274
    from logilab.common.testlib import unittest_main
64322aa83a1d start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   275
    unittest_main()