Module ImportFrom alias ImportFrom alias ImportFrom alias alias alias alias Assign NameStore TupleLoad TupleLoad Str Str TupleLoad Str Str TupleLoad Str Str TupleLoad Str Str TupleLoad Str Str TupleLoad Str Str ClassDef bases AttributeLoad NameLoad attr body Assign NameStore Call AttributeLoad NameLoad attr keyword NameLoad keyword Num Assign NameStore Call AttributeLoad NameLoad attr keyword Num FunctionDef arguments args NameParam defaults body Return AttributeLoad NameLoad attr decorator_list ClassDef bases body Assign NameStore Str decorator_list decorator_list ClassDef bases AttributeLoad NameLoad attr body Assign NameStore Call NameLoad NameLoad keyword Str keyword NameLoad FunctionDef arguments args NameParam defaults body Pass decorator_list Call NameLoad keyword NameLoad keyword Str keyword Str FunctionDef arguments args NameParam defaults body Pass decorator_list Call NameLoad keyword NameLoad keyword Str FunctionDef arguments args NameParam defaults body Pass decorator_list Call NameLoad keyword NameLoad keyword Str keyword Str FunctionDef arguments args NameParam defaults body Raise Call NameLoad Str decorator_list Call NameLoad keyword NameLoad keyword Str keyword Str FunctionDef arguments args NameParam defaults body Pass decorator_list Call NameLoad keyword NameLoad keyword ListLoad Str Str keyword Str FunctionDef arguments args NameParam defaults body Pass decorator_list Call NameLoad keyword NameLoad keyword Str keyword Str ClassDef bases body Assign NameStore Str decorator_list decorator_list ClassDef bases NameLoad body FunctionDef arguments args NameParam defaults body For NameStore NameLoad body Expr Call AttributeLoad AttributeLoad NameLoad attr attr keyword SubscriptLoad NameLoad Index Num keyword SubscriptLoad NameLoad Index Num Assign AttributeStore NameLoad attr Call NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Call AttributeLoad NameLoad attr AttributeLoad AttributeLoad NameLoad attr attr Str decorator_list FunctionDef arguments args NameParam defaults body Expr Call AttributeLoad NameLoad attr Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr AttributeLoad AttributeLoad NameLoad attr attr Str Expr Call AttributeLoad NameLoad attr Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr AttributeLoad AttributeLoad NameLoad attr attr Str decorator_list FunctionDef arguments args NameParam defaults body Expr Call AttributeLoad NameLoad attr Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr NameLoad AttributeLoad AttributeLoad NameLoad attr attr decorator_list FunctionDef arguments args NameParam defaults body Expr Call AttributeLoad NameLoad attr Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr NameLoad AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr AttributeLoad AttributeLoad NameLoad attr attr Str decorator_list FunctionDef arguments args NameParam defaults body Expr Call AttributeLoad NameLoad attr Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr AttributeLoad AttributeLoad NameLoad attr attr Str decorator_list FunctionDef arguments args NameParam defaults body Expr Call AttributeLoad NameLoad attr NameLoad AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr AttributeLoad AttributeLoad NameLoad attr attr Str decorator_list FunctionDef arguments args NameParam defaults body Expr Call AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr AttributeLoad AttributeLoad NameLoad attr attr Str decorator_list FunctionDef arguments args NameParam defaults body Expr Call AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr AttributeLoad AttributeLoad NameLoad attr attr Str decorator_list FunctionDef arguments args NameParam defaults body Expr Call AttributeLoad NameLoad attr Call NameLoad AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad AttributeLoad NameLoad attr attr Expr Call AttributeLoad NameLoad attr AttributeLoad AttributeLoad NameLoad attr attr Str decorator_list decorator_list Expr Str
N/A django.db models django.test TestCase django_fsm FSMKeyField TransitionNotAllowed transition can_proceed N/A FK_AVAILABLE_STATES N/A N/A New _NEW_ N/A Published _PUBLISHED_ N/A Hidden _HIDDEN_ N/A Removed _REMOVED_ N/A Stolen _STOLEN_ N/A Moderated _MODERATED_ DBState N/A N/A models Model N/A N/A id N/A N/A models CharField primary_key True max_length 50 N/A label N/A N/A models CharField max_length 255 __unicode__ N/A N/A self N/A N/A N/A N/A self label N/A Meta N/A N/A N/A app_label django_fsm N/A N/A FKBlogPost N/A N/A models Model N/A N/A state N/A FSMKeyField DBState default new protected True publish N/A N/A self N/A N/A N/A N/A N/A transition field state source new target published notify_all N/A N/A self N/A N/A N/A N/A N/A transition field state source published hide N/A N/A self N/A N/A N/A N/A N/A transition field state source published target hidden remove N/A N/A self N/A N/A N/A N/A Exception Upss N/A N/A transition field state source new target removed steal N/A N/A self N/A N/A N/A N/A N/A transition field state source N/A published hidden target stolen moderate N/A N/A self N/A N/A N/A N/A N/A transition field state source * target moderated Meta N/A N/A N/A app_label django_fsm N/A N/A FSMKeyFieldTest N/A TestCase N/A setUp N/A N/A self N/A N/A N/A item FK_AVAILABLE_STATES N/A N/A N/A N/A N/A DBState objects create pk N/A item N/A 0 label N/A item N/A 1 N/A N/A self model N/A FKBlogPost N/A test_initial_state_instatiated N/A N/A self N/A N/A N/A N/A N/A self assertEqual N/A N/A self model state new N/A test_known_transition_should_succeed N/A N/A self N/A N/A N/A N/A N/A self assertTrue N/A can_proceed N/A N/A self model publish N/A N/A N/A N/A self model publish N/A N/A N/A self assertEqual N/A N/A self model state published N/A N/A N/A self assertTrue N/A can_proceed N/A N/A self model hide N/A N/A N/A N/A self model hide N/A N/A N/A self assertEqual N/A N/A self model state hidden N/A test_unknow_transition_fails N/A N/A self N/A N/A N/A N/A N/A self assertFalse N/A can_proceed N/A N/A self model hide N/A N/A N/A self assertRaises TransitionNotAllowed N/A N/A self model hide N/A test_state_non_changed_after_fail N/A N/A self N/A N/A N/A N/A N/A self assertTrue N/A can_proceed N/A N/A self model remove N/A N/A N/A self assertRaises Exception N/A N/A self model remove N/A N/A N/A self assertEqual N/A N/A self model state new N/A test_allowed_null_transition_should_succeed N/A N/A self N/A N/A N/A N/A N/A self assertTrue N/A can_proceed N/A N/A self model publish N/A N/A N/A N/A self model publish N/A N/A N/A N/A self model notify_all N/A N/A N/A self assertEqual N/A N/A self model state published N/A test_unknow_null_transition_should_fail N/A N/A self N/A N/A N/A N/A N/A self assertRaises TransitionNotAllowed N/A N/A self model notify_all N/A N/A N/A self assertEqual N/A N/A self model state new N/A test_mutiple_source_support_path_1_works N/A N/A self N/A N/A N/A N/A N/A N/A self model publish N/A N/A N/A N/A self model steal N/A N/A N/A self assertEqual N/A N/A self model state stolen N/A test_mutiple_source_support_path_2_works N/A N/A self N/A N/A N/A N/A N/A N/A self model publish N/A N/A N/A N/A self model hide N/A N/A N/A N/A self model steal N/A N/A N/A self assertEqual N/A N/A self model state stolen N/A test_star_shortcut_succeed N/A N/A self N/A N/A N/A N/A N/A self assertTrue N/A can_proceed N/A N/A self model moderate N/A N/A N/A N/A self model moderate N/A N/A N/A self assertEqual N/A N/A self model state moderated N/A N/A N/A 
TODO FIX it
class BlogPostStatus(models.Model):
    name = models.CharField(max_length=10, unique=True)
    objects = models.Manager()

    class Meta:
        app_label = 'django_fsm'


class BlogPostWithFKState(models.Model):
    status = FSMKeyField(BlogPostStatus, default=lambda: BlogPostStatus.objects.get(name="new"))

    @transition(field=status, source='new', target='published')
    def publish(self):
        pass

    @transition(field=status, source='published', target='hidden')
    def hide(self):
        pass


class BlogPostWithFKStateTest(TestCase):
    def setUp(self):
        BlogPostStatus.objects.create(name="new")
        BlogPostStatus.objects.create(name="published")
        BlogPostStatus.objects.create(name="hidden")
        self.model = BlogPostWithFKState()

    def test_known_transition_should_succeed(self):
        self.model.publish()
        self.assertEqual(self.model.state, 'published')

        self.model.hide()
        self.assertEqual(self.model.state, 'hidden')

    def test_unknow_transition_fails(self):
        self.assertRaises(TransitionNotAllowed, self.model.hide)
