mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-17 05:40:25 +00:00
70 lines
2.3 KiB
Python
70 lines
2.3 KiB
Python
from __future__ import with_statement
|
|
|
|
import os
|
|
|
|
from django.test import TestCase
|
|
|
|
from .models import (Photo, AbstractImageModel, ConcreteImageModel1,
|
|
ConcreteImageModel2)
|
|
from .utils import create_photo, pickleback
|
|
|
|
|
|
class IKTest(TestCase):
|
|
|
|
def setUp(self):
|
|
self.photo = create_photo('test.jpg')
|
|
|
|
def test_nodelete(self):
|
|
"""Don't delete the spec file when the source image hasn't changed.
|
|
|
|
"""
|
|
filename = self.photo.thumbnail.file.name
|
|
self.photo.save()
|
|
self.assertTrue(self.photo.thumbnail.storage.exists(filename))
|
|
|
|
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):
|
|
""" Explicit and smart-cropped thumbnail size """
|
|
self.assertEqual(self.photo.thumbnail.width, 50)
|
|
self.assertEqual(self.photo.thumbnail.height, 50)
|
|
self.assertEqual(self.photo.smartcropped_thumbnail.width, 50)
|
|
self.assertEqual(self.photo.smartcropped_thumbnail.height, 50)
|
|
|
|
def test_thumbnail_source_file(self):
|
|
self.assertEqual(
|
|
self.photo.thumbnail.source_file, self.photo.original_image)
|
|
|
|
|
|
class PickleTest(TestCase):
|
|
def test_model(self):
|
|
ph = pickleback(create_photo('pickletest.jpg'))
|
|
|
|
# This isn't supposed to error.
|
|
ph.thumbnail.source_file
|
|
|
|
def test_field(self):
|
|
thumbnail = pickleback(create_photo('pickletest2.jpg').thumbnail)
|
|
|
|
# This isn't supposed to error.
|
|
thumbnail.source_file
|
|
|
|
|
|
class InheritanceTest(TestCase):
|
|
def test_abstract_base(self):
|
|
self.assertEqual(set(AbstractImageModel._ik.spec_fields),
|
|
set(['abstract_class_spec']))
|
|
self.assertEqual(set(ConcreteImageModel1._ik.spec_fields),
|
|
set(['abstract_class_spec', 'first_spec']))
|
|
self.assertEqual(set(ConcreteImageModel2._ik.spec_fields),
|
|
set(['abstract_class_spec', 'second_spec']))
|