diff options
| author | SaJH <wogur981208@gmail.com> | 2024-09-11 21:23:23 +0900 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-10-16 11:52:22 +0200 |
| commit | 4a685bc0dca5298a7d5a4e162120a90cac7fd1a4 (patch) | |
| tree | 4ecc8f20d0fc48c0a95e13e02a91b7eec8a20fb0 /tests/httpwrappers | |
| parent | ec7d69035a408b357f1803ca05a7c991cc358cfa (diff) | |
Fixed #35727 -- Added HttpResponse.text property.
Signed-off-by: SaJH <wogur981208@gmail.com>
Diffstat (limited to 'tests/httpwrappers')
| -rw-r--r-- | tests/httpwrappers/tests.py | 23 |
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): |
