Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Simplified test of contrib.auth.tests.

  • Loading branch information...
commit 0a8c0eda2ab2e7330bcf3bd5dc7c3434ab1a7a90 1 parent 535219e
@jorgecarleitao jorgecarleitao authored timgraham committed
Showing with 5 additions and 9 deletions.
  1. +5 −9 django/contrib/auth/tests/test_auth_backends.py
View
14 django/contrib/auth/tests/test_auth_backends.py
@@ -48,16 +48,15 @@ def tearDown(self):
def test_has_perm(self):
user = self.UserModel._default_manager.get(pk=self.user.pk)
self.assertEqual(user.has_perm('auth.test'), False)
+
user.is_staff = True
user.save()
self.assertEqual(user.has_perm('auth.test'), False)
+
user.is_superuser = True
user.save()
self.assertEqual(user.has_perm('auth.test'), True)
- user.is_staff = False
- user.is_superuser = False
- user.save()
- self.assertEqual(user.has_perm('auth.test'), False)
+
user.is_staff = True
user.is_superuser = True
user.is_active = False
@@ -69,7 +68,6 @@ def test_custom_perms(self):
content_type = ContentType.objects.get_for_model(Group)
perm = Permission.objects.create(name='test', content_type=content_type, codename='test')
user.user_permissions.add(perm)
- user.save()
# reloading user to purge the _perm_cache
user = self.UserModel._default_manager.get(pk=self.user.pk)
@@ -77,21 +75,20 @@ def test_custom_perms(self):
self.assertEqual(user.get_group_permissions(), set([]))
self.assertEqual(user.has_module_perms('Group'), False)
self.assertEqual(user.has_module_perms('auth'), True)
+
perm = Permission.objects.create(name='test2', content_type=content_type, codename='test2')
user.user_permissions.add(perm)
- user.save()
perm = Permission.objects.create(name='test3', content_type=content_type, codename='test3')
user.user_permissions.add(perm)
- user.save()
user = self.UserModel._default_manager.get(pk=self.user.pk)
self.assertEqual(user.get_all_permissions(), set(['auth.test2', 'auth.test', 'auth.test3']))
self.assertEqual(user.has_perm('test'), False)
self.assertEqual(user.has_perm('auth.test'), True)
self.assertEqual(user.has_perms(['auth.test2', 'auth.test3']), True)
+
perm = Permission.objects.create(name='test_group', content_type=content_type, codename='test_group')
group = Group.objects.create(name='test_group')
group.permissions.add(perm)
- group.save()
user.groups.add(group)
user = self.UserModel._default_manager.get(pk=self.user.pk)
exp = set(['auth.test2', 'auth.test', 'auth.test3', 'auth.test_group'])
@@ -109,7 +106,6 @@ def test_has_no_object_perm(self):
content_type = ContentType.objects.get_for_model(Group)
perm = Permission.objects.create(name='test', content_type=content_type, codename='test')
user.user_permissions.add(perm)
- user.save()
self.assertEqual(user.has_perm('auth.test', 'object'), False)
self.assertEqual(user.get_all_permissions('object'), set([]))
Please sign in to comment.
Something went wrong with that request. Please try again.