diff options
| author | Jannis Leidel <jannis@leidel.info> | 2011-05-17 10:16:12 +0000 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2011-05-17 10:16:12 +0000 |
| commit | 578a31fea3cb439f6bfeeb7825ac835820a9f58c (patch) | |
| tree | d900f07487179adabeb43da6a1b5cafdab003685 /tests | |
| parent | 9ad005ec1c50e254dd61bbb1760c524aa01a79e2 (diff) | |
Fixed #15921 -- Refined naturaltime filter added in r16071 to use timesince and timeuntil filters as fallbacks instead of date filter.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16233 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/humanize/tests.py | 67 |
1 files changed, 42 insertions, 25 deletions
diff --git a/tests/regressiontests/humanize/tests.py b/tests/regressiontests/humanize/tests.py index bc1bf26636..370575a84a 100644 --- a/tests/regressiontests/humanize/tests.py +++ b/tests/regressiontests/humanize/tests.py @@ -89,31 +89,6 @@ class HumanizeTests(TestCase): someday_result, u"I'm not a date value", None) self.humanize_tester(test_list, result_list, 'naturalday') - def test_naturaltime(self): - from django.template import defaultfilters - now = datetime.now() - seconds_ago = now - timedelta(seconds=30) - a_minute_ago = now - timedelta(minutes=1, seconds=30) - minutes_ago = now - timedelta(minutes=2) - an_hour_ago = now - timedelta(hours=1, minutes=30, seconds=30) - hours_ago = now - timedelta(hours=23, minutes=50, seconds=50) - - test_list = (now, a_minute_ago, an_hour_ago) - result_list = (_(u'now'), _(u'a minute ago'), _(u'an hour ago')) - self.humanize_tester(test_list, result_list, 'naturaltime') - - t = Template('{{ seconds_ago|%s }}' % 'naturaltime') - rendered = t.render(Context(locals())).strip() - self.assertTrue(u' seconds ago' in rendered) - - t = Template('{{ minutes_ago|%s }}' % 'naturaltime') - rendered = t.render(Context(locals())).strip() - self.assertTrue(u' minutes ago' in rendered) - - t = Template('{{ hours_ago|%s }}' % 'naturaltime') - rendered = t.render(Context(locals())).strip() - self.assertTrue(u' hours ago' in rendered) - def test_naturalday_tz(self): from django.contrib.humanize.templatetags.humanize import naturalday @@ -130,3 +105,45 @@ class HumanizeTests(TestCase): # As 24h of difference they will never be the same self.assertNotEqual(naturalday_one, naturalday_two) + + def test_naturaltime(self): + now = datetime.now() + test_list = [ + now, + now - timedelta(seconds=1), + now - timedelta(seconds=30), + now - timedelta(minutes=1, seconds=30), + now - timedelta(minutes=2), + now - timedelta(hours=1, minutes=30, seconds=30), + now - timedelta(hours=23, minutes=50, seconds=50), + now - timedelta(days=1), + now - timedelta(days=500), + now + timedelta(seconds=1), + now + timedelta(seconds=30), + now + timedelta(minutes=1, seconds=30), + now + timedelta(minutes=2), + now + timedelta(hours=1, minutes=30, seconds=30), + now + timedelta(hours=23, minutes=50, seconds=50), + now + timedelta(days=1), + now + timedelta(days=500), + ] + result_list = [ + 'now', + 'a second ago', + '30 seconds ago', + 'a minute ago', + '2 minutes ago', + 'an hour ago', + '23 hours ago', + '1 day ago', + '1 year, 4 months ago', + 'a second from now', + '30 seconds from now', + 'a minute from now', + '2 minutes from now', + 'an hour from now', + '23 hours from now', + '1 day from now', + '1 year, 4 months from now', + ] + self.humanize_tester(test_list, result_list, 'naturaltime') |
