class TestFSM2(FSM): """Dumb class.""" initial_state = "state1" state1 = properties.State( events=[properties.Event("ChangeState", target_state="state2")]) state2 = properties.State( events=[properties.Event("ChangeState", target_state="state3")]) state3 = properties.FinalState()
class TestFSM(FSM): """Dumb class.""" initial_state = "new" new = properties.State(events=[properties.Event("state1", "state1")]) state1 = properties.State( timeout=properties.Timeout(timedelta(days=6), "timeout")) state2 = properties.State( timeout=properties.Timeout(timedelta(days=5), "timeout")) timeout = properties.FinalState()
class TestFSM(FSM): """Dumb class.""" initial_state = "state" state = properties.State( error=properties.Error("state_error", commands=[state_error_command]), events=[ properties.Event( "TriggerEventError", "non_reachable", error=properties.Error("event_error", commands=[event_error_command]), commands=[lambda x: False], ), properties.Event("TriggerStateError", "non_reachable", commands=[lambda x: False]), ], ) state_error = properties.FinalState() event_error = properties.FinalState() non_reachable = properties.FinalState()
class TestFSM(FSM): """Dumb class.""" initial_state = "new" new = properties.State(events=[properties.Event("state1", "state1")]) state1 = properties.State(timeout=properties.Timeout( timedelta(days=7), "timeout", commands=[command])) timeout = properties.FinalState() @property def current_state_date(self): """Database always send time zone aware dates but not in tests.""" return getattr(self.container_object, self.date_attribute).replace(tzinfo=pytz.UTC)
class TestFSM2(FSM): """Dumb class.""" state = properties.State(events=[ properties.Event("EventName", "final_state", error=properties.Error("invalid_state")) ]) final_state = properties.FinalState()
class TestFSM(FSM): """Dumb class.""" initial_state = "new" state_attribute = "current_state" new = properties.State(events=[ properties.Event( "TestEvent", "final_state", commands=[command1, command2]) ]) final_state = properties.FinalState()
class TestFSM(FSM): """Dumb class.""" # pylint: disable=no-self-use def hold(self): """Hold the state machine.""" hold_triggered.set() shutdown.wait() new = properties.State( events=[properties.Event("Hold", "final_state", commands=[hold])]) final_state = properties.FinalState()
class TestFSM(FSM): """Dumb class.""" initial_state = "state1" @on_change def hacky_change_call(self, *args, **kwargs): """Hacky way to check on change calls.""" command(self, *args, **kwargs) state1 = properties.State( events=[properties.Event("Change", "final_state")]) final_state = properties.FinalState()
class TestFSM(FSM): """Dumb class.""" initial_state = "state1" @on_error def hacky_error_call(self, *args, **kwargs): """Hacky way to check on error calls.""" command(self, *args, **kwargs) state1 = properties.State(events=[ properties.Event( "Change", "final_state", commands=[throw_exception]) ]) final_state = properties.FinalState()
class ExampleCreditCardFSM(FSM): """Credit card FSM.""" initial_state = "new" state_attribute = "current_state" event_error = properties.FinalState() state_error = properties.FinalState() new = properties.State( events=[ properties.Event("Initialize", "authorisation_pending", error=properties.Error("event_error")) ], error=properties.Error("state_error"), ) authorisation_pending = properties.State( events=[properties.Event("Authorize", "capture_pending")]) capture_pending = properties.State( events=[properties.Event("Capture", "paid")], timeout=properties.Timeout(timedelta(days=7), "timeout_test")) timeout_test = properties.FinalState() paid = properties.State( events=[properties.Event("Refund", "refund_pending")]) finished = properties.State(events=[ properties.Event("ChargeBack", "charged_back"), properties.Event("Refund", "refunded") ]) refund_pending = properties.State( events=[properties.Event("Refund", "refunded")]) refunded = properties.FinalState() charged_back = properties.FinalState()
class TestFSM(FSM): """Dumb class.""" initial_state = "state1" state1 = properties.State(on_enter=[command])
class TestFSM(FSM): """Dumb class.""" state = properties.State(error=properties.Error("invalid_state"))