summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Hahler <git@thequod.de>2017-05-22 17:03:18 +0200
committerTim Graham <timograham@gmail.com>2017-05-22 13:00:44 -0400
commita810f4aa04d205afba39903a141422cdbc945667 (patch)
tree82026950bb667824fd9756f42a9dcd7da2e897a8 /tests
parentbd6a3546d4c0552ca18853f4843f799acfe3e15b (diff)
[1.11.x] Refs #28207 -- Fixed contrib.auth.authenticate() if 'backend' is in the credentials.
Regression in 3008f30f194af386c354416be4c483f0f6b15f33. Backport of a3ba2662cdaa36183fdfb8a26dfa157e26fca76a from master
Diffstat (limited to 'tests')
-rw-r--r--tests/auth_tests/test_auth_backends_deprecation.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/auth_tests/test_auth_backends_deprecation.py b/tests/auth_tests/test_auth_backends_deprecation.py
index 7ee53a0bc6..675e185e9f 100644
--- a/tests/auth_tests/test_auth_backends_deprecation.py
+++ b/tests/auth_tests/test_auth_backends_deprecation.py
@@ -4,6 +4,7 @@ from django.contrib.auth import authenticate
from django.test import SimpleTestCase, override_settings
mock_request = object()
+mock_backend = object()
class NoRequestBackend(object):
@@ -19,6 +20,14 @@ class RequestNotPositionArgBackend:
assert request is mock_request
+class RequestNotPositionArgWithUsedKwargBackend:
+ def authenticate(self, username=None, password=None, request=None, backend=None):
+ assert username == 'username'
+ assert password == 'pass'
+ assert request is mock_request
+ assert backend is mock_backend
+
+
class AcceptsRequestBackendTest(SimpleTestCase):
"""
A deprecation warning is shown for backends that have an authenticate()
@@ -26,6 +35,7 @@ class AcceptsRequestBackendTest(SimpleTestCase):
"""
no_request_backend = '%s.NoRequestBackend' % __name__
request_not_positional_backend = '%s.RequestNotPositionArgBackend' % __name__
+ request_not_positional_with_used_kwarg_backend = '%s.RequestNotPositionArgWithUsedKwargBackend' % __name__
@override_settings(AUTHENTICATION_BACKENDS=[no_request_backend])
def test_no_request_deprecation_warning(self):
@@ -68,3 +78,15 @@ class AcceptsRequestBackendTest(SimpleTestCase):
"Update %s.authenticate() to accept a positional `request` "
"argument." % self.no_request_backend
)
+
+ @override_settings(AUTHENTICATION_BACKENDS=[request_not_positional_with_used_kwarg_backend])
+ def test_handles_backend_in_kwargs(self):
+ with warnings.catch_warnings(record=True) as warns:
+ warnings.simplefilter('always')
+ authenticate(username='username', password='pass', request=mock_request, backend=mock_backend)
+ self.assertEqual(len(warns), 1)
+ self.assertEqual(
+ str(warns[0].message),
+ "In %s.authenticate(), move the `request` keyword argument to the "
+ "first positional argument." % self.request_not_positional_with_used_kwarg_backend
+ )