diff --git a/django_states/machine.py b/django_states/machine.py index 4ad7bfe..a76a160 100644 --- a/django_states/machine.py +++ b/django_states/machine.py @@ -364,6 +364,6 @@ def get_name(cls): """ return cls.__name__ - @property - def handler_kwargs(self): - return self.handler.__code__.co_varnames[3:] + @classmethod + def handler_kwargs(cls): + return cls.handler.__code__.co_varnames[3:] diff --git a/django_states/tests.py b/django_states/tests.py index 85a00fb..480f164 100644 --- a/django_states/tests.py +++ b/django_states/tests.py @@ -323,6 +323,15 @@ class startup(StateTransition): to_state = 'running' description = 'Start up the machine!' + class crash(StateTransition): + '''Transition from stopped to running''' + from_states = ['running'] + to_state = 'crashed' + description = 'Crash the machine!' + + def handler(self, instance, user=None, reason=None): + pass + class working(StateGroup): states = ['running'] @@ -343,18 +352,24 @@ class not_runing(StateGroup): T3Machine.get_transition_from_states('stopped', 'running') with self.assertRaises(TransitionNotFound): - T3Machine.get_transition_from_states('running', 'crashed') + T3Machine.get_transition_from_states('running', 'stopped') self.assertTrue(T3Machine.has_transition('startup')) - self.assertFalse(T3Machine.has_transition('crash')) + self.assertFalse(T3Machine.has_transition('stop')) trion = T3Machine.get_transitions('startup') self.assertFalse(hasattr(trion, 'from_state')) self.assertEqual(trion.from_states[0], 'stopped') self.assertEqual(trion.to_state, 'running') + trion = T3Machine.get_transitions('crash') + self.assertFalse(hasattr(trion, 'from_state')) + self.assertEqual(trion.from_states[0], 'running') + self.assertEqual(trion.to_state, 'crashed') + self.assertEqual(len(trion.handler_kwargs()), 1) + self.assertEqual(trion.handler_kwargs()[0], 'reason') with self.assertRaises(KeyError): - T3Machine.get_transitions('crash') + T3Machine.get_transitions('stop') # Admin actions actions = T3Machine.get_admin_actions() - self.assertEqual(len(actions), 1) + self.assertEqual(len(actions), 2) action = actions[0] self.assertEqual(action.__name__, 'state_transition_startup') self.assertTrue('stopped' in action.short_description)