entities/test/unittest_wfobjs.py
branchstable
changeset 3528 77a69de16709
parent 3206 5a51ac97f1d3
child 3536 f6c9a5df80fb
child 3587 5b3725f315fc
--- a/entities/test/unittest_wfobjs.py	Wed Sep 30 16:06:04 2009 +0200
+++ b/entities/test/unittest_wfobjs.py	Wed Sep 30 16:06:52 2009 +0200
@@ -343,6 +343,47 @@
                            ('asleep', 'activated', None, 'workflow changed to "default user workflow"'),])
 
 
+
+class AutoTransitionTC(EnvBasedTC):
+
+    def setup_database(self):
+        self.wf = add_wf(self, 'CWUser')
+        asleep = self.wf.add_state('asleep', initial=True)
+        dead = self.wf.add_state('dead')
+        self.wf.add_transition('rest', asleep, asleep)
+        self.wf.add_transition('sick', asleep, dead, type=u'auto',
+                               conditions=({'expr': u'U surname "toto"',
+                                            'mainvars': u'U'},))
+
+    def test_auto_transition_fired(self):
+        user = self.create_user('member')
+        self.execute('SET X custom_workflow WF WHERE X eid %(x)s, WF eid %(wf)s',
+                     {'wf': self.wf.eid, 'x': user.eid})
+        self.commit()
+        user.clear_all_caches()
+        self.assertEquals(user.state, 'asleep')
+        self.assertEquals([t.name for t in user.possible_transitions()],
+                          ['rest'])
+        user.fire_transition('rest')
+        self.commit()
+        user.clear_all_caches()
+        self.assertEquals(user.state, 'asleep')
+        self.assertEquals([t.name for t in user.possible_transitions()],
+                          ['rest'])
+        self.assertEquals(parse_hist(user.workflow_history),
+                          [('asleep', 'asleep', 'rest', None)])
+        self.request().user.set_attributes(surname=u'toto') # fulfill condition
+        self.commit()
+        user.fire_transition('rest')
+        self.commit()
+        user.clear_all_caches()
+        self.assertEquals(user.state, 'dead')
+        self.assertEquals(parse_hist(user.workflow_history),
+                          [('asleep', 'asleep', 'rest', None),
+                           ('asleep', 'asleep', 'rest', None),
+                           ('asleep', 'dead', 'sick', None),])
+
+
 from cubicweb.devtools.apptest import RepositoryBasedTC
 
 class WorkflowHooksTC(RepositoryBasedTC):