mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-17 05:40:25 +00:00
Add test for imagekit.forms.fields.ProcessedImageField
This commit is contained in:
parent
f4917ab7ca
commit
b45a22abe6
2 changed files with 26 additions and 1 deletions
|
|
@ -5,6 +5,10 @@ from imagekit.models import ImageSpecField
|
|||
from imagekit.processors import Adjust, ResizeToFill, SmartCrop
|
||||
|
||||
|
||||
class ImageModel(models.Model):
|
||||
image = models.ImageField(upload_to='b')
|
||||
|
||||
|
||||
class Photo(models.Model):
|
||||
original_image = models.ImageField(upload_to='photos')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
from django import forms
|
||||
from django.core.files.base import File
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from imagekit import forms as ikforms
|
||||
from imagekit.processors import SmartCrop
|
||||
from nose.tools import eq_
|
||||
from . import imagespecs # noqa
|
||||
from .models import ProcessedImageFieldModel
|
||||
from .models import ProcessedImageFieldModel, ImageModel
|
||||
from .utils import get_image_file
|
||||
|
||||
|
||||
|
|
@ -13,3 +17,20 @@ def test_model_processedimagefield():
|
|||
|
||||
eq_(instance.processed.width, 50)
|
||||
eq_(instance.processed.height, 50)
|
||||
|
||||
|
||||
def test_form_processedimagefield():
|
||||
class TestForm(forms.ModelForm):
|
||||
image = ikforms.ProcessedImageField(spec_id='tests:testform_image',
|
||||
processors=[SmartCrop(50, 50)], format='JPEG')
|
||||
|
||||
class Meta:
|
||||
model = ImageModel
|
||||
|
||||
upload_file = get_image_file()
|
||||
file_dict = {'image': SimpleUploadedFile('abc.jpg', upload_file.read())}
|
||||
form = TestForm({}, file_dict)
|
||||
instance = form.save()
|
||||
|
||||
eq_(instance.image.width, 50)
|
||||
eq_(instance.image.height, 50)
|
||||
|
|
|
|||
Loading…
Reference in a new issue