diff options
| author | Tobias McNulty <tobias@caktusgroup.com> | 2016-06-03 15:02:38 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-06-20 11:07:46 -0400 |
| commit | 17e661641ddaf8266e7430d83cfb2039abc55df7 (patch) | |
| tree | faab4310a86fed5682ff343efcffc9a9816a2eb3 /tests/test_client_regress | |
| parent | 00551c3eff5cedcb9cc7ce5af97b948d62713d97 (diff) | |
Refs #26666 -- Added ALLOWED_HOSTS validation when running tests.
Also used ALLOWED_HOSTS to check for external hosts in assertRedirects().
Diffstat (limited to 'tests/test_client_regress')
| -rw-r--r-- | tests/test_client_regress/tests.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py index ea33d66a02..d03b2d14e9 100644 --- a/tests/test_client_regress/tests.py +++ b/tests/test_client_regress/tests.py @@ -15,7 +15,8 @@ from django.template import ( ) from django.template.response import SimpleTemplateResponse from django.test import ( - Client, SimpleTestCase, TestCase, ignore_warnings, override_settings, + Client, SimpleTestCase, TestCase, ignore_warnings, modify_settings, + override_settings, ) from django.test.client import RedirectCycleError, RequestFactory, encode_file from django.test.utils import ContextList, str_prefix @@ -455,6 +456,7 @@ class AssertRedirectsTests(SimpleTestCase): self.assertRedirects(response, '/no_template_view/', 302, 200) self.assertEqual(len(response.redirect_chain), 3) + @modify_settings(ALLOWED_HOSTS={'append': 'otherserver'}) def test_redirect_to_different_host(self): "The test client will preserve scheme, host and port changes" response = self.client.get('/redirect_other_host/', follow=True) @@ -467,6 +469,12 @@ class AssertRedirectsTests(SimpleTestCase): self.assertEqual(response.request.get('wsgi.url_scheme'), 'https') self.assertEqual(response.request.get('SERVER_NAME'), 'otherserver') self.assertEqual(response.request.get('SERVER_PORT'), '8443') + # assertRedirects() can follow redirect to 'otherserver' too. + response = self.client.get('/redirect_other_host/', follow=False) + self.assertRedirects( + response, 'https://otherserver:8443/no_template_view/', + status_code=302, target_status_code=200 + ) def test_redirect_chain_on_non_redirect_page(self): "An assertion is raised if the original page couldn't be retrieved as expected" |
