diff options
author | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-05-13 06:24:52 +0100 |
---|---|---|
committer | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-05-13 06:24:52 +0100 |
commit | b5093905759f246176ca9f8992fb99cbb4aa9739 (patch) | |
tree | f237f70d90f0bbf61fdf34061bcc0a34745d982e /imagekit/tests.py | |
parent | 8c68a8a0d749327eed5431a04f03f5ec4472969a (diff) | |
download | troggle-b5093905759f246176ca9f8992fb99cbb4aa9739.tar.gz troggle-b5093905759f246176ca9f8992fb99cbb4aa9739.tar.bz2 troggle-b5093905759f246176ca9f8992fb99cbb4aa9739.zip |
[svn] Switch from photologue to imagekit. Less bloat.
Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8338 by cucc @ 5/11/2009 3:08 AM
Diffstat (limited to 'imagekit/tests.py')
-rw-r--r-- | imagekit/tests.py | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/imagekit/tests.py b/imagekit/tests.py new file mode 100644 index 0000000..8c2eb5e --- /dev/null +++ b/imagekit/tests.py @@ -0,0 +1,86 @@ +import os +import tempfile +import unittest +from django.conf import settings +from django.core.files.base import ContentFile +from django.db import models +from django.test import TestCase + +from imagekit import processors +from imagekit.models import ImageModel +from imagekit.specs import ImageSpec +from imagekit.lib import Image + + +class ResizeToWidth(processors.Resize): + width = 100 + +class ResizeToHeight(processors.Resize): + height = 100 + +class ResizeToFit(processors.Resize): + width = 100 + height = 100 + +class ResizeCropped(ResizeToFit): + crop = ('center', 'center') + +class TestResizeToWidth(ImageSpec): + access_as = 'to_width' + processors = [ResizeToWidth] + +class TestResizeToHeight(ImageSpec): + access_as = 'to_height' + processors = [ResizeToHeight] + +class TestResizeCropped(ImageSpec): + access_as = 'cropped' + processors = [ResizeCropped] + +class TestPhoto(ImageModel): + """ Minimal ImageModel class for testing """ + image = models.ImageField(upload_to='images') + + class IKOptions: + spec_module = 'imagekit.tests' + + +class IKTest(TestCase): + """ Base TestCase class """ + def setUp(self): + # create a test image using tempfile and PIL + self.tmp = tempfile.TemporaryFile() + Image.new('RGB', (800, 600)).save(self.tmp, 'JPEG') + self.tmp.seek(0) + self.p = TestPhoto() + self.p.image.save(os.path.basename('test.jpg'), + ContentFile(self.tmp.read())) + self.p.save() + # destroy temp file + self.tmp.close() + + def test_setup(self): + self.assertEqual(self.p.image.width, 800) + self.assertEqual(self.p.image.height, 600) + + def test_to_width(self): + self.assertEqual(self.p.to_width.width, 100) + self.assertEqual(self.p.to_width.height, 75) + + def test_to_height(self): + self.assertEqual(self.p.to_height.width, 133) + self.assertEqual(self.p.to_height.height, 100) + + def test_crop(self): + self.assertEqual(self.p.cropped.width, 100) + self.assertEqual(self.p.cropped.height, 100) + + def test_url(self): + tup = (settings.MEDIA_URL, self.p._ik.cache_dir, 'test_to_width.jpg') + self.assertEqual(self.p.to_width.url, "%s%s/%s" % tup) + + def tearDown(self): + # make sure image file is deleted + path = self.p.image.path + self.p.delete() + self.failIf(os.path.isfile(path)) |