mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-23 00:10:24 +00:00
* 'new_api' of https://github.com/matthewwithanm/django-imagekit: (63 commits) fixing typo ImageSpecFile is a proper File Typo fix A list of ImageSpec names are now stored on the model. AdminThumbnailView is now AdminThumbnail Docs typo fix Adds explicit import of resize module to processors fixing bad import in docs adding name to AUTHORS adding test for new api Moved Crop and Fit to resize module. More docs edits. Typo fix. Installation instructions. Embracing duck typing. Documentation! Fix bug Bound fields are now cached on the model instance. Transpose processor now supports auto EXIF orientation. Fix filename formatting. ... Conflicts: AUTHORS README.rst docs/Makefile docs/conf.py docs/index.rst imagekit/__init__.py imagekit/defaults.py imagekit/management/commands/ikflush.py imagekit/models.py imagekit/options.py imagekit/processors.py imagekit/specs.py tests/core/tests.py
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
import os
|
|
import tempfile
|
|
import Image
|
|
from django.core.files.base import ContentFile
|
|
from django.db import models
|
|
from django.test import TestCase
|
|
from imagekit.models import ImageSpec
|
|
from imagekit.processors.resize import Crop
|
|
from imagekit.processors import Adjust
|
|
|
|
|
|
class Photo(models.Model):
|
|
original_image = models.ImageField(upload_to='photos')
|
|
thumbnail = ImageSpec([Adjust(contrast=1.2, sharpness=1.1), Crop(50, 50)],
|
|
image_field='original_image', format='JPEG', quality=90)
|
|
|
|
|
|
class IKTest(TestCase):
|
|
""" Base TestCase class. """
|
|
def generate_image(self):
|
|
tmp = tempfile.TemporaryFile()
|
|
Image.new('RGB', (800, 600)).save(tmp, 'JPEG')
|
|
tmp.seek(0)
|
|
return tmp
|
|
|
|
def setUp(self):
|
|
self.photo = Photo()
|
|
img = self.generate_image()
|
|
file = ContentFile(img.read())
|
|
self.photo.original_image = file
|
|
self.photo.original_image.save('test.jpeg', file)
|
|
self.photo.save()
|
|
img.close()
|
|
|
|
def test_save_image(self):
|
|
photo = Photo.objects.get(id=self.photo.id)
|
|
self.assertTrue(os.path.isfile(photo.original_image.path))
|
|
|
|
def test_setup(self):
|
|
self.assertEqual(self.photo.original_image.width, 800)
|
|
self.assertEqual(self.photo.original_image.height, 600)
|
|
|
|
def test_thumbnail_creation(self):
|
|
photo = Photo.objects.get(id=self.photo.id)
|
|
self.assertTrue(os.path.isfile(photo.thumbnail.file.name))
|
|
|
|
def test_thumbnail_size(self):
|
|
self.assertEqual(self.photo.thumbnail.width, 50)
|
|
self.assertEqual(self.photo.thumbnail.height, 50)
|
|
|
|
def test_thumbnail_source_file(self):
|
|
self.assertEqual(
|
|
self.photo.thumbnail.source_file, self.photo.original_image)
|