summaryrefslogtreecommitdiff
path: root/tests/httpwrappers/tests.py
diff options
context:
space:
mode:
authorSaJH <wogur981208@gmail.com>2024-09-11 21:23:23 +0900
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-10-16 11:52:22 +0200
commit4a685bc0dca5298a7d5a4e162120a90cac7fd1a4 (patch)
tree4ecc8f20d0fc48c0a95e13e02a91b7eec8a20fb0 /tests/httpwrappers/tests.py
parentec7d69035a408b357f1803ca05a7c991cc358cfa (diff)
Fixed #35727 -- Added HttpResponse.text property.
Signed-off-by: SaJH <wogur981208@gmail.com>
Diffstat (limited to 'tests/httpwrappers/tests.py')
-rw-r--r--tests/httpwrappers/tests.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py
index 2197c6f7ea..154e9517fe 100644
--- a/tests/httpwrappers/tests.py
+++ b/tests/httpwrappers/tests.py
@@ -530,6 +530,22 @@ class HttpResponseTests(SimpleTestCase):
headers={"Content-Type": "text/csv"},
)
+ def test_text_updates_when_content_updates(self):
+ response = HttpResponse("Hello, world!")
+ self.assertEqual(response.text, "Hello, world!")
+ response.content = "Updated content"
+ self.assertEqual(response.text, "Updated content")
+
+ def test_text_charset(self):
+ for content_type, content in [
+ (None, b"Ol\xc3\xa1 Mundo"),
+ ("text/plain; charset=utf-8", b"Ol\xc3\xa1 Mundo"),
+ ("text/plain; charset=iso-8859-1", b"Ol\xe1 Mundo"),
+ ]:
+ with self.subTest(content_type=content_type):
+ response = HttpResponse(content, content_type=content_type)
+ self.assertEqual(response.text, "Olá Mundo")
+
class HttpResponseSubclassesTests(SimpleTestCase):
def test_redirect(self):
@@ -756,6 +772,13 @@ class StreamingHttpResponseTests(SimpleTestCase):
with self.assertWarnsMessage(Warning, msg):
self.assertEqual(b"hello", await anext(aiter(r)))
+ def test_text_attribute_error(self):
+ r = StreamingHttpResponse(iter(["hello", "world"]))
+ msg = "This %s instance has no `text` attribute." % r.__class__.__name__
+
+ with self.assertRaisesMessage(AttributeError, msg):
+ r.text
+
class FileCloseTests(SimpleTestCase):
def setUp(self):