summaryrefslogtreecommitdiff
path: root/tests/test_client/tests.py
diff options
context:
space:
mode:
authorTom <tom@tomforb.es>2017-05-22 11:49:39 +0100
committerTim Graham <timograham@gmail.com>2018-02-06 09:03:43 -0500
commit272f685794de0b8dead220ee57b30e65c9aa097c (patch)
treea3b3efebeba4df9eb9a6a8d865b0e0fb407e7c85 /tests/test_client/tests.py
parent0f0a07ac278dc2be6da81e519188f77e2a2a00cf (diff)
downloaddjango-272f685794de0b8dead220ee57b30e65c9aa097c.tar.gz
Fixed #27999 -- Added test client support for HTTP 307 and 308 redirects.
Diffstat (limited to 'tests/test_client/tests.py')
-rw-r--r--tests/test_client/tests.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test_client/tests.py b/tests/test_client/tests.py
index f7d32aa9cd..2643a279b1 100644
--- a/tests/test_client/tests.py
+++ b/tests/test_client/tests.py
@@ -19,6 +19,7 @@ testing against the contexts and templates produced by a view,
rather than the HTML rendered to the end-user.
"""
+import itertools
import tempfile
from django.contrib.auth.models import User
@@ -202,6 +203,39 @@ class ClientTest(TestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.request['PATH_INFO'], '/accounts/login/')
+ def test_follow_307_and_308_redirect(self):
+ """
+ A 307 or 308 redirect preserves the request method after the redirect.
+ """
+ methods = ('get', 'post', 'head', 'options', 'put', 'patch', 'delete', 'trace')
+ codes = (307, 308)
+ for method, code in itertools.product(methods, codes):
+ with self.subTest(method=method, code=code):
+ req_method = getattr(self.client, method)
+ response = req_method('/redirect_view_%s/' % code, data={'value': 'test'}, follow=True)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.request['PATH_INFO'], '/post_view/')
+ self.assertEqual(response.request['REQUEST_METHOD'], method.upper())
+
+ def test_follow_307_and_308_preserves_post_data(self):
+ for code in (307, 308):
+ with self.subTest(code=code):
+ response = self.client.post('/redirect_view_%s/' % code, data={'value': 'test'}, follow=True)
+ self.assertContains(response, 'test is the value')
+
+ def test_follow_307_and_308_preserves_put_body(self):
+ for code in (307, 308):
+ with self.subTest(code=code):
+ response = self.client.put('/redirect_view_%s/?to=/put_view/' % code, data='a=b', follow=True)
+ self.assertContains(response, 'a=b is the body')
+
+ def test_follow_307_and_308_preserves_get_params(self):
+ data = {'var': 30, 'to': '/get_view/'}
+ for code in (307, 308):
+ with self.subTest(code=code):
+ response = self.client.get('/redirect_view_%s/' % code, data=data, follow=True)
+ self.assertContains(response, '30 is the value')
+
def test_redirect_http(self):
"GET a URL that redirects to an http URI"
response = self.client.get('/http_redirect_view/', follow=True)