2009-01-04 16:29:53 +00:00
|
|
|
import os
|
|
|
|
|
import StringIO
|
2008-12-31 17:54:47 +00:00
|
|
|
import unittest
|
2009-01-04 16:29:53 +00:00
|
|
|
from django.conf import settings
|
|
|
|
|
from django.core.files.base import ContentFile
|
2009-01-04 22:14:13 +00:00
|
|
|
from django.db import models
|
2008-12-31 17:54:47 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
|
|
2009-01-04 18:40:22 +00:00
|
|
|
from models import IKModel
|
|
|
|
|
from specs import ImageSpec
|
2008-12-31 17:54:47 +00:00
|
|
|
|
2009-01-04 22:14:13 +00:00
|
|
|
from imagekit import Image
|
2008-12-31 17:54:47 +00:00
|
|
|
|
2009-01-04 22:14:13 +00:00
|
|
|
IMG_PATH = os.path.join(os.path.dirname(__file__), 'test.jpg')
|
2009-01-04 16:29:53 +00:00
|
|
|
|
2008-12-31 17:54:47 +00:00
|
|
|
class TestPhoto(IKModel):
|
|
|
|
|
""" Minimal ImageModel class for testing """
|
|
|
|
|
name = models.CharField(max_length=30)
|
|
|
|
|
|
2009-01-04 16:29:53 +00:00
|
|
|
|
|
|
|
|
class PLTest(TestCase):
|
|
|
|
|
""" Base TestCase class """
|
2008-12-31 17:54:47 +00:00
|
|
|
def setUp(self):
|
2009-01-04 22:14:13 +00:00
|
|
|
Image.new('RGB', (100, 100)).save(IMG_PATH, 'JPEG')
|
2009-01-04 16:29:53 +00:00
|
|
|
self.p = TestPhoto(name='landscape')
|
2009-01-04 22:14:13 +00:00
|
|
|
self.p.image.save(os.path.basename(IMG_PATH),
|
|
|
|
|
ContentFile(open(IMG_PATH, 'rb').read()))
|
2009-01-04 16:29:53 +00:00
|
|
|
self.p.save()
|
|
|
|
|
|
|
|
|
|
def test_setup(self):
|
|
|
|
|
self.assert_(self.p.image is not None)
|
|
|
|
|
self.assertEqual(self.p.image.width, 100 )
|
2008-12-31 17:54:47 +00:00
|
|
|
|
2009-01-04 16:29:53 +00:00
|
|
|
def test_accessor(self):
|
2009-01-04 22:14:13 +00:00
|
|
|
self.assertEqual(self.p.admin_thumbnail.width, 100)
|
2008-12-31 17:54:47 +00:00
|
|
|
|
|
|
|
|
def tearDown(self):
|
2009-01-04 22:14:13 +00:00
|
|
|
os.remove(IMG_PATH)
|
2009-01-04 16:29:53 +00:00
|
|
|
path = self.p.image.path
|
|
|
|
|
self.p.delete()
|
|
|
|
|
self.failIf(os.path.isfile(path))
|