Improvements to #620

As per https://github.com/torchbox/wagtail/pull/620#issuecomment-59203932

Also improved the tests a little bit
This commit is contained in:
Karl Hobley 2015-02-09 12:35:19 +00:00
parent ec341d76ab
commit dc70e2ac77
2 changed files with 14 additions and 12 deletions

View file

@ -35,6 +35,9 @@ def wagtail_version():
@register.filter
def richtext(value):
if value:
return mark_safe('<div class="rich-text">' + expand_db_html(value) + '</div>')
return ''
if value is not None:
html = expand_db_html(value)
else:
html = ''
return mark_safe('<div class="rich-text">' + html + '</div>')

View file

@ -1,5 +1,6 @@
from django.test import TestCase
from django.core.cache import cache
from django.utils.safestring import SafeString
from wagtail.wagtailcore.models import Page, Site
from wagtail.wagtailcore.templatetags.wagtailcore_tags import richtext
@ -146,13 +147,11 @@ class TestSiteRootPathsCache(TestCase):
class TestRichtextTag(TestCase):
def test_call_with_text(self):
result = richtext("Hello world!")
self.assertEqual(result, '<div class="rich-text">Hello world!</div>')
self.assertIsInstance(result, SafeString)
def test_typeerror(self):
"""`richtext` fails when it's called with `value` being not a string
or buffer.
"""
value = None
result = richtext(value)
self.assertEqual(result, '')
def test_call_with_none(self):
result = richtext(None)
self.assertEqual(result, '<div class="rich-text"></div>')