mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-16 21:30:23 +00:00
Add tests for generateimage template tag
Currently, these will fail because the temporary file cannot be pickled in order to generate a hash.
This commit is contained in:
parent
a499f5fbe6
commit
a5c33a4925
3 changed files with 74 additions and 0 deletions
1
setup.py
1
setup.py
|
|
@ -31,6 +31,7 @@ setup(
|
|||
zip_safe=False,
|
||||
include_package_data=True,
|
||||
tests_require=[
|
||||
'beautifulsoup4==4.1.3',
|
||||
'nose==1.2.1',
|
||||
'nose-progressive==1.3',
|
||||
'django-nose==1.1',
|
||||
|
|
|
|||
8
tests/imagespecs.py
Normal file
8
tests/imagespecs.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from imagekit import ImageSpec, register
|
||||
|
||||
|
||||
class TestSpec(ImageSpec):
|
||||
pass
|
||||
|
||||
|
||||
register.spec(TestSpec, 'testspec')
|
||||
65
tests/test_generateimage_tag.py
Normal file
65
tests/test_generateimage_tag.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
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
|
||||
|
||||
|
||||
def render_tag(ttag):
|
||||
img = get_named_image_file()
|
||||
img.name = 'tmp' # FIXME: If we don't do this, we get a SuspiciousOperation
|
||||
template = Template('{%% load imagekit %%}%s' % ttag)
|
||||
context = Context({'img': img})
|
||||
return template.render(context)
|
||||
|
||||
|
||||
def get_html_attrs(ttag):
|
||||
return BeautifulSoup(render_tag(ttag)).img.attrs
|
||||
|
||||
|
||||
def test_img_tag():
|
||||
ttag = r"""{% generateimage 'testspec' from=img %}"""
|
||||
attrs = get_html_attrs(ttag)
|
||||
expected_attrs = set(['src', 'width', 'height'])
|
||||
eq_(set(attrs.keys()), expected_attrs)
|
||||
for k in expected_attrs:
|
||||
assert_not_equal(attrs[k].strip(), '')
|
||||
|
||||
|
||||
def test_img_tag_attrs():
|
||||
ttag = r"""{% generateimage 'testspec' from=img with alt="Hello" %}"""
|
||||
attrs = get_html_attrs(ttag)
|
||||
eq_(attrs.get('alt'), 'Hello')
|
||||
|
||||
|
||||
@raises(TemplateSyntaxError)
|
||||
def test_dangling_with():
|
||||
ttag = r"""{% generateimage 'testspec' from=img with %}"""
|
||||
render_tag(ttag)
|
||||
|
||||
|
||||
@raises(TemplateSyntaxError)
|
||||
def test_with_assignment():
|
||||
"""
|
||||
You can either use generateimage as an assigment tag or specify html attrs,
|
||||
but not both.
|
||||
|
||||
"""
|
||||
ttag = r"""{% generateimage 'testspec' from=img with alt="Hello" as th %}"""
|
||||
render_tag(ttag)
|
||||
|
||||
|
||||
def test_single_dimension_attr():
|
||||
"""
|
||||
If you only provide one of width or height, the other should not be added.
|
||||
|
||||
"""
|
||||
ttag = r"""{% generateimage 'testspec' from=img with width="50" %}"""
|
||||
attrs = get_html_attrs(ttag)
|
||||
assert_not_in('height', attrs)
|
||||
|
||||
|
||||
def test_assignment_tag():
|
||||
ttag = r"""{% generateimage 'testspec' from=img as th %} {{ th.url }}"""
|
||||
html = render_tag(ttag)
|
||||
assert_not_equal(html.strip(), '')
|
||||
Loading…
Reference in a new issue