This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
96 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from django.db import models | ||
from django.test import TestCase | ||
|
||
from django_fsm import FSMField, transition, can_proceed | ||
from django_fsm.signals import post_transition | ||
|
||
|
||
class ExceptionalBlogPost(models.Model): | ||
state = FSMField(default='new') | ||
|
||
@transition(field=state, source='new', target='published', on_error='crashed') | ||
def publish(self): | ||
raise Exception('Upss') | ||
|
||
@transition(field=state, source='new', target='deleted') | ||
def delete(self): | ||
raise Exception('Upss') | ||
|
||
|
||
class FSMFieldExceptionTest(TestCase): | ||
def setUp(self): | ||
self.model = ExceptionalBlogPost() | ||
post_transition.connect(self.on_post_transition, sender=ExceptionalBlogPost) | ||
self.post_transition_data = None | ||
|
||
def on_post_transition(self, **kwargs): | ||
self.post_transition_data = kwargs | ||
|
||
def test_state_changed_after_fail(self): | ||
self.assertTrue(can_proceed(self.model.publish)) | ||
self.assertRaises(Exception, self.model.publish) | ||
self.assertEqual(self.model.state, 'crashed') | ||
self.assertEqual(self.post_transition_data['target'], 'crashed') | ||
self.assertTrue('exception' in self.post_transition_data) | ||
|
||
def test_state_not_changed_after_fail(self): | ||
self.assertTrue(can_proceed(self.model.delete)) | ||
self.assertRaises(Exception, self.model.delete) | ||
self.assertEqual(self.model.state, 'new') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters