django-imagekit/src/imagekit/tests.py

42 lines
1.1 KiB
Python
Raw Normal View History

import os
import StringIO
2008-12-31 17:54:47 +00:00
import unittest
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
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')
2008-12-31 17:54:47 +00:00
class TestPhoto(IKModel):
""" Minimal ImageModel class for testing """
name = models.CharField(max_length=30)
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')
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()))
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
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)
path = self.p.image.path
self.p.delete()
self.failIf(os.path.isfile(path))