summaryrefslogtreecommitdiff
path: root/tests/test_client
diff options
context:
space:
mode:
authorJaap Roes <jroes@leukeleu.nl>2021-09-23 12:18:15 +0200
committerCarlton Gibson <carlton@noumenal.es>2021-09-24 08:22:28 +0200
commitb1bf8c8a4ba04049dc19217bf0e876488a4fae3c (patch)
tree60747a28b5d370e23ac9ba46c62192f1f1ece7d8 /tests/test_client
parentf997c81472b96a1cf48a1a19a4fe974683455a50 (diff)
downloaddjango-b1bf8c8a4ba04049dc19217bf0e876488a4fae3c.tar.gz
Fixed #33132 -- Fixed test client handling of querystring only redirects.
Regression in 1e5aa8e1c79252cc810af21294a6e945d11d37b3.
Diffstat (limited to 'tests/test_client')
-rw-r--r--tests/test_client/tests.py7
-rw-r--r--tests/test_client/urls.py1
-rw-r--r--tests/test_client/views.py15
3 files changed, 23 insertions, 0 deletions
diff --git a/tests/test_client/tests.py b/tests/test_client/tests.py
index 3799dada91..e8ac4bfc00 100644
--- a/tests/test_client/tests.py
+++ b/tests/test_client/tests.py
@@ -291,6 +291,13 @@ class ClientTest(TestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.request['PATH_INFO'], '/accounts/login/')
+ def test_redirect_to_querystring_only(self):
+ """A URL that consists of a querystring only can be followed"""
+ response = self.client.post('/post_then_get_view/', follow=True)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.request['PATH_INFO'], '/post_then_get_view/')
+ self.assertEqual(response.content, b'The value of success is true.')
+
def test_follow_307_and_308_redirect(self):
"""
A 307 or 308 redirect preserves the request method after the redirect.
diff --git a/tests/test_client/urls.py b/tests/test_client/urls.py
index e2275797af..51f1fdbb72 100644
--- a/tests/test_client/urls.py
+++ b/tests/test_client/urls.py
@@ -8,6 +8,7 @@ urlpatterns = [
path('upload_view/', views.upload_view, name='upload_view'),
path('get_view/', views.get_view, name='get_view'),
path('post_view/', views.post_view),
+ path('post_then_get_view/', views.post_then_get_view),
path('put_view/', views.put_view),
path('trace_view/', views.trace_view),
path('header_view/', views.view_with_header),
diff --git a/tests/test_client/views.py b/tests/test_client/views.py
index 692581e892..fa2bac2943 100644
--- a/tests/test_client/views.py
+++ b/tests/test_client/views.py
@@ -85,6 +85,21 @@ def post_view(request):
return HttpResponse(t.render(c))
+def post_then_get_view(request):
+ """
+ A view that expects a POST request, returns a redirect response
+ to itself providing only a ?success=true querystring,
+ the value of this querystring is then rendered upon GET.
+ """
+ if request.method == 'POST':
+ return HttpResponseRedirect('?success=true')
+
+ t = Template('The value of success is {{ value }}.', name='GET Template')
+ c = Context({'value': request.GET.get('success', 'false')})
+
+ return HttpResponse(t.render(c))
+
+
def json_view(request):
"""
A view that expects a request with the header 'application/json' and JSON