Fixed #19489 -- Documented host parameter of assertRedirects().

Thanks mrknacky at gmail.com for the report and gajimenezmaggiora
for the draft patch.
This commit is contained in:
Tim Graham 2014-06-30 17:48:14 -04:00
parent 874053edf9
commit e3c7af18a3
1 changed files with 12 additions and 4 deletions

View File

@ -1368,16 +1368,24 @@ your test suite.
You can use this as a context manager in the same way as You can use this as a context manager in the same way as
:meth:`~SimpleTestCase.assertTemplateUsed`. :meth:`~SimpleTestCase.assertTemplateUsed`.
.. method:: SimpleTestCase.assertRedirects(response, expected_url, status_code=302, target_status_code=200, msg_prefix='', fetch_redirect_response=True) .. method:: SimpleTestCase.assertRedirects(response, expected_url, status_code=302, target_status_code=200, host=None, msg_prefix='', fetch_redirect_response=True)
Asserts that the response return a ``status_code`` redirect status, it Asserts that the response returned a ``status_code`` redirect status,
redirected to ``expected_url`` (including any GET data), and the final redirected to ``expected_url`` (including any ``GET`` data), and that the
page was received with ``target_status_code``. final page was received with ``target_status_code``.
If your request used the ``follow`` argument, the ``expected_url`` and If your request used the ``follow`` argument, the ``expected_url`` and
``target_status_code`` will be the url and status code for the final ``target_status_code`` will be the url and status code for the final
point of the redirect chain. point of the redirect chain.
The ``host`` argument sets a default host if ``expected_url`` doesn't
include one (e.g. ``"/bar/"``). If ``expected_url`` is an absolute URL that
includes a host (e.g. ``"http://testhost/bar/"``), the ``host`` parameter
will be ignored. Note that the test client doesn't support fetching external
URLs, but the parameter may be useful if you are testing with a custom HTTP
host (for example, initializing the test client with
``Client(HTTP_HOST="testhost")``.
.. versionadded:: 1.7 .. versionadded:: 1.7
If ``fetch_redirect_response`` is ``False``, the final page won't be If ``fetch_redirect_response`` is ``False``, the final page won't be