Kaydet (Commit) 65131911 authored tarafından Chris Wilson's avatar Chris Wilson Kaydeden (comit) Tim Graham

Fixed #21518 -- Made override_settings(ROOT_URLCONF) clear the resolver cache.

Thanks Aymeric Augustin and Simon Charette for reviews.
üst 43510cff
...@@ -124,3 +124,10 @@ def complex_setting_changed(**kwargs): ...@@ -124,3 +124,10 @@ def complex_setting_changed(**kwargs):
# stacklevel=5 shows the line containing the override_settings call. # stacklevel=5 shows the line containing the override_settings call.
warnings.warn("Overriding setting %s can lead to unexpected behaviour." warnings.warn("Overriding setting %s can lead to unexpected behaviour."
% kwargs['setting'], stacklevel=5) % kwargs['setting'], stacklevel=5)
@receiver(setting_changed)
def root_urlconf_changed(**kwargs):
if kwargs['setting'] == 'ROOT_URLCONF':
from django.core.urlresolvers import clear_url_caches
clear_url_caches()
...@@ -3,13 +3,16 @@ from __future__ import unicode_literals ...@@ -3,13 +3,16 @@ from __future__ import unicode_literals
import unittest import unittest
from django.conf.urls import patterns, url
from django.core.urlresolvers import reverse
from django.db import connection from django.db import connection
from django.forms import EmailField, IntegerField from django.forms import EmailField, IntegerField
from django.http import HttpResponse from django.http import HttpResponse
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.test import SimpleTestCase, TestCase, skipIfDBFeature, skipUnlessDBFeature from django.test import SimpleTestCase, TestCase, skipIfDBFeature, skipUnlessDBFeature
from django.test.html import HTMLParseError, parse_html from django.test.html import HTMLParseError, parse_html
from django.test.utils import CaptureQueriesContext, IgnoreAllDeprecationWarningsMixin from django.test.utils import (CaptureQueriesContext,
IgnoreAllDeprecationWarningsMixin, override_settings)
from django.utils import six from django.utils import six
from .models import Person from .models import Person
...@@ -627,3 +630,32 @@ class DoctestNormalizerTest(IgnoreAllDeprecationWarningsMixin, SimpleTestCase): ...@@ -627,3 +630,32 @@ class DoctestNormalizerTest(IgnoreAllDeprecationWarningsMixin, SimpleTestCase):
suite = make_doctest("test_utils.doctest_output") suite = make_doctest("test_utils.doctest_output")
failures = unittest.TextTestRunner(stream=six.StringIO()).run(suite) failures = unittest.TextTestRunner(stream=six.StringIO()).run(suite)
self.assertEqual(failures.failures, []) self.assertEqual(failures.failures, [])
# for OverrideSettingsTests
def fake_view(request):
pass
class FirstUrls:
urlpatterns = patterns('', url(r'first/$', fake_view, name='first'))
class SecondUrls:
urlpatterns = patterns('', url(r'second/$', fake_view, name='second'))
class OverrideSettingsTests(TestCase):
"""
#21518 -- If neither override_settings nor a settings_changed receiver
clears the URL cache between tests, then one of these two test methods will
fail.
"""
@override_settings(ROOT_URLCONF=FirstUrls)
def test_first(self):
reverse('first')
@override_settings(ROOT_URLCONF=SecondUrls)
def test_second(self):
reverse('second')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment