Commits

Ian George  committed a6e3840

Added tests for new control flow

  • Participants
  • Parent commits 99da764

Comments (0)

Files changed (2)

File statemachine/fsm.py

         except FSM_CancelTransition:
             return self.state
         except FSM_RedirectTransition as e:
-            return self.change(e.state, *args, **kwargs):
+            return self.change(e.state, *args, **kwargs)
 
         # safe to change the state if we get this far
         self.__state = new_state

File statemachine/tests.py

 
 from statemachine.models import StateMachineWithHistory
 from statemachine.fields import FSM_StateField
-from statemachine import fsm
+from statemachine import fsm  
+
 
 
 class TestMachine(fsm.FSM):
 
         self.assertEqual(testmachine.field1, 10)
         self.assertEqual(testmachine.field2, "Chickens")
+
+    def test_cancel_action(self):
+        def cancel_change(from_state):
+            if from_state == "step1c":
+                raise fsm.CancelTransition("Didn't want to continue")
+
+        def redirect_change(from_state):
+            if from_state == "step1c":
+                raise fsm.RedirectTransition("end")
+
+        testmachine = TestStateMachine(field1=100, field2="LALALALA")
+        testmachine.save(None)
+        testmachine.status.states["step2"].entry_action = cancel_change
+        testmachine.status.change("step1c")
+        testmachine.status.change("step2")
+
+        self.assertEqual(testmachine.status.state.name, "step2")