Last active
August 29, 2015 13:59
-
-
Save cansadadeserfeliz/10480812 to your computer and use it in GitHub Desktop.
Django: ImageField in unittests
This file contains hidden or 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
class Post(models.Model): | |
image = models.ImageField( | |
max_length=255, | |
upload_to='uploads/blog', | |
) |
This file contains hidden or 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
from django.test import TestCase | |
from django.core.urlresolvers import reverse | |
from blog.models import Post | |
from StringIO import StringIO | |
from PIL import Image | |
class BlogPostTestCase(TestCase): | |
def test_admin(self): | |
file_obj = StringIO() | |
image = Image.new('RGBA', size=(50, 50)) | |
image.save(file_obj, 'png') | |
file_obj.name = 'test.png' | |
file_obj.seek(0) | |
self.client.post( | |
reverse('admin:post_add'), | |
{ | |
'title': 'xxx', | |
'image': file_obj, | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment