Ticket #12594: 12594.patch

File 12594.patch, 3.0 KB (added by Yuri Baburov, 15 years ago)

Patch with tests

  • django/core/handlers/base.py

    diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py
    index a9bb058..d09f833 100644
    a b class BaseHandler(object):  
    174174            request_repr = "Request repr() unavailable"
    175175        message = "%s\n\n%s" % (self._get_traceback(exc_info), request_repr)
    176176        mail_admins(subject, message, fail_silently=True)
     177        # If Http500 handler is not installed, re-raise last exception
     178        if resolver.urlconf_module is None:
     179            raise exc_info[1], None, exc_info[2]
    177180        # Return an HttpResponse that displays a friendly error message.
    178181        callback, param_dict = resolver.resolve500()
    179182        return callback(request, **param_dict)
  • tests/regressiontests/urlpatterns_reverse/tests.py

    diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py
    index d5f3ec9..52a00f5 100644
    a b ImproperlyConfigured: The included urlconf regressiontests.urlpatterns_reverse.n  
    1717import unittest
    1818
    1919from django.conf import settings
     20from django.core.exceptions import ImproperlyConfigured
    2021from django.core.urlresolvers import reverse, resolve, NoReverseMatch, Resolver404
    2122from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect
    2223from django.shortcuts import redirect
    class ErrorHandlerResolutionTests(TestCase):  
    303304        handler = (empty_view, {})
    304305        self.assertEqual(self.callable_resolver.resolve404(), handler)
    305306        self.assertEqual(self.callable_resolver.resolve500(), handler)
     307
     308
     309class NoRootUrlConfTests(TestCase):
     310    """Tests for handler404 and handler500 if urlconf is None"""
     311    urls = None
     312   
     313    def test_no_handler_exception(self):
     314        self.assertRaises(ImproperlyConfigured, self.client.get, '/test_client_regress/no_template_view/')
     315
     316class ResolverIsNoneResolutionTests(TestCase):
     317    """Tests that handler404 and handler500 are properly raised if urlconf is None"""
     318
     319    urls = None
     320
     321    def setUp(self):
     322        from django.core.urlresolvers import RegexURLResolver
     323        urlconf = 'regressiontests.urlpatterns_reverse.urls_error_handlers'
     324        self.normal_resolver = RegexURLResolver(r'^$', urlconf)
     325        self.empty_resolver = RegexURLResolver(r'^$', None)
     326
     327    def test_handler_exceptions(self):
     328        from views import empty_view
     329        handler = (empty_view, {})
     330
     331        self.assertTrue(self.normal_resolver.urlconf_module is not None)
     332        self.assertTrue(self.empty_resolver.urlconf_module is None)
     333
     334        self.assertEqual(self.normal_resolver.resolve404(), handler)
     335        self.assertEqual(self.normal_resolver.resolve500(), handler)
     336
     337        #raises "AttributeError: 'NoneType' object has no attribute 'handler404'"
     338        self.assertRaises(AttributeError, self.empty_resolver.resolve404)
     339        #raises "AttributeError: 'NoneType' object has no attribute 'handler500'"
     340        self.assertRaises(AttributeError, self.empty_resolver.resolve500)
Back to Top