Ticket #13394: authentication_backend.patch
File authentication_backend.patch, 6.2 KB (added by , 13 years ago) |
---|
-
contrib/auth/tests/signals.py
1 from django.conf import settings 1 2 from django.test import TestCase 2 3 from django.contrib.auth import signals 3 4 … … 13 14 self.logged_out.append(user) 14 15 15 16 def setUp(self): 16 """Set up the listeners and reset the logged in/logged out counters""" 17 """ 18 Set up the listeners 19 reset the logged in/logged out counters 20 enable only the minimum required middleware and authentication backends to 21 prevent these tests from breaking when different middleware/backends are used 22 """ 17 23 self.logged_in = [] 18 24 self.logged_out = [] 19 25 signals.user_logged_in.connect(self.listener_login) 20 26 signals.user_logged_out.connect(self.listener_logout) 27 self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES 28 settings.MIDDLEWARE_CLASSES = ( 29 'django.contrib.sessions.middleware.SessionMiddleware', 30 ) 31 self.old_AUTHENTICATION_BACKENDS = settings.AUTHENTICATION_BACKENDS 32 settings.AUTHENTICATION_BACKENDS = ( 33 'django.contrib.auth.backends.ModelBackend', 34 ) 21 35 22 36 def tearDown(self): 23 """Disconnect the listeners""" 37 """ 38 Disconnect the listeners 39 restore the original settings 40 """ 24 41 signals.user_logged_in.disconnect(self.listener_login) 25 42 signals.user_logged_out.disconnect(self.listener_logout) 43 settings.AUTHENTICATION_BACKENDS = self.old_AUTHENTICATION_BACKENDS 44 settings.MIDDLEWARE_CLASSES = self.old_MIDDLEWARE_CLASSES 26 45 27 46 def test_login(self): 28 47 # Only a successful login will trigger the signal. -
contrib/auth/tests/views.py
28 28 settings.TEMPLATE_DIRS = ( 29 29 os.path.join(os.path.dirname(__file__), 'templates'), 30 30 ) 31 self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES 32 settings.MIDDLEWARE_CLASSES = ( 33 'django.contrib.sessions.middleware.SessionMiddleware', 34 'django.contrib.auth.middleware.AuthenticationMiddleware', 35 ) 36 self.old_AUTHENTICATION_BACKENDS = settings.AUTHENTICATION_BACKENDS 37 settings.AUTHENTICATION_BACKENDS = ( 38 'django.contrib.auth.backends.ModelBackend', 39 ) 31 40 32 41 def tearDown(self): 33 42 settings.LANGUAGES = self.old_LANGUAGES 34 43 settings.LANGUAGE_CODE = self.old_LANGUAGE_CODE 35 44 settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS 45 settings.MIDDLEWARE_CLASSES = self.old_MIDDLEWARE_CLASSES 46 settings.AUTHENTICATION_BACKENDS = self.old_AUTHENTICATION_BACKENDS 36 47 37 48 def login(self, password='password'): 38 49 response = self.client.post('/login/', { -
contrib/messages/tests/base.py
63 63 self.save_warnings_state() 64 64 warnings.filterwarnings('ignore', category=DeprecationWarning, 65 65 module='django.contrib.auth.models') 66 self.old_AUTHENTICATION_BACKENDS = settings.AUTHENTICATION_BACKENDS 67 settings.AUTHENTICATION_BACKENDS = ( 68 'django.contrib.auth.backends.ModelBackend', 69 ) 70 self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES 71 settings.MIDDLEWARE_CLASSES = ( 72 'django.contrib.sessions.middleware.SessionMiddleware', 73 'django.contrib.auth.middleware.AuthenticationMiddleware', 74 'django.contrib.messages.middleware.MessageMiddleware', 75 ) 66 76 67 77 def tearDown(self): 68 78 for setting in self.restore_settings: … … 75 85 settings.MESSAGE_STORAGE = self._message_storage 76 86 settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS 77 87 self.restore_warnings_state() 88 settings.AUTHENTICATION_BACKENDS = self.old_AUTHENTICATION_BACKENDS 89 settings.MIDDLEWARE_CLASSES = self.old_MIDDLEWARE_CLASSES 78 90 79 91 def restore_setting(self, setting): 80 92 if setting in self._remembered_settings: -
contrib/auth/tests/forms.py
1 from django.conf import settings 1 2 from django.contrib.auth.models import User 2 3 from django.contrib.auth.forms import UserCreationForm, AuthenticationForm, PasswordChangeForm, SetPasswordForm, UserChangeForm, PasswordResetForm 3 4 from django.test import TestCase … … 78 79 79 80 fixtures = ['authtestdata.json'] 80 81 82 def setUp(self): 83 self.old_AUTHENTICATION_BACKENDS = settings.AUTHENTICATION_BACKENDS 84 settings.AUTHENTICATION_BACKENDS = ( 85 'django.contrib.auth.backends.ModelBackend', 86 ) 87 88 def tearDown(self): 89 settings.AUTHENTICATION_BACKENDS = self.old_AUTHENTICATION_BACKENDS 90 81 91 def test_invalid_username(self): 82 92 # The user submits an invalid username. 83 93 -
contrib/auth/tests/remote_user.py
19 19 def setUp(self): 20 20 self.curr_middleware = settings.MIDDLEWARE_CLASSES 21 21 self.curr_auth = settings.AUTHENTICATION_BACKENDS 22 settings.MIDDLEWARE_CLASSES += (self.middleware,) 22 settings.MIDDLEWARE_CLASSES = ( 23 'django.contrib.sessions.middleware.SessionMiddleware', 24 'django.contrib.auth.middleware.AuthenticationMiddleware', 25 self.middleware, 26 ) 23 27 settings.AUTHENTICATION_BACKENDS = (self.backend,) 24 28 25 29 def test_no_remote_user(self):