Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/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 ='RGBA', size=(10,10), color=(255, 255, 255)), 'png') = 'test_img.png'
img_dict = {
'image': SimpleUploadedFile(,,
return img_dict
Copy link

tanishiking commented May 4, 2015


from inmemory_image_generator import get_image_dict

class HogeTest(TestCase):
    def test_hoge(self):
        img_dict = get_image_dict()
        param = {
        form = HogeForm(param, img_dict)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment