From 643413f654d52ca4d7bf6d9402ff9ca24d2ea635 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Sat, 6 May 2017 19:14:15 +0200 Subject: [1.11.x] Fixed #28148 -- Doc'd ImageField name validation concerns with the test client. Backport of bdf192c59357a0d8117f6f34c94fb32a51e7a774 from master --- docs/topics/testing/tools.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'docs/topics') diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt index 9b2e76cadc..1a2e9a847a 100644 --- a/docs/topics/testing/tools.txt +++ b/docs/topics/testing/tools.txt @@ -235,7 +235,15 @@ Use the ``django.test.Client`` class to make requests. file-processing code expects.) You may also provide any file-like object (e.g., :class:`~io.StringIO` or - :class:`~io.BytesIO`) as a file handle. + :class:`~io.BytesIO`) as a file handle. If you're uploading to an + :class:`~django.db.models.ImageField`, the object needs a ``name`` + attribute that passes the + :data:`~django.core.validators.validate_image_file_extension` validator. + For example:: + + >>> from io import BytesIO + >>> img = BytesIO(b'mybinarydata') + >>> img.name = 'myimage.jpg' Note that if you wish to use the same file handle for multiple ``post()`` calls then you will need to manually reset the file -- cgit v1.3