Permalink
Browse files

Create failing test to illustrate #97

  • Loading branch information...
matthewwithanm committed Jul 18, 2012
1 parent 5e1757c commit 118f6e42064bd328c9ebf5834ae64341878ea4ec
Showing with 19 additions and 11 deletions.
  1. +10 −10 tests/core/tests.py
  2. +9 −1 tests/core/testutils.py
View
@@ -1,15 +1,13 @@
from __future__ import with_statement
import os
-import pickle
from django.test import TestCase
from imagekit import utils
-from imagekit.lib import StringIO
from .models import (Photo, AbstractImageModel, ConcreteImageModel1,
ConcreteImageModel2)
-from .testutils import create_photo
+from .testutils import create_photo, pickleback
class IKTest(TestCase):
@@ -66,15 +64,17 @@ def test_format_to_extension_no_init(self):
class PickleTest(TestCase):
- def test_source_file(self):
- ph = create_photo('pickletest.jpg')
- pickled_model = StringIO()
- pickle.dump(ph, pickled_model)
- pickled_model.seek(0)
- unpickled_model = pickle.load(pickled_model)
+ def test_model(self):
+ ph = pickleback(create_photo('pickletest.jpg'))
# This isn't supposed to error.
- unpickled_model.thumbnail.source_file
+ 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):
View
@@ -3,8 +3,9 @@
from django.core.files.base import ContentFile
-from imagekit.lib import Image
+from imagekit.lib import Image, StringIO
from .models import Photo
+import pickle
def generate_lenna():
@@ -36,3 +37,10 @@ def create_instance(model_class, image_name):
def create_photo(name):
return create_instance(Photo, name)
+
+
+def pickleback(obj):
+ pickled = StringIO()
+ pickle.dump(obj, pickled)
+ pickled.seek(0)
+ return pickle.load(pickled)

0 comments on commit 118f6e4

Please sign in to comment.