Created
May 4, 2015 08:53
-
-
Save tanishiking/ff7336608fca2c889955 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from __future__ import unicode_literals | |
from django.core.files.uploadedfile import SimpleUploadedFile | |
from StringIO import StringIO | |
from PIL import Image | |
def get_image_dict(): | |
"""create inmemory dummy image for testing forms which have image field""" | |
img_file = StringIO() | |
img = Image.new('RGBA', size=(10,10), color=(255, 255, 255)) | |
img.save(img_file, 'png') | |
img_file.name = 'test_img.png' | |
img_file.seek(0) | |
img_dict = { | |
'image': SimpleUploadedFile( | |
img_file.name, | |
img_file.read(), | |
content_type='image/png')} | |
return img_dict | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage