mirror of
https://github.com/django/django.git
synced 2025-07-24 13:44:32 +00:00
Fixed #13090 -- Corrected handling of errors in middleware when DEBUG=False. Thanks to EroSennin for the report, and Ivan Sagalaev for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12773 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
4120a181e9
commit
794690c272
2 changed files with 19 additions and 15 deletions
|
@ -3,9 +3,12 @@ import sys
|
|||
from django.test import TestCase
|
||||
from django.core.signals import got_request_exception
|
||||
|
||||
class RequestMiddleware(object):
|
||||
class TestException(Exception):
|
||||
pass
|
||||
|
||||
class TestMiddleware(object):
|
||||
def process_request(self, request):
|
||||
raise Exception('Exception')
|
||||
raise TestException('Test Exception')
|
||||
|
||||
class MiddlewareExceptionTest(TestCase):
|
||||
def setUp(self):
|
||||
|
@ -21,15 +24,17 @@ class MiddlewareExceptionTest(TestCase):
|
|||
self.exceptions.append(sys.exc_info())
|
||||
|
||||
def test_process_request(self):
|
||||
self.client.handler._request_middleware.insert(0, RequestMiddleware().process_request)
|
||||
self.client.handler._request_middleware.insert(0, TestMiddleware().process_request)
|
||||
try:
|
||||
response = self.client.get('/')
|
||||
except:
|
||||
except TestException, e:
|
||||
# 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
|
||||
except Exception, e:
|
||||
self.fail("Unexpected exception: %s" % e)
|
||||
self.assertEquals(len(self.exceptions), 1)
|
||||
exception, value, tb = self.exceptions[0]
|
||||
self.assertEquals(value.args, ('Exception', ))
|
||||
self.assertEquals(value.args, ('Test Exception', ))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue