94 self.assertEquals([tr.comment for tr in e.reverse_wf_info_for], |
94 self.assertEquals([tr.comment for tr in e.reverse_wf_info_for], |
95 ['deactivate 1', 'activate 1', 'deactivate 2']) |
95 ['deactivate 1', 'activate 1', 'deactivate 2']) |
96 self.assertEquals(e.latest_trinfo().comment, 'deactivate 2') |
96 self.assertEquals(e.latest_trinfo().comment, 'deactivate 2') |
97 |
97 |
98 def test_possible_transitions(self): |
98 def test_possible_transitions(self): |
99 user = self.entity('CWUser X') |
99 user = self.execute('CWUser X').get_entity(0, 0) |
100 trs = list(user.possible_transitions()) |
100 trs = list(user.possible_transitions()) |
101 self.assertEquals(len(trs), 1) |
101 self.assertEquals(len(trs), 1) |
102 self.assertEquals(trs[0].name, u'deactivate') |
102 self.assertEquals(trs[0].name, u'deactivate') |
103 self.assertEquals(trs[0].destination(None).name, u'deactivated') |
103 self.assertEquals(trs[0].destination(None).name, u'deactivated') |
104 # test a std user get no possible transition |
104 # test a std user get no possible transition |
129 s = wf.add_state(u'foo', initial=True) |
129 s = wf.add_state(u'foo', initial=True) |
130 self.commit() |
130 self.commit() |
131 with security_enabled(self.session, write=False): |
131 with security_enabled(self.session, write=False): |
132 ex = self.assertRaises(ValidationError, self.session.execute, |
132 ex = self.assertRaises(ValidationError, self.session.execute, |
133 'SET X in_state S WHERE X eid %(x)s, S eid %(s)s', |
133 'SET X in_state S WHERE X eid %(x)s, S eid %(s)s', |
134 {'x': self.user().eid, 's': s.eid}, 'x') |
134 {'x': self.user().eid, 's': s.eid}) |
135 self.assertEquals(ex.errors, {'in_state-subject': "state doesn't belong to entity's workflow. " |
135 self.assertEquals(ex.errors, {'in_state-subject': "state doesn't belong to entity's workflow. " |
136 "You may want to set a custom workflow for this entity first."}) |
136 "You may want to set a custom workflow for this entity first."}) |
137 |
137 |
138 def test_fire_transition(self): |
138 def test_fire_transition(self): |
139 user = self.user() |
139 user = self.user() |
411 def test_custom_wf_bad_etype(self): |
411 def test_custom_wf_bad_etype(self): |
412 """try to set a custom workflow which doesn't apply to entity type""" |
412 """try to set a custom workflow which doesn't apply to entity type""" |
413 wf = add_wf(self, 'Company') |
413 wf = add_wf(self, 'Company') |
414 wf.add_state('asleep', initial=True) |
414 wf.add_state('asleep', initial=True) |
415 self.execute('SET X custom_workflow WF WHERE X eid %(x)s, WF eid %(wf)s', |
415 self.execute('SET X custom_workflow WF WHERE X eid %(x)s, WF eid %(wf)s', |
416 {'wf': wf.eid, 'x': self.member.eid}, 'x') |
416 {'wf': wf.eid, 'x': self.member.eid}) |
417 ex = self.assertRaises(ValidationError, self.commit) |
417 ex = self.assertRaises(ValidationError, self.commit) |
418 self.assertEquals(ex.errors, {'custom_workflow-subject': 'workflow isn\'t a workflow for this type'}) |
418 self.assertEquals(ex.errors, {'custom_workflow-subject': 'workflow isn\'t a workflow for this type'}) |
419 |
419 |
420 def test_del_custom_wf(self): |
420 def test_del_custom_wf(self): |
421 """member in some state shared by the new workflow, nothing has to be |
421 """member in some state shared by the new workflow, nothing has to be |