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

Also improved the tests a little bit
pull/733/merge
Karl Hobley 2015-02-09 12:35:19 +00:00
rodzic 357a5c7449
commit 89bb3787e3
2 zmienionych plików z 14 dodań i 12 usunięć

Wyświetl plik

@ -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>')

Wyświetl plik

@ -2,6 +2,7 @@ import unittest
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
@ -188,13 +189,11 @@ class TestResolveModelString(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>')