Made the defaultfilters tests run on the actual filters, not on functions imported from django.utils.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17054 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
eedc9cb5f6
commit
0a1a9b71fa
|
@ -581,7 +581,7 @@ def random(value):
|
||||||
random.is_safe = True
|
random.is_safe = True
|
||||||
|
|
||||||
@register.filter("slice")
|
@register.filter("slice")
|
||||||
def slice_(value, arg):
|
def slice_filter(value, arg):
|
||||||
"""
|
"""
|
||||||
Returns a slice of the list.
|
Returns a slice of the list.
|
||||||
|
|
||||||
|
@ -600,7 +600,7 @@ def slice_(value, arg):
|
||||||
|
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
return value # Fail silently.
|
return value # Fail silently.
|
||||||
slice_.is_safe = True
|
slice_filter.is_safe = True
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def unordered_list(value, autoescape=None):
|
def unordered_list(value, autoescape=None):
|
||||||
|
|
|
@ -75,20 +75,20 @@ class DefaultFiltersTests(TestCase):
|
||||||
self.assertEqual(capfirst(u'hello world'), u'Hello world')
|
self.assertEqual(capfirst(u'hello world'), u'Hello world')
|
||||||
|
|
||||||
def test_escapejs(self):
|
def test_escapejs(self):
|
||||||
self.assertEqual(escapejs(u'"double quotes" and \'single quotes\''),
|
self.assertEqual(escapejs_filter(u'"double quotes" and \'single quotes\''),
|
||||||
u'\\u0022double quotes\\u0022 and \\u0027single quotes\\u0027')
|
u'\\u0022double quotes\\u0022 and \\u0027single quotes\\u0027')
|
||||||
self.assertEqual(escapejs(ur'\ : backslashes, too'),
|
self.assertEqual(escapejs_filter(ur'\ : backslashes, too'),
|
||||||
u'\\u005C : backslashes, too')
|
u'\\u005C : backslashes, too')
|
||||||
self.assertEqual(escapejs(u'and lots of whitespace: \r\n\t\v\f\b'),
|
self.assertEqual(escapejs_filter(u'and lots of whitespace: \r\n\t\v\f\b'),
|
||||||
u'and lots of whitespace: \\u000D\\u000A\\u0009\\u000B\\u000C\\u0008')
|
u'and lots of whitespace: \\u000D\\u000A\\u0009\\u000B\\u000C\\u0008')
|
||||||
self.assertEqual(escapejs(ur'<script>and this</script>'),
|
self.assertEqual(escapejs_filter(ur'<script>and this</script>'),
|
||||||
u'\\u003Cscript\\u003Eand this\\u003C/script\\u003E')
|
u'\\u003Cscript\\u003Eand this\\u003C/script\\u003E')
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
escapejs(u'paragraph separator:\u2029and line separator:\u2028'),
|
escapejs_filter(u'paragraph separator:\u2029and line separator:\u2028'),
|
||||||
u'paragraph separator:\\u2029and line separator:\\u2028')
|
u'paragraph separator:\\u2029and line separator:\\u2028')
|
||||||
|
|
||||||
def test_fix_ampersands(self):
|
def test_fix_ampersands(self):
|
||||||
self.assertEqual(fix_ampersands(u'Jack & Jill & Jeroboam'),
|
self.assertEqual(fix_ampersands_filter(u'Jack & Jill & Jeroboam'),
|
||||||
u'Jack & Jill & Jeroboam')
|
u'Jack & Jill & Jeroboam')
|
||||||
|
|
||||||
def test_linenumbers(self):
|
def test_linenumbers(self):
|
||||||
|
@ -265,12 +265,12 @@ class DefaultFiltersTests(TestCase):
|
||||||
u' \u0110\xc5\u20ac\xa3')
|
u' \u0110\xc5\u20ac\xa3')
|
||||||
|
|
||||||
def test_linebreaks(self):
|
def test_linebreaks(self):
|
||||||
self.assertEqual(linebreaks(u'line 1'), u'<p>line 1</p>')
|
self.assertEqual(linebreaks_filter(u'line 1'), u'<p>line 1</p>')
|
||||||
self.assertEqual(linebreaks(u'line 1\nline 2'),
|
self.assertEqual(linebreaks_filter(u'line 1\nline 2'),
|
||||||
u'<p>line 1<br />line 2</p>')
|
u'<p>line 1<br />line 2</p>')
|
||||||
self.assertEqual(linebreaks(u'line 1\rline 2'),
|
self.assertEqual(linebreaks_filter(u'line 1\rline 2'),
|
||||||
u'<p>line 1<br />line 2</p>')
|
u'<p>line 1<br />line 2</p>')
|
||||||
self.assertEqual(linebreaks(u'line 1\r\nline 2'),
|
self.assertEqual(linebreaks_filter(u'line 1\r\nline 2'),
|
||||||
u'<p>line 1<br />line 2</p>')
|
u'<p>line 1<br />line 2</p>')
|
||||||
|
|
||||||
def test_linebreaksbr(self):
|
def test_linebreaksbr(self):
|
||||||
|
@ -327,12 +327,12 @@ class DefaultFiltersTests(TestCase):
|
||||||
self.assertEqual(length_is(u'a', 10), False)
|
self.assertEqual(length_is(u'a', 10), False)
|
||||||
|
|
||||||
def test_slice(self):
|
def test_slice(self):
|
||||||
self.assertEqual(slice_(u'abcdefg', u'0'), u'')
|
self.assertEqual(slice_filter(u'abcdefg', u'0'), u'')
|
||||||
self.assertEqual(slice_(u'abcdefg', u'1'), u'a')
|
self.assertEqual(slice_filter(u'abcdefg', u'1'), u'a')
|
||||||
self.assertEqual(slice_(u'abcdefg', u'-1'), u'abcdef')
|
self.assertEqual(slice_filter(u'abcdefg', u'-1'), u'abcdef')
|
||||||
self.assertEqual(slice_(u'abcdefg', u'1:2'), u'b')
|
self.assertEqual(slice_filter(u'abcdefg', u'1:2'), u'b')
|
||||||
self.assertEqual(slice_(u'abcdefg', u'1:3'), u'bc')
|
self.assertEqual(slice_filter(u'abcdefg', u'1:3'), u'bc')
|
||||||
self.assertEqual(slice_(u'abcdefg', u'0::2'), u'aceg')
|
self.assertEqual(slice_filter(u'abcdefg', u'0::2'), u'aceg')
|
||||||
|
|
||||||
def test_unordered_list(self):
|
def test_unordered_list(self):
|
||||||
self.assertEqual(unordered_list([u'item 1', u'item 2']),
|
self.assertEqual(unordered_list([u'item 1', u'item 2']),
|
||||||
|
@ -411,20 +411,21 @@ class DefaultFiltersTests(TestCase):
|
||||||
def test_timesince(self):
|
def test_timesince(self):
|
||||||
# real testing is done in timesince.py, where we can provide our own 'now'
|
# real testing is done in timesince.py, where we can provide our own 'now'
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
timesince(datetime.datetime.now() - datetime.timedelta(1)),
|
timesince_filter(datetime.datetime.now() - datetime.timedelta(1)),
|
||||||
u'1 day')
|
u'1 day')
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
timesince(datetime.datetime(2005, 12, 29),
|
timesince_filter(datetime.datetime(2005, 12, 29),
|
||||||
datetime.datetime(2005, 12, 30)),
|
datetime.datetime(2005, 12, 30)),
|
||||||
u'1 day')
|
u'1 day')
|
||||||
|
|
||||||
def test_timeuntil(self):
|
def test_timeuntil(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
timeuntil(datetime.datetime.now() + datetime.timedelta(1)),
|
timeuntil_filter(datetime.datetime.now() + datetime.timedelta(1)),
|
||||||
u'1 day')
|
u'1 day')
|
||||||
|
|
||||||
self.assertEqual(timeuntil(datetime.datetime(2005, 12, 30),
|
self.assertEqual(
|
||||||
|
timeuntil_filter(datetime.datetime(2005, 12, 30),
|
||||||
datetime.datetime(2005, 12, 29)),
|
datetime.datetime(2005, 12, 29)),
|
||||||
u'1 day')
|
u'1 day')
|
||||||
|
|
||||||
|
@ -510,7 +511,7 @@ class DefaultFiltersTests(TestCase):
|
||||||
self.assertEqual(pluralize(0,u'y,ies,error'), u'')
|
self.assertEqual(pluralize(0,u'y,ies,error'), u'')
|
||||||
|
|
||||||
def test_phone2numeric(self):
|
def test_phone2numeric(self):
|
||||||
self.assertEqual(phone2numeric(u'0800 flowers'), u'0800 3569377')
|
self.assertEqual(phone2numeric_filter(u'0800 flowers'), u'0800 3569377')
|
||||||
|
|
||||||
def test_non_string_input(self):
|
def test_non_string_input(self):
|
||||||
# Filters shouldn't break if passed non-strings
|
# Filters shouldn't break if passed non-strings
|
||||||
|
@ -533,7 +534,7 @@ class DefaultFiltersTests(TestCase):
|
||||||
self.assertEqual(center('123', 6), u' 123 ')
|
self.assertEqual(center('123', 6), u' 123 ')
|
||||||
self.assertEqual(cut(123, '2'), u'13')
|
self.assertEqual(cut(123, '2'), u'13')
|
||||||
self.assertEqual(escape(123), u'123')
|
self.assertEqual(escape(123), u'123')
|
||||||
self.assertEqual(linebreaks(123), u'<p>123</p>')
|
self.assertEqual(linebreaks_filter(123), u'<p>123</p>')
|
||||||
self.assertEqual(linebreaksbr(123), u'123')
|
self.assertEqual(linebreaksbr(123), u'123')
|
||||||
self.assertEqual(removetags(123, 'a'), u'123')
|
self.assertEqual(removetags(123, 'a'), u'123')
|
||||||
self.assertEqual(striptags(123), u'123')
|
self.assertEqual(striptags(123), u'123')
|
||||||
|
|
Loading…
Reference in New Issue