This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
2 changed files
with
81 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from django.db import models | ||
from django.test import TestCase | ||
from django_fsm import FSMField, transition, RETURN_VALUE, GET_STATE | ||
|
||
|
||
class MultiResultTest(models.Model): | ||
state = FSMField(default='new') | ||
|
||
@transition( | ||
field=state, | ||
source='new', | ||
target=RETURN_VALUE('for_moderators', 'published')) | ||
def publish(self, is_public=False): | ||
return 'published' if is_public else 'for_moderators' | ||
|
||
@transition( | ||
field=state, | ||
source='for_moderators', | ||
target=GET_STATE( | ||
lambda self, allowed: 'published' if allowed else 'rejected', | ||
states=['published', 'rejected'] | ||
) | ||
) | ||
def moderate(self, allowed): | ||
pass | ||
|
||
class Meta: | ||
app_label = 'testapp' | ||
|
||
|
||
class Test(TestCase): | ||
def test_return_state_succeed(self): | ||
instance = MultiResultTest() | ||
instance.publish(is_public=True) | ||
self.assertEqual(instance.state, 'published') | ||
|
||
def test_get_state_succeed(self): | ||
instance = MultiResultTest(state='for_moderators') | ||
instance.moderate(allowed=False) | ||
self.assertEqual(instance.state, 'rejected') |