mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #27027 -- Restored Client.force_login() defaulting to the first auth backend.
This commit is contained in:
parent
4f113483d7
commit
fc8f097117
3 changed files with 25 additions and 0 deletions
|
@ -532,12 +532,30 @@ class ClientTest(TestCase):
|
|||
|
||||
# Log in
|
||||
self.client.force_login(self.u1, backend='test_client.auth_backends.TestClientBackend')
|
||||
self.assertEqual(self.u1.backend, 'test_client.auth_backends.TestClientBackend')
|
||||
|
||||
# Request a page that requires a login
|
||||
response = self.client.get('/login_protected_view/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.context['user'].username, 'testclient')
|
||||
|
||||
@override_settings(
|
||||
AUTHENTICATION_BACKENDS=[
|
||||
'django.contrib.auth.backends.ModelBackend',
|
||||
'test_client.auth_backends.TestClientBackend',
|
||||
],
|
||||
)
|
||||
def test_force_login_without_backend(self):
|
||||
"""
|
||||
force_login() without passing a backend and with multiple backends
|
||||
configured should automatically use the first backend.
|
||||
"""
|
||||
self.client.force_login(self.u1)
|
||||
response = self.client.get('/login_protected_view/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.context['user'].username, 'testclient')
|
||||
self.assertEqual(self.u1.backend, 'django.contrib.auth.backends.ModelBackend')
|
||||
|
||||
@override_settings(SESSION_ENGINE="django.contrib.sessions.backends.signed_cookies")
|
||||
def test_logout_cookie_sessions(self):
|
||||
self.test_logout()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue