Ticket #6094: 6094-minimal.diff
File 6094-minimal.diff, 4.8 KB (added by , 15 years ago) |
---|
-
django/core/handlers/base.py
=== modified file 'django/core/handlers/base.py'
68 68 from django.core import exceptions, urlresolvers 69 69 from django.conf import settings 70 70 71 # Reset the urlconf for this thread.72 urlresolvers.set_urlconf(None)73 74 # Apply request middleware75 for middleware_method in self._request_middleware:76 response = middleware_method(request)77 if response:78 return response79 80 # Get urlconf from request object, if available. Otherwise use default.81 urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF)82 83 # Set the urlconf for this thread to the one specified above.84 urlresolvers.set_urlconf(urlconf)85 86 resolver = urlresolvers.RegexURLResolver(r'^/', urlconf)87 71 try: 88 72 try: 73 # Reset the urlconf for this thread. 74 urlresolvers.set_urlconf(None) 75 76 # Get urlconf from request object, if available. Otherwise use default. 77 urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF) 78 79 # Set the urlconf for this thread to the one specified above. 80 urlresolvers.set_urlconf(urlconf) 81 resolver = urlresolvers.RegexURLResolver(r'^/', urlconf) 82 83 # Apply request middleware 84 for middleware_method in self._request_middleware: 85 response = middleware_method(request) 86 if response: 87 return response 88 89 89 callback, callback_args, callback_kwargs = resolver.resolve( 90 90 request.path_info) 91 91 -
tests/regressiontests/middleware_exceptions/models.py
=== added directory 'tests/regressiontests/middleware_exceptions' === added file 'tests/regressiontests/middleware_exceptions/__init__.py' === added file 'tests/regressiontests/middleware_exceptions/models.py'
1 from django.db import models -
tests/regressiontests/middleware_exceptions/tests.py
=== added file 'tests/regressiontests/middleware_exceptions/tests.py'
1 import sys 2 3 from django.test import TestCase 4 from django.core.signals import got_request_exception 5 6 class RequestMiddleware(object): 7 def process_request(self, request): 8 raise Exception('Exception') 9 10 class MiddlewareExceptionTest(TestCase): 11 def __init__(self, *args, **kwargs): 12 super(MiddlewareExceptionTest, self).__init__(*args, **kwargs) 13 self.exceptions = [] 14 got_request_exception.connect(self._on_request_exception) 15 16 def setUp(self): 17 self.client.handler.load_middleware() 18 19 def tearDown(self): 20 self.exceptions = [] 21 22 def _on_request_exception(self, sender, request, **kwargs): 23 self.exceptions.append(sys.exc_info()) 24 25 def test_process_request(self): 26 self.client.handler._request_middleware.insert(0, RequestMiddleware().process_request) 27 try: 28 response = self.client.get('/') 29 except: 30 # Test client indefinitely re-raises any exceptions being raised 31 # during request handling. Hence actual testing that exception was 32 # properly handled is done by relying on got_request_exception 33 # signal being sent. 34 pass 35 self.assertEquals(len(self.exceptions), 1) 36 exception, value, tb = self.exceptions[0] 37 self.assertEquals(value.args, ('Exception', )) -
tests/regressiontests/middleware_exceptions/urls.py
=== added file 'tests/regressiontests/middleware_exceptions/urls.py'
1 # coding: utf-8 2 from django.conf.urls.defaults import * 3 4 import views 5 6 urlpatterns = patterns('', 7 (r'^$', views.index), 8 ) -
tests/regressiontests/middleware_exceptions/views.py
=== added file 'tests/regressiontests/middleware_exceptions/views.py'
1 from django import http 2 3 def index(request): 4 return http.HttpResponse('') -
tests/urls.py
=== modified file 'tests/urls.py'
35 35 36 36 # conditional get views 37 37 (r'condition/', include('regressiontests.conditional_processing.urls')), 38 39 # middleware exceptions tests 40 (r'middleware_exceptions/', include('regressiontests.middleware_exceptions.urls')), 38 41 )