Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made the defaultfilters tests run on the actual filters, not on funct…

…ions imported from django.utils.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17054 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0a1a9b71fab11fd598e0699f09797eea55d42fce 1 parent eedc9cb
@aaugustin aaugustin authored
View
4 django/template/defaultfilters.py
@@ -581,7 +581,7 @@ def random(value):
random.is_safe = True
@register.filter("slice")
-def slice_(value, arg):
+def slice_filter(value, arg):
"""
Returns a slice of the list.
@@ -600,7 +600,7 @@ def slice_(value, arg):
except (ValueError, TypeError):
return value # Fail silently.
-slice_.is_safe = True
+slice_filter.is_safe = True
@register.filter
def unordered_list(value, autoescape=None):
View
51 tests/regressiontests/defaultfilters/tests.py
@@ -75,20 +75,20 @@ def test_capfirst(self):
self.assertEqual(capfirst(u'hello world'), u'Hello world')
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')
- self.assertEqual(escapejs(ur'\ : backslashes, too'),
+ self.assertEqual(escapejs_filter(ur'\ : 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')
- self.assertEqual(escapejs(ur'<script>and this</script>'),
+ self.assertEqual(escapejs_filter(ur'<script>and this</script>'),
u'\\u003Cscript\\u003Eand this\\u003C/script\\u003E')
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')
def test_fix_ampersands(self):
- self.assertEqual(fix_ampersands(u'Jack & Jill & Jeroboam'),
+ self.assertEqual(fix_ampersands_filter(u'Jack & Jill & Jeroboam'),
u'Jack &amp; Jill &amp; Jeroboam')
def test_linenumbers(self):
@@ -265,12 +265,12 @@ def test_force_escape(self):
u' \u0110\xc5\u20ac\xa3')
def test_linebreaks(self):
- self.assertEqual(linebreaks(u'line 1'), u'<p>line 1</p>')
- self.assertEqual(linebreaks(u'line 1\nline 2'),
+ self.assertEqual(linebreaks_filter(u'line 1'), u'<p>line 1</p>')
+ self.assertEqual(linebreaks_filter(u'line 1\nline 2'),
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>')
- 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>')
def test_linebreaksbr(self):
@@ -327,12 +327,12 @@ def test_length(self):
self.assertEqual(length_is(u'a', 10), False)
def test_slice(self):
- self.assertEqual(slice_(u'abcdefg', u'0'), u'')
- self.assertEqual(slice_(u'abcdefg', u'1'), u'a')
- self.assertEqual(slice_(u'abcdefg', u'-1'), u'abcdef')
- self.assertEqual(slice_(u'abcdefg', u'1:2'), u'b')
- self.assertEqual(slice_(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'), u'')
+ self.assertEqual(slice_filter(u'abcdefg', u'1'), u'a')
+ self.assertEqual(slice_filter(u'abcdefg', u'-1'), u'abcdef')
+ self.assertEqual(slice_filter(u'abcdefg', u'1:2'), u'b')
+ self.assertEqual(slice_filter(u'abcdefg', u'1:3'), u'bc')
+ self.assertEqual(slice_filter(u'abcdefg', u'0::2'), u'aceg')
def test_unordered_list(self):
self.assertEqual(unordered_list([u'item 1', u'item 2']),
@@ -411,22 +411,23 @@ def test_time(self):
def test_timesince(self):
# real testing is done in timesince.py, where we can provide our own 'now'
self.assertEqual(
- timesince(datetime.datetime.now() - datetime.timedelta(1)),
+ timesince_filter(datetime.datetime.now() - datetime.timedelta(1)),
u'1 day')
self.assertEqual(
- timesince(datetime.datetime(2005, 12, 29),
- datetime.datetime(2005, 12, 30)),
+ timesince_filter(datetime.datetime(2005, 12, 29),
+ datetime.datetime(2005, 12, 30)),
u'1 day')
def test_timeuntil(self):
self.assertEqual(
- timeuntil(datetime.datetime.now() + datetime.timedelta(1)),
+ timeuntil_filter(datetime.datetime.now() + datetime.timedelta(1)),
u'1 day')
- self.assertEqual(timeuntil(datetime.datetime(2005, 12, 30),
- datetime.datetime(2005, 12, 29)),
- u'1 day')
+ self.assertEqual(
+ timeuntil_filter(datetime.datetime(2005, 12, 30),
+ datetime.datetime(2005, 12, 29)),
+ u'1 day')
def test_default(self):
self.assertEqual(default(u"val", u"default"), u'val')
@@ -510,7 +511,7 @@ def test_pluralize(self):
self.assertEqual(pluralize(0,u'y,ies,error'), u'')
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):
# Filters shouldn't break if passed non-strings
@@ -533,7 +534,7 @@ def test_non_string_input(self):
self.assertEqual(center('123', 6), u' 123 ')
self.assertEqual(cut(123, '2'), u'13')
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(removetags(123, 'a'), u'123')
self.assertEqual(striptags(123), u'123')
Please sign in to comment.
Something went wrong with that request. Please try again.