Refs #23960 -- Removed the host parameter for SimpleTestCase.assertRedirects().

Per deprecation timeline.
This commit is contained in:
Tim Graham 2016-12-16 18:13:34 -05:00
parent f032bbc8b1
commit 0f454f5d4d
4 changed files with 7 additions and 38 deletions

View File

@ -39,7 +39,7 @@ from django.utils.decorators import classproperty
from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.encoding import force_text
from django.utils.six.moves.urllib.parse import (
unquote, urljoin, urlparse, urlsplit, urlunsplit,
unquote, urljoin, urlparse, urlsplit,
)
from django.utils.six.moves.urllib.request import url2pathname
from django.views.static import serve
@ -245,7 +245,7 @@ class SimpleTestCase(unittest.TestCase):
return modify_settings(**kwargs)
def assertRedirects(self, response, expected_url, status_code=302,
target_status_code=200, host=None, msg_prefix='',
target_status_code=200, msg_prefix='',
fetch_redirect_response=True):
"""Asserts that a response redirected to a specific URL, and that the
redirect URL can be loaded.
@ -254,12 +254,6 @@ class SimpleTestCase(unittest.TestCase):
TestClient to do a request (use fetch_redirect_response=False to check
such links without fetching them).
"""
if host is not None:
warnings.warn(
"The host argument is deprecated and no longer used by assertRedirects",
RemovedInDjango20Warning, stacklevel=2
)
if msg_prefix:
msg_prefix += ": "
@ -324,19 +318,6 @@ class SimpleTestCase(unittest.TestCase):
% (path, redirect_response.status_code, target_status_code)
)
if url != expected_url:
# For temporary backwards compatibility, try to compare with a relative url
e_scheme, e_netloc, e_path, e_query, e_fragment = urlsplit(expected_url)
relative_url = urlunsplit(('', '', e_path, e_query, e_fragment))
if url == relative_url:
warnings.warn(
"assertRedirects had to strip the scheme and domain from the "
"expected URL, as it was always added automatically to URLs "
"before Django 1.9. Please update your expected URLs by "
"removing the scheme and domain.",
RemovedInDjango20Warning, stacklevel=2)
expected_url = relative_url
self.assertEqual(
url, expected_url,
msg_prefix + "Response redirected to '%s', expected '%s'" % (url, expected_url)

View File

@ -243,3 +243,7 @@ these features.
* The ``django.forms.extras`` package is removed.
* The ``assignment_tag`` helper is removed.
* The ``host`` argument to ``SimpleTestCase.assertsRedirects()`` is removed.
The compatibility layer which allows absolute URLs to be considered equal to
relative ones when the path is identical is also removed.

View File

@ -1479,11 +1479,6 @@ your test suite.
the original request's scheme is used. If present, the scheme in
``expected_url`` is the one used to make the comparisons to.
.. deprecated:: 1.9
The ``host`` argument is deprecated, as redirections are no longer
forced to be absolute URLs.
.. method:: SimpleTestCase.assertHTMLEqual(html1, html2, msg=None)
Asserts that the strings ``html1`` and ``html2`` are equal. The comparison

View File

@ -15,14 +15,12 @@ from django.template import (
)
from django.template.response import SimpleTemplateResponse
from django.test import (
Client, SimpleTestCase, TestCase, ignore_warnings, modify_settings,
override_settings,
Client, SimpleTestCase, TestCase, modify_settings, override_settings,
)
from django.test.client import RedirectCycleError, RequestFactory, encode_file
from django.test.utils import ContextList, str_prefix
from django.urls import NoReverseMatch, reverse
from django.utils._os import upath
from django.utils.deprecation import RemovedInDjango20Warning
from django.utils.translation import ugettext_lazy
from .models import CustomUser
@ -514,15 +512,6 @@ class AssertRedirectsTests(SimpleTestCase):
with self.assertRaises(AssertionError):
self.assertRedirects(response, 'http://testserver/secure_view/', status_code=302)
@ignore_warnings(category=RemovedInDjango20Warning)
def test_full_path_in_expected_urls(self):
"""
Specifying a full URL as assertRedirects expected_url still
work as backwards compatible behavior until Django 2.0.
"""
response = self.client.get('/redirect_view/')
self.assertRedirects(response, 'http://testserver/get_view/')
@override_settings(ROOT_URLCONF='test_client_regress.urls')
class AssertFormErrorTests(SimpleTestCase):