mirror of
https://github.com/django/django.git
synced 2025-10-25 22:56:12 +00:00
Fixed #25187 -- Made request available in authentication backends.
This commit is contained in:
committed by
Tim Graham
parent
32c0d823e5
commit
4b9330ccc0
30
tests/auth_tests/test_auth_backends_deprecation.py
Normal file
30
tests/auth_tests/test_auth_backends_deprecation.py
Normal file
@@ -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
|
||||
)
|
||||
Reference in New Issue
Block a user