Commits

Anonymous committed 28c5a70

add test for group permissions

Comments (0)

Files changed (2)

djangotoolbox/contrib/auth/tests/__init__.py

 from djangotoolbox.contrib.auth.tests.tokens import TOKEN_GENERATOR_TESTS
 from djangotoolbox.contrib.auth.tests.models import ProfileTestCase
 
+from djangotoolbox.contrib.auth.tests.groups import GroupPermissionTest
+
 # The password for the fixture data users is 'password'
 
 __test__ = {

djangotoolbox/contrib/auth/tests/groups.py

+from django.conf import settings
+from django.contrib.contenttypes.models import ContentType
+from django.test import TestCase
+from djangotoolbox.contrib.auth.models import Group, User, GroupList, Permission, PermissionList
+
+
+class GroupPermissionTest(TestCase):
+
+    backend = 'djangotoolbox.contrib.auth.backends.ModelBackend'
+
+    def setUp(self):
+        self.curr_auth = settings.AUTHENTICATION_BACKENDS
+        settings.AUTHENTICATION_BACKENDS = (self.backend,)
+        User.objects.create_user('test', 'test@example.com', 'test')
+
+    def tearDown(self):
+        settings.AUTHENTICATION_BACKENDS = self.curr_auth
+
+    def test_group_perms(self):
+        user = User.objects.get(username='test')
+        group_list = GroupList.objects.create()
+        user.group_list = group_list
+        user.save()
+        group = Group.objects.create(name='test_group')
+        group_list.groups.append(group.id)
+        group_list.save()
+        content_type=ContentType.objects.get_for_model(Group)
+        perm = Permission.objects.create(name='test_group', content_type=content_type, codename='test_group')
+        perm_list = PermissionList.objects.create()
+        perm_list.permissions.append(perm.id)
+        content_type=ContentType.objects.get_for_model(ContentType)
+        perm = Permission.objects.create(name='test_group', content_type=content_type, codename='test_group')
+        perm_list.permissions.append(perm.id)
+        perm_list.save()
+        group.permissions = perm_list
+        group.save()
+
+        self.assertEqual(user.get_group_permissions(), set([u'contenttypes.test_group', u'auth.test_group']))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.