Ticket #11321: 11321-r11173-test.diff

File 11321-r11173-test.diff, 2.2 KB (added by Sergio Oliveira, 15 years ago)

Unit tests

  • tests/regressiontests/humanize/timezone.py

     
     1from datetime import tzinfo, timedelta
     2
     3class FixedOffset(tzinfo):
     4    """Fixed offset in hours east from UTC."""
     5
     6    def __init__(self, offset, name):
     7        self.__offset = timedelta(hours=offset)
     8        self.__name = name
     9
     10    def utcoffset(self, dt):
     11        return self.__offset
     12
     13    def tzname(self, dt):
     14        return self.__name
     15
     16    def dst(self, dt):
     17        return timedelta(0)
  • tests/regressiontests/humanize/tests.py

     
    5959        tomorrow = today + timedelta(days=1)
    6060        someday = today - timedelta(days=10)
    6161        notdate = u"I'm not a date value"
    62 
     62       
    6363        test_list = (today, yesterday, tomorrow, someday, notdate)
    6464        someday_result = defaultfilters.date(someday)
    6565        result_list = (_(u'today'), _(u'yesterday'), _(u'tomorrow'),
    6666                       someday_result, u"I'm not a date value")
    6767        self.humanize_tester(test_list, result_list, 'naturalday')
     68   
     69    def test_naturalday_tz(self):
     70        from datetime import datetime
     71        from django.contrib.humanize.templatetags.humanize import naturalday
     72        from timezone import FixedOffset
     73       
     74        today = date.today()
     75       
     76        tz_one = FixedOffset(-12, 'TzOne')
     77        tz_two = FixedOffset(12, 'TzTwo')
    6878
     79        # Can be today or yesterday
     80        date_one = datetime(today.year, today.month, today.day, tzinfo=tz_one)
     81        naturalday_one = naturalday(date_one)
     82        # Can be today or tomorrow
     83        date_two = datetime(today.year, today.month, today.day, tzinfo=tz_two)
     84        naturalday_two = naturalday(date_two)
     85       
     86        # As 24h of difference they will never be the same   
     87        self.assertNotEqual(naturalday_one, naturalday_two)
     88
    6989if __name__ == '__main__':
    7090    unittest.main()
    7191
Back to Top