Ticket #15671: no-hasattr2.diff
File no-hasattr2.diff, 2.0 KB (added by , 14 years ago) |
---|
-
django/contrib/auth/tests/remote_user.py
1 1 from datetime import datetime 2 2 3 3 from django.conf import settings 4 from django.contrib.auth import middleware 4 5 from django.contrib.auth.backends import RemoteUserBackend 5 6 from django.contrib.auth.models import User 6 7 from django.test import TestCase … … 92 93 response = self.client.get('/remote_user/', REMOTE_USER=self.known_user) 93 94 self.assertEqual(default_login, response.context['user'].last_login) 94 95 96 def test_raises_exceptions(self): 97 """ 98 The exception raised by a failure when checking for request.user should 99 bubble up. 100 """ 101 class BrokenLazyUser(object): 102 def __get__(self, request, obj_type=None): 103 raise TypeError 104 curr_lazy_user = middleware.LazyUser 105 middleware.LazyUser = BrokenLazyUser 106 try: 107 self.assertRaises(TypeError, self.client.get, '/remote_user/', 108 REMOTE_USER=self.known_user) 109 finally: 110 middleware.LazyUser = curr_lazy_user 111 95 112 def tearDown(self): 96 113 """Restores settings to avoid breaking other tests.""" 97 114 settings.MIDDLEWARE_CLASSES = self.curr_middleware -
django/contrib/auth/middleware.py
38 38 39 39 def process_request(self, request): 40 40 # AuthenticationMiddleware is required so that request.user exists. 41 if not hasattr(request, 'user'): 41 try: 42 request.user 43 except AttributeError: 42 44 raise ImproperlyConfigured( 43 45 "The Django remote user auth middleware requires the" 44 46 " authentication middleware to be installed. Edit your"