summaryrefslogtreecommitdiff
path: root/tests/auth_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auth_tests')
-rw-r--r--tests/auth_tests/test_auth_backends.py4
-rw-r--r--tests/auth_tests/test_auth_backends_deprecation.py30
2 files changed, 32 insertions, 2 deletions
diff --git a/tests/auth_tests/test_auth_backends.py b/tests/auth_tests/test_auth_backends.py
index e850772f35..ea40992a61 100644
--- a/tests/auth_tests/test_auth_backends.py
+++ b/tests/auth_tests/test_auth_backends.py
@@ -475,7 +475,7 @@ class PermissionDeniedBackend(object):
Always raises PermissionDenied in `authenticate`, `has_perm` and `has_module_perms`.
"""
- def authenticate(self, username=None, password=None):
+ def authenticate(self, request, username=None, password=None):
raise PermissionDenied
def has_perm(self, user_obj, perm, obj=None):
@@ -585,7 +585,7 @@ class TypeErrorBackend(object):
Always raises TypeError.
"""
- def authenticate(self, username=None, password=None):
+ def authenticate(self, request, username=None, password=None):
raise TypeError
diff --git a/tests/auth_tests/test_auth_backends_deprecation.py b/tests/auth_tests/test_auth_backends_deprecation.py
new file mode 100644
index 0000000000..6178936535
--- /dev/null
+++ b/tests/auth_tests/test_auth_backends_deprecation.py
@@ -0,0 +1,30 @@
+import warnings
+
+from django.contrib.auth import authenticate
+from django.test import SimpleTestCase, override_settings
+
+
+class NoRequestBackend(object):
+ def authenticate(self, username=None, password=None):
+ # Doesn't accept a request parameter.
+ pass
+
+
+class AcceptsRequestBackendTest(SimpleTestCase):
+ """
+ A deprecation warning is shown for backends that have an authenticate()
+ method without a request parameter.
+ """
+ no_request_backend = '%s.NoRequestBackend' % __name__
+
+ @override_settings(AUTHENTICATION_BACKENDS=[no_request_backend])
+ def test_no_request_deprecation_warning(self):
+ with warnings.catch_warnings(record=True) as warns:
+ warnings.simplefilter('always')
+ authenticate(username='test', password='test')
+ self.assertEqual(len(warns), 1)
+ self.assertEqual(
+ str(warns[0].message),
+ "Update authentication backend %s to accept a positional `request` "
+ "argument." % self.no_request_backend
+ )