diff options
author | Nick Pope <nick@nickpope.me.uk> | 2022-07-22 20:58:38 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-01-05 19:25:25 +0100 |
commit | 57f5669d23fe17d940887e1e3ce694c7366a6330 (patch) | |
tree | bb9fd95da51a5e0a6465217e050fa9f1b7dce2cc /tests/test_client | |
parent | 95182a8593f87046999fc50c4f4161843d68273c (diff) | |
download | django-57f5669d23fe17d940887e1e3ce694c7366a6330.tar.gz |
Refs #33865 -- Improved implementation of FakePayload.
FakePayload is a wrapper around io.BytesIO and is expected to
masquerade as though it is a file-like object. For that reason it makes
sense that it should inherit the correct signatures from io.BytesIO
methods.
Crucially an implementation of .readline() is added which will be
necessary for this to behave more like the expected file-like objects as
LimitedStream will be changed to defer to the wrapped stream object
rather than rolling its own implementation for improved performance.
It should be safe to adjust these signatures because FakePayload is
only used internally within test client helpers, is undocumented, and
thus private.
Diffstat (limited to 'tests/test_client')
-rw-r--r-- | tests/test_client/test_fakepayload.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/tests/test_client/test_fakepayload.py b/tests/test_client/test_fakepayload.py index 191bf0e111..222bef3b00 100644 --- a/tests/test_client/test_fakepayload.py +++ b/tests/test_client/test_fakepayload.py @@ -5,7 +5,9 @@ from django.test.client import FakePayload class FakePayloadTests(SimpleTestCase): def test_write_after_read(self): payload = FakePayload() - payload.read() - msg = "Unable to write a payload after it's been read" - with self.assertRaisesMessage(ValueError, msg): - payload.write(b"abc") + for operation in [payload.read, payload.readline]: + with self.subTest(operation=operation.__name__): + operation() + msg = "Unable to write a payload after it's been read" + with self.assertRaisesMessage(ValueError, msg): + payload.write(b"abc") |