summaryrefslogtreecommitdiff
path: root/tests/test_client
diff options
context:
space:
mode:
authorAnv3sh <anveshgreat11@gmail.com>2022-06-16 21:34:13 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-06-20 08:51:26 +0200
commitd7f5bfd241666c0a76e90208da1e9ef81aec44db (patch)
tree46ee5a0f15aead8589dcddc2b0d2c03ab431548a /tests/test_client
parent901a1691982cab76349d33e51b72c40120ec927a (diff)
downloaddjango-d7f5bfd241666c0a76e90208da1e9ef81aec44db.tar.gz
Fixed #32969 -- Fixed pickling HttpResponse and subclasses.
Diffstat (limited to 'tests/test_client')
-rw-r--r--tests/test_client/tests.py16
-rw-r--r--tests/test_client/urls.py1
-rw-r--r--tests/test_client/views.py5
3 files changed, 22 insertions, 0 deletions
diff --git a/tests/test_client/tests.py b/tests/test_client/tests.py
index ddc063f33d..57dc22ea0c 100644
--- a/tests/test_client/tests.py
+++ b/tests/test_client/tests.py
@@ -20,6 +20,7 @@ rather than the HTML rendered to the end-user.
"""
import itertools
+import pickle
import tempfile
from unittest import mock
@@ -80,6 +81,21 @@ class ClientTest(TestCase):
self.assertEqual(response.context["var"], "\xf2")
self.assertEqual(response.templates[0].name, "GET Template")
+ def test_pickling_response(self):
+ tests = ["/cbv_view/", "/get_view/"]
+ for url in tests:
+ with self.subTest(url=url):
+ response = self.client.get(url)
+ dump = pickle.dumps(response)
+ response_from_pickle = pickle.loads(dump)
+ self.assertEqual(repr(response), repr(response_from_pickle))
+
+ async def test_pickling_response_async(self):
+ response = await self.async_client.get("/async_get_view/")
+ dump = pickle.dumps(response)
+ response_from_pickle = pickle.loads(dump)
+ self.assertEqual(repr(response), repr(response_from_pickle))
+
def test_query_string_encoding(self):
# WSGI requires latin-1 encoded strings.
response = self.client.get("/get_view/?var=1\ufffd")
diff --git a/tests/test_client/urls.py b/tests/test_client/urls.py
index 2508346cf8..228e6c6a78 100644
--- a/tests/test_client/urls.py
+++ b/tests/test_client/urls.py
@@ -7,6 +7,7 @@ from . import views
urlpatterns = [
path("upload_view/", views.upload_view, name="upload_view"),
path("get_view/", views.get_view, name="get_view"),
+ path("cbv_view/", views.CBView.as_view()),
path("post_view/", views.post_view),
path("post_then_get_view/", views.post_then_get_view),
path("put_view/", views.put_view),
diff --git a/tests/test_client/views.py b/tests/test_client/views.py
index cff0463788..773e9e4e98 100644
--- a/tests/test_client/views.py
+++ b/tests/test_client/views.py
@@ -18,6 +18,7 @@ from django.shortcuts import render
from django.template import Context, Template
from django.test import Client
from django.utils.decorators import method_decorator
+from django.views.generic import TemplateView
def get_view(request):
@@ -418,3 +419,7 @@ class TwoArgException(Exception):
def two_arg_exception(request):
raise TwoArgException("one", "two")
+
+
+class CBView(TemplateView):
+ template_name = "base.html"