From 415bd694f9de8252e8d47bdf3df73cc62ca97728 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Mon, 30 Jun 2008 12:34:29 +0000 Subject: [PATCH] Fixed #7521 -- Added the ability to customize ROOT_URLCONF for the duration of a TestCase. Thanks to Mark Fargas (telenieko) for his work on this patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7805 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/formtools/tests.py | 6 +--- django/core/urlresolvers.py | 5 +++ django/test/testcases.py | 25 +++++++++++++++ docs/testing.txt | 31 +++++++++++++++++++ .../test_client_regress/models.py | 19 ++++++++++++ 5 files changed, 81 insertions(+), 5 deletions(-) diff --git a/django/contrib/formtools/tests.py b/django/contrib/formtools/tests.py index 143857ad58..ba241e9dc6 100644 --- a/django/contrib/formtools/tests.py +++ b/django/contrib/formtools/tests.py @@ -21,18 +21,14 @@ class TestForm(forms.Form): class PreviewTests(TestCase): + urls = 'django.contrib.formtools.test_urls' def setUp(self): - self._old_root_urlconf = settings.ROOT_URLCONF - settings.ROOT_URLCONF = 'django.contrib.formtools.test_urls' # Create a FormPreview instance to share between tests self.preview = preview.FormPreview(TestForm) input_template = '' self.input = input_template % (self.preview.unused_name('stage'), "%d") - def tearDown(self): - settings.ROOT_URLCONF = self._old_root_urlconf - def test_unused_name(self): """ Verifies name mangling to get uniue field name. diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py index 2ad63bfc7d..ff0bcbcfea 100644 --- a/django/core/urlresolvers.py +++ b/django/core/urlresolvers.py @@ -296,3 +296,8 @@ def reverse(viewname, urlconf=None, args=None, kwargs=None): kwargs = kwargs or {} return iri_to_uri(u'/' + get_resolver(urlconf).reverse(viewname, *args, **kwargs)) +def clear_url_caches(): + global _resolver_cache + global _callable_cache + _resolver_cache.clear() + _callable_cache.clear() diff --git a/django/test/testcases.py b/django/test/testcases.py index ee83b960a6..3bad3995bb 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -4,10 +4,12 @@ from urlparse import urlsplit, urlunsplit from django.http import QueryDict from django.db import transaction +from django.conf import settings from django.core import mail from django.core.management import call_command from django.test import _doctest as doctest from django.test.client import Client +from django.core.urlresolvers import clear_url_caches normalize_long_ints = lambda s: re.sub(r'(?