1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
124 self.assertEqual(len(trs), 1) |
124 self.assertEqual(len(trs), 1) |
125 self.assertEqual(trs[0].name, u'deactivate') |
125 self.assertEqual(trs[0].name, u'deactivate') |
126 self.assertEqual(trs[0].destination(None).name, u'deactivated') |
126 self.assertEqual(trs[0].destination(None).name, u'deactivated') |
127 # test a std user get no possible transition |
127 # test a std user get no possible transition |
128 cnx = self.login('member') |
128 cnx = self.login('member') |
|
129 req = self.request() |
129 # fetch the entity using the new session |
130 # fetch the entity using the new session |
130 trs = list(cnx.user().cw_adapt_to('IWorkflowable').possible_transitions()) |
131 trs = list(req.user.cw_adapt_to('IWorkflowable').possible_transitions()) |
131 self.assertEqual(len(trs), 0) |
132 self.assertEqual(len(trs), 0) |
132 cnx.close() |
133 cnx.close() |
133 |
134 |
134 def _test_manager_deactivate(self, user): |
135 def _test_manager_deactivate(self, user): |
135 iworkflowable = user.cw_adapt_to('IWorkflowable') |
136 iworkflowable = user.cw_adapt_to('IWorkflowable') |
171 trinfo = self._test_manager_deactivate(user) |
172 trinfo = self._test_manager_deactivate(user) |
172 self.assertEqual(trinfo.transition.name, 'deactivate') |
173 self.assertEqual(trinfo.transition.name, 'deactivate') |
173 |
174 |
174 def test_goback_transition(self): |
175 def test_goback_transition(self): |
175 req = self.request() |
176 req = self.request() |
176 wf = self.session.user.cw_adapt_to('IWorkflowable').current_workflow |
177 wf = req.user.cw_adapt_to('IWorkflowable').current_workflow |
177 asleep = wf.add_state('asleep') |
178 asleep = wf.add_state('asleep') |
178 wf.add_transition('rest', (wf.state_by_name('activated'), |
179 wf.add_transition('rest', (wf.state_by_name('activated'), |
179 wf.state_by_name('deactivated')), |
180 wf.state_by_name('deactivated')), |
180 asleep) |
181 asleep) |
181 wf.add_transition('wake up', asleep) |
182 wf.add_transition('wake up', asleep) |
210 cnx.close() |
211 cnx.close() |
211 cnx = self.login('member') |
212 cnx = self.login('member') |
212 req = self.request() |
213 req = self.request() |
213 iworkflowable = req.entity_from_eid(self.member.eid).cw_adapt_to('IWorkflowable') |
214 iworkflowable = req.entity_from_eid(self.member.eid).cw_adapt_to('IWorkflowable') |
214 iworkflowable.fire_transition('deactivate') |
215 iworkflowable.fire_transition('deactivate') |
215 cnx.commit() |
216 req.cu.commit() |
216 with self.assertRaises(ValidationError) as cm: |
217 with self.assertRaises(ValidationError) as cm: |
217 iworkflowable.fire_transition('activate') |
218 iworkflowable.fire_transition('activate') |
218 self.assertEqual(cm.exception.errors, {'by_transition-subject': "transition may not be fired"}) |
219 self.assertEqual(cm.exception.errors, {'by_transition-subject': "transition may not be fired"}) |
219 cnx.close() |
220 cnx.close() |
220 |
221 |
554 |
555 |
555 class WorkflowHooksTC(CubicWebTC): |
556 class WorkflowHooksTC(CubicWebTC): |
556 |
557 |
557 def setUp(self): |
558 def setUp(self): |
558 CubicWebTC.setUp(self) |
559 CubicWebTC.setUp(self) |
559 self.wf = self.session.user.cw_adapt_to('IWorkflowable').current_workflow |
560 req = self.request() |
560 self.session.set_cnxset() |
561 self.wf = req.user.cw_adapt_to('IWorkflowable').current_workflow |
561 self.s_activated = self.wf.state_by_name('activated').eid |
562 self.s_activated = self.wf.state_by_name('activated').eid |
562 self.s_deactivated = self.wf.state_by_name('deactivated').eid |
563 self.s_deactivated = self.wf.state_by_name('deactivated').eid |
563 self.s_dummy = self.wf.add_state(u'dummy').eid |
564 self.s_dummy = self.wf.add_state(u'dummy').eid |
564 self.wf.add_transition(u'dummy', (self.s_deactivated,), self.s_dummy) |
565 self.wf.add_transition(u'dummy', (self.s_deactivated,), self.s_dummy) |
565 req = self.request() |
|
566 ueid = self.create_user(req, 'stduser', commit=False).eid |
566 ueid = self.create_user(req, 'stduser', commit=False).eid |
567 # test initial state is set |
567 # test initial state is set |
568 rset = self.execute('Any N WHERE S name N, X in_state S, X eid %(x)s', |
568 rset = self.execute('Any N WHERE S name N, X in_state S, X eid %(x)s', |
569 {'x' : ueid}) |
569 {'x' : ueid}) |
570 self.assertFalse(rset, rset.rows) |
570 self.assertFalse(rset, rset.rows) |