mirror of
https://github.com/django/django.git
synced 2024-11-25 07:59:34 +01:00
57f5669d23
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.
14 lines
518 B
Python
14 lines
518 B
Python
from django.test import SimpleTestCase
|
|
from django.test.client import FakePayload
|
|
|
|
|
|
class FakePayloadTests(SimpleTestCase):
|
|
def test_write_after_read(self):
|
|
payload = FakePayload()
|
|
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")
|