Refs #31494 -- Added test for query strings for GET/HEAD requests when following HTTP 307/308 redirects in test client.
This commit is contained in:
parent
9d55ae00d3
commit
6425fd3124
|
@ -284,6 +284,20 @@ class ClientTest(TestCase):
|
|||
self.assertEqual(response.request['PATH_INFO'], '/post_view/')
|
||||
self.assertEqual(response.request['REQUEST_METHOD'], method.upper())
|
||||
|
||||
def test_follow_307_and_308_get_head_query_string(self):
|
||||
methods = ('get', 'head')
|
||||
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_query_string/' % code,
|
||||
data={'value': 'test'},
|
||||
follow=True,
|
||||
)
|
||||
self.assertRedirects(response, '/post_view/?hello=world', status_code=code)
|
||||
self.assertEqual(response.request['QUERY_STRING'], 'value=test')
|
||||
|
||||
def test_follow_307_and_308_preserves_post_data(self):
|
||||
for code in (307, 308):
|
||||
with self.subTest(code=code):
|
||||
|
|
|
@ -14,7 +14,15 @@ urlpatterns = [
|
|||
path('raw_post_view/', views.raw_post_view),
|
||||
path('redirect_view/', views.redirect_view),
|
||||
path('redirect_view_307/', views.method_saving_307_redirect_view),
|
||||
path(
|
||||
'redirect_view_307_query_string/',
|
||||
views.method_saving_307_redirect_query_string_view,
|
||||
),
|
||||
path('redirect_view_308/', views.method_saving_308_redirect_view),
|
||||
path(
|
||||
'redirect_view_308_query_string/',
|
||||
views.method_saving_308_redirect_query_string_view,
|
||||
),
|
||||
path('secure_view/', views.view_with_secure),
|
||||
path('permanent_redirect_view/', RedirectView.as_view(url='/get_view/', permanent=True)),
|
||||
path('temporary_redirect_view/', RedirectView.as_view(url='/get_view/', permanent=False)),
|
||||
|
|
|
@ -131,6 +131,14 @@ def redirect_view(request):
|
|||
return HttpResponseRedirect('/get_view/' + query)
|
||||
|
||||
|
||||
def method_saving_307_redirect_query_string_view(request):
|
||||
return HttpResponseRedirect('/post_view/?hello=world', status=307)
|
||||
|
||||
|
||||
def method_saving_308_redirect_query_string_view(request):
|
||||
return HttpResponseRedirect('/post_view/?hello=world', status=308)
|
||||
|
||||
|
||||
def _post_view_redirect(request, status_code):
|
||||
"""Redirect to /post_view/ using the status code."""
|
||||
redirect_to = request.GET.get('to', '/post_view/')
|
||||
|
|
Loading…
Reference in New Issue