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.
Support for permissions on transition methods Close #36
- Loading branch information
Showing
5 changed files
with
141 additions
and
32 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
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 |
---|---|---|
@@ -1,16 +1,33 @@ | ||
""" | ||
This file demonstrates writing tests using the unittest module. These will pass | ||
when you run "manage.py test". | ||
from django.contrib.auth.models import User, Permission | ||
from django.test import TestCase | ||
|
||
Replace this with more appropriate tests for your application. | ||
""" | ||
from django_fsm import has_transition_perm | ||
from testapp.models import BlogPost | ||
|
||
from django.test import TestCase | ||
|
||
class PermissionFSMFieldTest(TestCase): | ||
def setUp(self): | ||
self.model = BlogPost() | ||
self.unpriviledged = User.objects.create(username='unpriviledged') | ||
self.priviledged = User.objects.create(username='priviledged') | ||
|
||
self.priviledged.user_permissions.add( | ||
Permission.objects.get_by_natural_key('can_publish_post', 'testapp', 'blogpost')) | ||
self.priviledged.user_permissions.add( | ||
Permission.objects.get_by_natural_key('can_remove_post', 'testapp', 'blogpost')) | ||
|
||
def test_proviledged_access_succed(self): | ||
self.assertTrue(has_transition_perm(self.model.publish, self.priviledged)) | ||
self.assertTrue(has_transition_perm(self.model.remove, self.priviledged)) | ||
|
||
transitions = self.model.get_available_user_state_transitions(self.priviledged) | ||
self.assertEquals(set(['publish', 'remove', 'moderate']), | ||
set(transition.name for transition in transitions)) | ||
|
||
def test_unpriviledged_access_prohibited(self): | ||
self.assertFalse(has_transition_perm(self.model.publish, self.unpriviledged)) | ||
self.assertFalse(has_transition_perm(self.model.remove, self.unpriviledged)) | ||
|
||
class SimpleTest(TestCase): | ||
def test_basic_addition(self): | ||
""" | ||
Tests that 1 + 1 always equals 2. | ||
""" | ||
self.assertEqual(1 + 1, 2) | ||
transitions = self.model.get_available_user_state_transitions(self.unpriviledged) | ||
self.assertEquals(set(['moderate']), | ||
set(transition.name for transition in transitions)) |
This code block should start one line earlier