mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Refs #23960 -- Removed the host parameter for SimpleTestCase.assertRedirects().
Per deprecation timeline.
This commit is contained in:
parent
f032bbc8b1
commit
0f454f5d4d
@ -39,7 +39,7 @@ from django.utils.decorators import classproperty
|
|||||||
from django.utils.deprecation import RemovedInDjango20Warning
|
from django.utils.deprecation import RemovedInDjango20Warning
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_text
|
||||||
from django.utils.six.moves.urllib.parse import (
|
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.utils.six.moves.urllib.request import url2pathname
|
||||||
from django.views.static import serve
|
from django.views.static import serve
|
||||||
@ -245,7 +245,7 @@ class SimpleTestCase(unittest.TestCase):
|
|||||||
return modify_settings(**kwargs)
|
return modify_settings(**kwargs)
|
||||||
|
|
||||||
def assertRedirects(self, response, expected_url, status_code=302,
|
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):
|
fetch_redirect_response=True):
|
||||||
"""Asserts that a response redirected to a specific URL, and that the
|
"""Asserts that a response redirected to a specific URL, and that the
|
||||||
redirect URL can be loaded.
|
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
|
TestClient to do a request (use fetch_redirect_response=False to check
|
||||||
such links without fetching them).
|
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:
|
if msg_prefix:
|
||||||
msg_prefix += ": "
|
msg_prefix += ": "
|
||||||
|
|
||||||
@ -324,19 +318,6 @@ class SimpleTestCase(unittest.TestCase):
|
|||||||
% (path, redirect_response.status_code, target_status_code)
|
% (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(
|
self.assertEqual(
|
||||||
url, expected_url,
|
url, expected_url,
|
||||||
msg_prefix + "Response redirected to '%s', expected '%s'" % (url, expected_url)
|
msg_prefix + "Response redirected to '%s', expected '%s'" % (url, expected_url)
|
||||||
|
@ -243,3 +243,7 @@ these features.
|
|||||||
* The ``django.forms.extras`` package is removed.
|
* The ``django.forms.extras`` package is removed.
|
||||||
|
|
||||||
* The ``assignment_tag`` helper 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.
|
||||||
|
@ -1479,11 +1479,6 @@ your test suite.
|
|||||||
the original request's scheme is used. If present, the scheme in
|
the original request's scheme is used. If present, the scheme in
|
||||||
``expected_url`` is the one used to make the comparisons to.
|
``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)
|
.. method:: SimpleTestCase.assertHTMLEqual(html1, html2, msg=None)
|
||||||
|
|
||||||
Asserts that the strings ``html1`` and ``html2`` are equal. The comparison
|
Asserts that the strings ``html1`` and ``html2`` are equal. The comparison
|
||||||
|
@ -15,14 +15,12 @@ from django.template import (
|
|||||||
)
|
)
|
||||||
from django.template.response import SimpleTemplateResponse
|
from django.template.response import SimpleTemplateResponse
|
||||||
from django.test import (
|
from django.test import (
|
||||||
Client, SimpleTestCase, TestCase, ignore_warnings, modify_settings,
|
Client, SimpleTestCase, TestCase, modify_settings, override_settings,
|
||||||
override_settings,
|
|
||||||
)
|
)
|
||||||
from django.test.client import RedirectCycleError, RequestFactory, encode_file
|
from django.test.client import RedirectCycleError, RequestFactory, encode_file
|
||||||
from django.test.utils import ContextList, str_prefix
|
from django.test.utils import ContextList, str_prefix
|
||||||
from django.urls import NoReverseMatch, reverse
|
from django.urls import NoReverseMatch, reverse
|
||||||
from django.utils._os import upath
|
from django.utils._os import upath
|
||||||
from django.utils.deprecation import RemovedInDjango20Warning
|
|
||||||
from django.utils.translation import ugettext_lazy
|
from django.utils.translation import ugettext_lazy
|
||||||
|
|
||||||
from .models import CustomUser
|
from .models import CustomUser
|
||||||
@ -514,15 +512,6 @@ class AssertRedirectsTests(SimpleTestCase):
|
|||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
self.assertRedirects(response, 'http://testserver/secure_view/', status_code=302)
|
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')
|
@override_settings(ROOT_URLCONF='test_client_regress.urls')
|
||||||
class AssertFormErrorTests(SimpleTestCase):
|
class AssertFormErrorTests(SimpleTestCase):
|
||||||
|
Loading…
Reference in New Issue
Block a user