From 1392aff440bc8be26ac09062265269a0414d96d1 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Tue, 18 Aug 2015 12:07:13 -0400 Subject: [PATCH] Refs #21977 -- Removed SimpleTestCase.urls per deprecation timeline. --- django/test/testcases.py | 31 +++---------------------------- docs/releases/1.8.txt | 8 ++++---- docs/topics/testing/tools.txt | 32 ++------------------------------ tests/deprecation/tests.py | 27 --------------------------- 4 files changed, 9 insertions(+), 89 deletions(-) diff --git a/django/test/testcases.py b/django/test/testcases.py index 302c284edb..675ed7b6f7 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -26,7 +26,6 @@ from django.core.management import call_command from django.core.management.color import no_style from django.core.management.sql import emit_post_migrate_signal from django.core.servers.basehttp import WSGIRequestHandler, WSGIServer -from django.core.urlresolvers import clear_url_caches, set_urlconf from django.db import DEFAULT_DB_ALIAS, connection, connections, transaction from django.forms.fields import CharField from django.http import QueryDict @@ -39,9 +38,7 @@ from django.test.utils import ( ) from django.utils import six from django.utils.decorators import classproperty -from django.utils.deprecation import ( - RemovedInDjango20Warning, RemovedInDjango110Warning, -) +from django.utils.deprecation import RemovedInDjango20Warning from django.utils.encoding import force_text from django.utils.six.moves.urllib.parse import ( unquote, urlparse, urlsplit, urlunsplit, @@ -227,33 +224,11 @@ class SimpleTestCase(unittest.TestCase): * Clearing the mail test outbox. """ self.client = self.client_class() - self._urlconf_setup() mail.outbox = [] - def _urlconf_setup(self): - if hasattr(self, 'urls'): - warnings.warn( - "SimpleTestCase.urls is deprecated and will be removed in " - "Django 1.10. Use @override_settings(ROOT_URLCONF=...) " - "in %s instead." % self.__class__.__name__, - RemovedInDjango110Warning, stacklevel=2) - set_urlconf(None) - self._old_root_urlconf = settings.ROOT_URLCONF - settings.ROOT_URLCONF = self.urls - clear_url_caches() - def _post_teardown(self): - """Performs any post-test things. This includes: - - * Putting back the original ROOT_URLCONF if it was changed. - """ - self._urlconf_teardown() - - def _urlconf_teardown(self): - if hasattr(self, '_old_root_urlconf'): - set_urlconf(None) - settings.ROOT_URLCONF = self._old_root_urlconf - clear_url_caches() + """Perform any post-test things.""" + pass def settings(self, **kwargs): """ diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt index d13abcabfc..1e0c233cba 100644 --- a/docs/releases/1.8.txt +++ b/docs/releases/1.8.txt @@ -1307,10 +1307,10 @@ Built-in template context processors have been moved to ``django.test.SimpleTestCase.urls`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The attribute :attr:`SimpleTestCase.urls ` -for specifying URLconf configuration in tests has been deprecated and will be -removed in Django 1.10. Use :func:`@override_settings(ROOT_URLCONF=...) -` instead. +The attribute ``SimpleTestCase.urls`` for specifying URLconf configuration in +tests has been deprecated and will be removed in Django 1.10. Use +:func:`@override_settings(ROOT_URLCONF=...) ` +instead. ``prefix`` argument to :func:`~django.conf.urls.i18n.i18n_patterns` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt index 52a00b7ded..800f083765 100644 --- a/docs/topics/testing/tools.txt +++ b/docs/topics/testing/tools.txt @@ -639,7 +639,6 @@ functionality like: * The ability to run tests with :ref:`modified settings `. * Using the :attr:`~SimpleTestCase.client` :class:`~django.test.Client`. -* Custom test-time :attr:`URL maps `. If you need any of the other more complex and heavyweight Django-specific features like: @@ -1080,39 +1079,12 @@ using multiple databases and set :attr:`multi_db=True URLconf configuration ~~~~~~~~~~~~~~~~~~~~~ -.. attribute:: SimpleTestCase.urls - -.. deprecated:: 1.8 - - Use ``@override_settings(ROOT_URLCONF=...)`` instead for URLconf - configuration. - If your application provides views, you may want to include tests that use the test client to exercise those views. However, an end user is free to deploy the views in your application at any URL of their choosing. This means that your tests can't rely upon the fact that your views will be available at a -particular URL. - -In order to provide a reliable URL space for your test, -``django.test.*TestCase`` classes provide the ability to customize the URLconf -configuration for the duration of the execution of a test suite. If your -``*TestCase`` instance defines an ``urls`` attribute, the ``*TestCase`` will use -the value of that attribute as the :setting:`ROOT_URLCONF` for the duration -of that test. - -For example:: - - from django.test import TestCase - - class TestMyViews(TestCase): - urls = 'myapp.test_urls' - - def test_index_page_view(self): - # Here you'd test your view using ``Client``. - call_some_test_code() - -This test case will use the contents of ``myapp.test_urls`` as the -URLconf for the duration of the test case. +particular URL. Decorate your test class or test method with +``@override_settings(ROOT_URLCONF=...)`` for URLconf configuration. .. _emptying-test-outbox: diff --git a/tests/deprecation/tests.py b/tests/deprecation/tests.py index 8f4ccf4eb5..e1ff2c8d2c 100644 --- a/tests/deprecation/tests.py +++ b/tests/deprecation/tests.py @@ -1,14 +1,11 @@ from __future__ import unicode_literals -import os -import unittest import warnings from django.test import SimpleTestCase from django.test.utils import reset_warning_registry from django.utils import six from django.utils.deprecation import RenameMethodsBase -from django.utils.encoding import force_text class RenameManagerMethods(RenameMethodsBase): @@ -173,27 +170,3 @@ class RenameMethodsTests(SimpleTestCase): '`DeprecatedMixin.old` is deprecated, use `new` instead.', '`RenamedMixin.old` is deprecated, use `new` instead.', ]) - - -class DeprecatingSimpleTestCaseUrls(unittest.TestCase): - - def test_deprecation(self): - """ - Ensure the correct warning is raised when SimpleTestCase.urls is used. - """ - class TempTestCase(SimpleTestCase): - urls = 'tests.urls' - - def test(self): - pass - - with warnings.catch_warnings(record=True) as recorded: - warnings.filterwarnings('always') - suite = unittest.TestLoader().loadTestsFromTestCase(TempTestCase) - with open(os.devnull, 'w') as devnull: - unittest.TextTestRunner(stream=devnull, verbosity=2).run(suite) - msg = force_text(recorded.pop().message) - self.assertEqual(msg, - "SimpleTestCase.urls is deprecated and will be removed in " - "Django 1.10. Use @override_settings(ROOT_URLCONF=...) " - "in TempTestCase instead.")