Clean up test utils; write to media dir

This commit is contained in:
Matthew Tretter 2012-12-04 23:11:05 -05:00
parent 7f11f44c67
commit 938e2e178b
4 changed files with 9 additions and 22 deletions

3
.gitignore vendored
View file

@ -7,4 +7,5 @@
MANIFEST
build
dist
/tests/media
/tests/media/*
!/tests/media/lenna.png

BIN
tests/media/lenna.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 KiB

View file

@ -2,12 +2,11 @@ from bs4 import BeautifulSoup
from django.template import Context, Template, TemplateSyntaxError
from nose.tools import eq_, assert_not_in, raises, assert_not_equal
from . import imagespecs
from .utils import get_named_image_file
from .utils import get_image_file
def render_tag(ttag):
img = get_named_image_file()
img.name = 'tmp' # FIXME: If we don't do this, we get a SuspiciousOperation
img = get_image_file()
template = Template('{%% load imagekit %%}%s' % ttag)
context = Context({'img': img})
return template.render(context)

View file

@ -1,14 +1,12 @@
import os
from django.conf import settings
from django.core.files.base import ContentFile
from imagekit.lib import Image, StringIO
from tempfile import NamedTemporaryFile
from .models import Photo
import pickle
from .models import Photo
def _get_image_file(file_factory):
def get_image_file():
"""
See also:
@ -16,19 +14,8 @@ def _get_image_file(file_factory):
http://sipi.usc.edu/database/database.php?volume=misc&image=12
"""
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'assets', 'lenna-800x600-white-border.jpg')
tmp = file_factory()
tmp.write(open(path, 'r+b').read())
tmp.seek(0)
return tmp
def get_image_file():
return _get_image_file(StringIO)
def get_named_image_file():
return _get_image_file(NamedTemporaryFile)
path = os.path.join(settings.MEDIA_ROOT, 'lenna.png')
return open(path, 'r+b')
def create_image():