diff options
| author | Aleksej Manaev <aleksej.manaev@gmx.de> | 2016-07-11 16:40:39 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-09-12 20:11:53 -0400 |
| commit | 4b9330ccc04575f9e5126529ec355a450d12e77c (patch) | |
| tree | 90d340a9d28bd448b3b709b8b605bd1009bbba0a /tests | |
| parent | 32c0d823e5316aa7d616a69996919b62748368cc (diff) | |
Fixed #25187 -- Made request available in authentication backends.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/auth_tests/test_auth_backends.py | 4 | ||||
| -rw-r--r-- | tests/auth_tests/test_auth_backends_deprecation.py | 30 | ||||
| -rw-r--r-- | tests/test_client_regress/auth_backends.py | 2 |
3 files changed, 33 insertions, 3 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 + ) diff --git a/tests/test_client_regress/auth_backends.py b/tests/test_client_regress/auth_backends.py index 02a6d39611..847bef85f0 100644 --- a/tests/test_client_regress/auth_backends.py +++ b/tests/test_client_regress/auth_backends.py @@ -5,7 +5,7 @@ from .models import CustomUser class CustomUserBackend(ModelBackend): - def authenticate(self, username=None, password=None): + def authenticate(self, request, username=None, password=None): try: user = CustomUser.custom_objects.get_by_natural_key(username) if user.check_password(password): |
