summaryrefslogtreecommitdiff
path: root/tests/auth_tests/test_auth_backends.py
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2016-04-02 13:18:26 +0200
committerTim Graham <timograham@gmail.com>2016-04-09 14:54:18 -0400
commitc1aec0feda73ede09503192a66f973598aef901d (patch)
treef1e4c09f3e98177cfe78cc9039b300f8984e7aed /tests/auth_tests/test_auth_backends.py
parentc16b9dd8e0ae757616e9accbaffecc521191ee98 (diff)
Fixed #25847 -- Made User.is_(anonymous|authenticated) properties.
Diffstat (limited to 'tests/auth_tests/test_auth_backends.py')
-rw-r--r--tests/auth_tests/test_auth_backends.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/tests/auth_tests/test_auth_backends.py b/tests/auth_tests/test_auth_backends.py
index e3c0109c96..91f92397a2 100644
--- a/tests/auth_tests/test_auth_backends.py
+++ b/tests/auth_tests/test_auth_backends.py
@@ -12,7 +12,7 @@ from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
from django.http import HttpRequest
from django.test import (
- SimpleTestCase, TestCase, modify_settings, override_settings,
+ SimpleTestCase, TestCase, mock, modify_settings, override_settings,
)
from .models import (
@@ -142,11 +142,10 @@ class BaseModelBackendTest(object):
self.assertEqual(backend.get_user_permissions(user), {'auth.test_user', 'auth.test_group'})
self.assertEqual(backend.get_group_permissions(user), {'auth.test_group'})
- user.is_anonymous = lambda: True
-
- self.assertEqual(backend.get_all_permissions(user), set())
- self.assertEqual(backend.get_user_permissions(user), set())
- self.assertEqual(backend.get_group_permissions(user), set())
+ with mock.patch.object(self.UserModel, 'is_anonymous', True):
+ self.assertEqual(backend.get_all_permissions(user), set())
+ self.assertEqual(backend.get_user_permissions(user), set())
+ self.assertEqual(backend.get_group_permissions(user), set())
def test_inactive_has_no_permissions(self):
"""
@@ -334,14 +333,14 @@ class SimpleRowlevelBackend(object):
if isinstance(obj, TestObj):
if user.username == 'test2':
return True
- elif user.is_anonymous() and perm == 'anon':
+ elif user.is_anonymous and perm == 'anon':
return True
elif not user.is_active and perm == 'inactive':
return True
return False
def has_module_perms(self, user, app_label):
- if not user.is_anonymous() and not user.is_active:
+ if not user.is_anonymous and not user.is_active:
return False
return app_label == "app1"
@@ -352,7 +351,7 @@ class SimpleRowlevelBackend(object):
if not isinstance(obj, TestObj):
return ['none']
- if user.is_anonymous():
+ if user.is_anonymous:
return ['anon']
if user.username == 'test2':
return ['simple', 'advanced']
@@ -578,7 +577,7 @@ class ChangedBackendSettingsTest(TestCase):
# Assert that the user retrieval is successful and the user is
# anonymous as the backend is not longer available.
self.assertIsNotNone(user)
- self.assertTrue(user.is_anonymous())
+ self.assertTrue(user.is_anonymous)
class TypeErrorBackend(object):