Package pytils :: Package test :: Package templatetags :: Module test_dt
[hide private]

Source Code for Module pytils.test.templatetags.test_dt

 1  # -*- coding: utf-8 -*- 
 2  # pytils - simple processing for russian strings 
 3  # Copyright (C) 2006-2007  Yury Yurevich 
 4  # 
 5  # http://www.pyobject.ru/projects/pytils/ 
 6  # 
 7  # This program is free software; you can redistribute it and/or 
 8  # modify it under the terms of the GNU General Public License 
 9  # as published by the Free Software Foundation, version 2 
10  # of the License. 
11  # 
12  # This program is distributed in the hope that it will be useful, 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
15  # GNU General Public License for more details. 
16  """ 
17  Unit tests for pytils' dt templatetags for Django web framework 
18  """ 
19   
20  __id__ = __revision__ = "$Id: test_dt.py 102 2007-07-12 12:33:36Z the.pythy $" 
21  __url__ = "$URL: https://pythy.googlecode.com/svn/tags/pytils/0_2_2/pytils/test/templatetags/test_dt.py $" 
22   
23  import datetime 
24  from pytils.test.templatetags import helpers 
25   
26 -class DtDefaultTestCase(helpers.TemplateTagTestCase):
27
28 - def setUp(self):
29 self.date = datetime.datetime(2007, 1, 26, 15, 50) 30 self.date_before = datetime.datetime.now() - datetime.timedelta(1, 2000)
31
32 - def testLoad(self):
33 self.check_template_tag('load_tag', '{% load pytils_dt %}', {}, '')
34
35 - def testRuStrftimeFilter(self):
36 self.check_template_tag('ru_strftime_filter', 37 '{% load pytils_dt %}{{ val|ru_strftime:"%d %B %Y, %A" }}', 38 {'val': self.date}, 39 '26 января 2007, пятница')
40
42 self.check_template_tag('ru_strftime_inflected_filter', 43 '{% load pytils_dt %}{{ val|ru_strftime_inflected:"в %A, %d %B %Y" }}', 44 {'val': self.date}, 45 'в пятницу, 26 января 2007')
46
48 self.check_template_tag('ru_strftime_preposition_filter', 49 '{% load pytils_dt %}{{ val|ru_strftime_preposition:"%A, %d %B %Y" }}', 50 {'val': self.date}, 51 'в\xc2\xa0пятницу, 26 января 2007')
52
53 - def testDistanceFilter(self):
54 self.check_template_tag('distance_filter', 55 '{% load pytils_dt %}{{ val|distance_of_time }}', 56 {'val': self.date_before}, 57 'вчера') 58 59 self.check_template_tag('distance_filter', 60 '{% load pytils_dt %}{{ val|distance_of_time:3 }}', 61 {'val': self.date_before}, 62 '1 день 0 часов 33 минуты назад')
63 64 # без отладки, если ошибка -- по умолчанию пустая строка
65 - def testRuStrftimeError(self):
66 self.check_template_tag('ru_strftime_error', 67 '{% load pytils_dt %}{{ val|ru_strftime:"%d %B %Y" }}', 68 {'val': 1}, 69 '')
70 71 72 if __name__ == '__main__': 73 import unittest 74 unittest.main() 75