def new_test_image():
"""
Creates an automatically generated test image.
In your testing `tearDown` method make sure to delete the test
image with the helper function `delete_test_image`.
The recommended way of using this helper function is as follows:
object_1.image_property.save(*new_test_image())
:return: Image name and image content file.
"""
warnings.warn(DeprecationWarning(
"new_test_image() is deprecated in favour of the get_sample_image() "
"context manager."), stacklevel=2)
image_name = 'test-{}.png'.format(uuid.uuid4())
image = Image.new('RGBA', size=(50, 50), color=(256, 0, 0))
ImageDraw.Draw(image)
byte_io = BytesIO()
image.save(byte_io, 'png')
byte_io.seek(0)
return image_name, ContentFile(byte_io.read(), image_name)
评论列表
文章目录