Ticket #13394: authentication_backend.patch

File authentication_backend.patch, 6.2 KB (added by mattjmorrison, 13 years ago)

changed some django.contrib tests to explicitly define which middleware classes and authentication backends are assumed to be in settings.

  • contrib/auth/tests/signals.py

     
     1from django.conf import settings
    12from django.test import TestCase
    23from django.contrib.auth import signals
    34
     
    1314        self.logged_out.append(user)
    1415
    1516    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        """
    1723        self.logged_in = []
    1824        self.logged_out = []
    1925        signals.user_logged_in.connect(self.listener_login)
    2026        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        )
    2135
    2236    def tearDown(self):
    23         """Disconnect the listeners"""
     37        """
     38            Disconnect the listeners
     39            restore the original settings
     40        """
    2441        signals.user_logged_in.disconnect(self.listener_login)
    2542        signals.user_logged_out.disconnect(self.listener_logout)
     43        settings.AUTHENTICATION_BACKENDS = self.old_AUTHENTICATION_BACKENDS
     44        settings.MIDDLEWARE_CLASSES = self.old_MIDDLEWARE_CLASSES
    2645
    2746    def test_login(self):
    2847        # Only a successful login will trigger the signal.
  • contrib/auth/tests/views.py

     
    2828        settings.TEMPLATE_DIRS = (
    2929            os.path.join(os.path.dirname(__file__), 'templates'),
    3030        )
     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        )
    3140
    3241    def tearDown(self):
    3342        settings.LANGUAGES = self.old_LANGUAGES
    3443        settings.LANGUAGE_CODE = self.old_LANGUAGE_CODE
    3544        settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS
     45        settings.MIDDLEWARE_CLASSES = self.old_MIDDLEWARE_CLASSES
     46        settings.AUTHENTICATION_BACKENDS = self.old_AUTHENTICATION_BACKENDS
    3647
    3748    def login(self, password='password'):
    3849        response = self.client.post('/login/', {
  • contrib/messages/tests/base.py

     
    6363        self.save_warnings_state()
    6464        warnings.filterwarnings('ignore', category=DeprecationWarning,
    6565                                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        )
    6676
    6777    def tearDown(self):
    6878        for setting in self.restore_settings:
     
    7585        settings.MESSAGE_STORAGE = self._message_storage
    7686        settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS
    7787        self.restore_warnings_state()
     88        settings.AUTHENTICATION_BACKENDS = self.old_AUTHENTICATION_BACKENDS
     89        settings.MIDDLEWARE_CLASSES = self.old_MIDDLEWARE_CLASSES
    7890
    7991    def restore_setting(self, setting):
    8092        if setting in self._remembered_settings:
  • contrib/auth/tests/forms.py

     
     1from django.conf import settings
    12from django.contrib.auth.models import User
    23from django.contrib.auth.forms import UserCreationForm, AuthenticationForm,  PasswordChangeForm, SetPasswordForm, UserChangeForm, PasswordResetForm
    34from django.test import TestCase
     
    7879
    7980    fixtures = ['authtestdata.json']
    8081
     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
    8191    def test_invalid_username(self):
    8292        # The user submits an invalid username.
    8393
  • contrib/auth/tests/remote_user.py

     
    1919    def setUp(self):
    2020        self.curr_middleware = settings.MIDDLEWARE_CLASSES
    2121        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        )
    2327        settings.AUTHENTICATION_BACKENDS = (self.backend,)
    2428
    2529    def test_no_remote_user(self):
Back to Top