Ticket #13190: 13190_empty_auth_backends.diff.2

File 13190_empty_auth_backends.diff.2, 2.6 KB (added by Łukasz Rekucki, 14 years ago)

Use new exception syntax.

Line 
1diff --git a/django/contrib/auth/__init__.py b/django/contrib/auth/__init__.py
2index 169ae01..979f58d 100644
3--- a/django/contrib/auth/__init__.py
4+++ b/django/contrib/auth/__init__.py
5@@ -39,6 +39,8 @@ def get_backends():
6 backends = []
7 for backend_path in settings.AUTHENTICATION_BACKENDS:
8 backends.append(load_backend(backend_path))
9+ if not backends:
10+ raise ImproperlyConfigured('settings.AUTHENTICATION_BACKENDS is empty.')
11 return backends
12
13 def authenticate(**credentials):
14diff --git a/django/contrib/auth/tests/__init__.py b/django/contrib/auth/tests/__init__.py
15index a1d02b6..25d058e 100644
16--- a/django/contrib/auth/tests/__init__.py
17+++ b/django/contrib/auth/tests/__init__.py
18@@ -1,4 +1,4 @@
19-from django.contrib.auth.tests.auth_backends import BackendTest, RowlevelBackendTest, AnonymousUserBackendTest, NoAnonymousUserBackendTest
20+from django.contrib.auth.tests.auth_backends import BackendTest, RowlevelBackendTest, AnonymousUserBackendTest, NoAnonymousUserBackendTest, NoBackendTest
21 from django.contrib.auth.tests.basic import BASIC_TESTS
22 from django.contrib.auth.tests.decorators import LoginRequiredTestCase
23 from django.contrib.auth.tests.forms import UserCreationFormTest, AuthenticationFormTest, SetPasswordFormTest, PasswordChangeFormTest, UserChangeFormTest, PasswordResetFormTest
24diff --git a/django/contrib/auth/tests/auth_backends.py b/django/contrib/auth/tests/auth_backends.py
25index 8eaf2cb..9e6d338 100644
26--- a/django/contrib/auth/tests/auth_backends.py
27+++ b/django/contrib/auth/tests/auth_backends.py
28@@ -1,6 +1,7 @@
29 from django.conf import settings
30 from django.contrib.auth.models import User, Group, Permission, AnonymousUser
31 from django.contrib.contenttypes.models import ContentType
32+from django.core.exceptions import ImproperlyConfigured
33 from django.test import TestCase
34
35
36@@ -245,3 +246,20 @@ class NoAnonymousUserBackendTest(TestCase):
37
38 def test_get_all_permissions(self):
39 self.assertEqual(self.user1.get_all_permissions(TestObj()), set())
40+
41+class NoBackendTest(TestCase):
42+ """
43+ Tests that an appropriate error is raised if no auth backends are provided.
44+ """
45+ backend = ()
46+
47+ def setUp(self):
48+ self.curr_auth = settings.AUTHENTICATION_BACKENDS
49+ settings.AUTHENTICATION_BACKENDS = self.backend
50+ self.user = User.objects.create_user('test', 'test@example.com', 'test')
51+
52+ def tearDown(self):
53+ settings.AUTHENTICATION_BACKENDS = self.curr_auth
54+
55+ def test_raises_exception(self):
56+ self.assertRaises(ImproperlyConfigured, self.user.has_perm, ('perm', TestObj(),))
Back to Top