mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #6094 -- Middleware exceptions are now caught by the core handler. Thanks, isagalaev
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12165 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
1
tests/regressiontests/middleware_exceptions/models.py
Normal file
1
tests/regressiontests/middleware_exceptions/models.py
Normal file
@@ -0,0 +1 @@
|
||||
from django.db import models
|
||||
37
tests/regressiontests/middleware_exceptions/tests.py
Normal file
37
tests/regressiontests/middleware_exceptions/tests.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import sys
|
||||
|
||||
from django.test import TestCase
|
||||
from django.core.signals import got_request_exception
|
||||
|
||||
class RequestMiddleware(object):
|
||||
def process_request(self, request):
|
||||
raise Exception('Exception')
|
||||
|
||||
class MiddlewareExceptionTest(TestCase):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(MiddlewareExceptionTest, self).__init__(*args, **kwargs)
|
||||
self.exceptions = []
|
||||
got_request_exception.connect(self._on_request_exception)
|
||||
|
||||
def setUp(self):
|
||||
self.client.handler.load_middleware()
|
||||
|
||||
def tearDown(self):
|
||||
self.exceptions = []
|
||||
|
||||
def _on_request_exception(self, sender, request, **kwargs):
|
||||
self.exceptions.append(sys.exc_info())
|
||||
|
||||
def test_process_request(self):
|
||||
self.client.handler._request_middleware.insert(0, RequestMiddleware().process_request)
|
||||
try:
|
||||
response = self.client.get('/')
|
||||
except:
|
||||
# Test client indefinitely re-raises any exceptions being raised
|
||||
# during request handling. Hence actual testing that exception was
|
||||
# properly handled is done by relying on got_request_exception
|
||||
# signal being sent.
|
||||
pass
|
||||
self.assertEquals(len(self.exceptions), 1)
|
||||
exception, value, tb = self.exceptions[0]
|
||||
self.assertEquals(value.args, ('Exception', ))
|
||||
8
tests/regressiontests/middleware_exceptions/urls.py
Normal file
8
tests/regressiontests/middleware_exceptions/urls.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# coding: utf-8
|
||||
from django.conf.urls.defaults import *
|
||||
|
||||
import views
|
||||
|
||||
urlpatterns = patterns('',
|
||||
(r'^$', views.index),
|
||||
)
|
||||
4
tests/regressiontests/middleware_exceptions/views.py
Normal file
4
tests/regressiontests/middleware_exceptions/views.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from django import http
|
||||
|
||||
def index(request):
|
||||
return http.HttpResponse('')
|
||||
Reference in New Issue
Block a user