Ticket #3311: natural_day_tests_v3.diff

File natural_day_tests_v3.diff, 2.5 KB (added by Jyrki Pulliainen <jyrki.pulliainen@…>, 18 years ago)

Tests against v3 patch

  • regressiontests/humanize/tests.py

     
     1# Quick tests for the humanize templatefilters (django.contrib.humanize)
     2
     3from django.template import Template, Context, add_to_builtins
     4from django.conf import settings
     5from django.utils.dateformat import DateFormat
     6from django.utils.translation import gettext as _
     7from datetime import timedelta, date
     8import unittest
     9
     10add_to_builtins('django.contrib.humanize.templatetags.humanize')
     11
     12class TemplateTest(unittest.TestCase):
     13    def test_naturalday(self):
     14       
     15        today = date.today()
     16        yesterday = today - timedelta(days=1)
     17        tomorrow = today + timedelta(days=1)
     18        someday = today - timedelta(days=10)
     19        notdate = "I'm not a date value"
     20
     21        t_today = Template('{{ today|naturalday }}')
     22        t_tomorrow = Template('{{ tomorrow|naturalday }}')
     23        t_yesterday = Template('{{ yesterday|naturalday }}')
     24        t_someday = Template('{{ someday|naturalday }}')
     25        t_someday_custom = Template('{{ someday|naturalday:"d.m.Y" }}')
     26        t_notdate = Template('{{ notdate|naturalday }}')
     27
     28        rendered_today = t_today.render(Context(locals())).strip()
     29        self.assertEqual(rendered_today, _('today'))
     30
     31        rendered_yesterday = t_yesterday.render(Context(locals())).strip()
     32        self.assertEqual(rendered_yesterday, _('yesterday'))
     33
     34        rendered_tomorrow = t_tomorrow.render(Context(locals())).strip()
     35        self.assertEqual(rendered_tomorrow, _('tomorrow'))
     36
     37        rendered_someday = t_someday.render(Context(locals())).strip()
     38        self.assertEqual(rendered_someday, DateFormat(someday).format(settings.DATE_FORMAT))
     39
     40        rendered_someday_custom = t_someday_custom.render(Context(locals())).strip()
     41        self.assertEqual(rendered_someday_custom, DateFormat(someday).format('d.m.Y'))
     42
     43        rendered_notdate = t_notdate.render(Context(locals())).strip()
     44        self.assertEqual(rendered_notdate, "I'm not a date value")
     45       
  • regressiontests/humanize/models.py

     
     1
Back to Top