diff options
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): |
