Skip to content

Commit

Permalink
Create failing test to illustrate #97
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewwithanm committed Jul 18, 2012
1 parent 5e1757c commit 118f6e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
20 changes: 10 additions & 10 deletions tests/core/tests.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 9 additions & 1 deletion tests/core/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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.