mirror of
https://github.com/django/django.git
synced 2025-08-03 02:23:12 +00:00
Improved test coverage for django.contrib.auth.
This commit is contained in:
parent
fede65260a
commit
7588d7e439
3 changed files with 54 additions and 6 deletions
|
@ -583,20 +583,33 @@ class TypeErrorBackend:
|
|||
raise TypeError
|
||||
|
||||
|
||||
class TypeErrorBackendTest(TestCase):
|
||||
"""
|
||||
A TypeError within a backend is propagated properly (#18171).
|
||||
"""
|
||||
backend = 'auth_tests.test_auth_backends.TypeErrorBackend'
|
||||
class SkippedBackend:
|
||||
def authenticate(self):
|
||||
# Doesn't accept any credentials so is skipped by authenticate().
|
||||
pass
|
||||
|
||||
|
||||
class AuthenticateTests(TestCase):
|
||||
def setUp(self):
|
||||
self.user1 = User.objects.create_user('test', 'test@example.com', 'test')
|
||||
|
||||
@override_settings(AUTHENTICATION_BACKENDS=[backend])
|
||||
@override_settings(AUTHENTICATION_BACKENDS=['auth_tests.test_auth_backends.TypeErrorBackend'])
|
||||
def test_type_error_raised(self):
|
||||
"""A TypeError within a backend is propagated properly (#18171)."""
|
||||
with self.assertRaises(TypeError):
|
||||
authenticate(username='test', password='test')
|
||||
|
||||
@override_settings(AUTHENTICATION_BACKENDS=(
|
||||
'auth_tests.test_auth_backends.SkippedBackend',
|
||||
'django.contrib.auth.backends.ModelBackend',
|
||||
))
|
||||
def test_skips_backends_without_arguments(self):
|
||||
"""
|
||||
A backend (SkippedBackend) is ignored if it doesn't accept the
|
||||
credentials as arguments.
|
||||
"""
|
||||
self.assertEqual(authenticate(username='test', password='test'), self.user1)
|
||||
|
||||
|
||||
class ImproperlyConfiguredUserModelTest(TestCase):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue