mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #15083 -- Corrected the order of TemplateResponse middleware handling, ensuring that custom URLConfs are valid, and that ResponseMiddleware is invoked if the TemplateResponseMiddleware causes errors. Thanks to Sayane for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15226 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
from django.utils import unittest
|
||||
from django.test import RequestFactory
|
||||
from django.test import RequestFactory, TestCase
|
||||
from django.conf import settings
|
||||
import django.template.context
|
||||
from django.template import Template, Context, RequestContext
|
||||
@@ -11,6 +11,13 @@ def test_processor(request):
|
||||
return {'processors': 'yes'}
|
||||
test_processor_name = 'regressiontests.templates.response.test_processor'
|
||||
|
||||
|
||||
# A test middleware that installs a temporary URLConf
|
||||
class CustomURLConfMiddleware(object):
|
||||
def process_request(self, request):
|
||||
request.urlconf = 'regressiontests.templates.alternate_urls'
|
||||
|
||||
|
||||
class BaseTemplateResponseTest(unittest.TestCase):
|
||||
# tests rely on fact that global context
|
||||
# processors should only work when RequestContext is used.
|
||||
@@ -179,3 +186,23 @@ class TemplateResponseTest(BaseTemplateResponseTest):
|
||||
rc = response.resolve_context(response.context_data)
|
||||
|
||||
self.assertEqual(rc.current_app, 'foobar')
|
||||
|
||||
|
||||
class CustomURLConfTest(TestCase):
|
||||
urls = 'regressiontests.templates.urls'
|
||||
|
||||
def setUp(self):
|
||||
self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES
|
||||
settings.MIDDLEWARE_CLASSES = list(settings.MIDDLEWARE_CLASSES) + [
|
||||
'regressiontests.templates.response.CustomURLConfMiddleware'
|
||||
]
|
||||
|
||||
def tearDown(self):
|
||||
settings.MIDDLEWARE_CLASSES = self.old_MIDDLEWARE_CLASSES
|
||||
|
||||
def test_custom_urlconf(self):
|
||||
response = self.client.get('/template_response_view/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.content, 'This is where you can find the snark: /snark/')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user