~widelands-dev/widelands-website/django_staticfiles

65 by Holger Rapp
Added custom date format
1
#!/usr/bin/python -tt
2
3
import unittest
4
import datetime
5
6
from templatetags.custom_date import do_custom_date
7
438.1.6 by franku
run the script
8
9
class _CustomDate_Base(unittest.TestCase):
10
65 by Holger Rapp
Added custom date format
11
    def setUp(self):
438.1.6 by franku
run the script
12
        self.date = datetime.datetime(2008, 4, 12, 12, 53, 21)
13
65 by Holger Rapp
Added custom date format
14
15
class TestCustomDate_PythonReplacement_ExceptCorrectResult(_CustomDate_Base):
438.1.6 by franku
run the script
16
65 by Holger Rapp
Added custom date format
17
    def runTest(self):
438.1.6 by franku
run the script
18
        rv = do_custom_date('r', self.date, 2)
19
        self.assertEqual('Sat, 12 Apr 2008 13:53:21 +0200', rv)
20
21
65 by Holger Rapp
Added custom date format
22
class TestCustomDate_PythonReplacement2_ExceptCorrectResult(_CustomDate_Base):
438.1.6 by franku
run the script
23
65 by Holger Rapp
Added custom date format
24
    def runTest(self):
438.1.6 by franku
run the script
25
        rv = do_custom_date('j.m.Y', self.date, 0)
26
        self.assertEqual('12.04.2008', rv)
27
28
65 by Holger Rapp
Added custom date format
29
class TestCustomDate_NaturalYearReplacementSame_ExceptCorrectResult(_CustomDate_Base):
438.1.6 by franku
run the script
30
65 by Holger Rapp
Added custom date format
31
    def runTest(self):
438.1.6 by franku
run the script
32
        now = datetime.datetime(2008, 4, 12, 12, 53, 21)
33
        rv = do_custom_date('m%NY(.Y)', self.date, 0, now)
34
        self.assertEqual('04', rv)
35
36
65 by Holger Rapp
Added custom date format
37
class TestCustomDate_NaturalYearReplacementDifferent_ExceptCorrectResult(_CustomDate_Base):
438.1.6 by franku
run the script
38
65 by Holger Rapp
Added custom date format
39
    def runTest(self):
438.1.6 by franku
run the script
40
        now = datetime.datetime(2009, 4, 12, 12, 53, 21)
41
        rv = do_custom_date('m%NY(.Y)', self.date, 0, now)
42
        self.assertEqual('04.2008', rv)
43
44
65 by Holger Rapp
Added custom date format
45
class TestCustomDate_NaturalYearReplacementTwice_ExceptCorrectResult(_CustomDate_Base):
438.1.6 by franku
run the script
46
65 by Holger Rapp
Added custom date format
47
    def runTest(self):
438.1.6 by franku
run the script
48
        now = datetime.datetime(2009, 4, 12, 12, 53, 21)
49
        rv = do_custom_date(
50
            r"m%NY(.Y) \b\l\a\h \m\o\r\e %NY(m.Y)", self.date, 0, now)
51
        self.assertEqual('04.2008 blah more 04.2008', rv)
52
53
65 by Holger Rapp
Added custom date format
54
class TestCustomDate_NaturalDayReplacementToday_ExceptCorrectResult(_CustomDate_Base):
438.1.6 by franku
run the script
55
65 by Holger Rapp
Added custom date format
56
    def runTest(self):
438.1.6 by franku
run the script
57
        now = datetime.datetime(2008, 4, 12, 0, 0, 21)
58
        rv = do_custom_date('j.m.y: %ND(j.m.y)', self.date, 0, now)
59
        self.assertEqual('12.04.08: today', rv)
60
61
65 by Holger Rapp
Added custom date format
62
class TestCustomDate_NaturalDayReplacementTomorrow_ExceptCorrectResult(_CustomDate_Base):
438.1.6 by franku
run the script
63
65 by Holger Rapp
Added custom date format
64
    def runTest(self):
438.1.6 by franku
run the script
65
        now = datetime.datetime(2008, 4, 11, 23, 59, 59)
66
        rv = do_custom_date('j.m.y: %ND(j.m.y)', self.date, 0, now)
67
        self.assertEqual('12.04.08: tomorrow', rv)
68
69
65 by Holger Rapp
Added custom date format
70
class TestCustomDate_NaturalDayReplacementYesterday_ExceptCorrectResult(_CustomDate_Base):
438.1.6 by franku
run the script
71
65 by Holger Rapp
Added custom date format
72
    def runTest(self):
438.1.6 by franku
run the script
73
        now = datetime.datetime(2008, 4, 13, 00, 00, 01)
74
        rv = do_custom_date('j.m.y: %ND(j.m.y)', self.date, 0, now)
75
        self.assertEqual('12.04.08: yesterday', rv)
76
77
65 by Holger Rapp
Added custom date format
78
class TestCustomDate_NaturalDayReplacementNoSpecialDay_ExceptCorrectResult(_CustomDate_Base):
438.1.6 by franku
run the script
79
65 by Holger Rapp
Added custom date format
80
    def runTest(self):
438.1.6 by franku
run the script
81
        now = datetime.datetime(2011, 4, 13, 00, 00, 01)
82
        rv = do_custom_date('j.m.y: %ND(j.m.Y)', self.date, 0, now)
83
        self.assertEqual('12.04.08: 12.04.2008', rv)
84
85
65 by Holger Rapp
Added custom date format
86
class TestCustomDate_RecursiveReplacementNoHit_ExceptCorrectResult(_CustomDate_Base):
438.1.6 by franku
run the script
87
65 by Holger Rapp
Added custom date format
88
    def runTest(self):
438.1.6 by franku
run the script
89
        now = datetime.datetime(2011, 4, 13, 00, 00, 01)
90
        rv = do_custom_date('j.m.y%ND(: j.m%NY(.Y))', self.date, 0, now)
91
        self.assertEqual('12.04.08: 12.04.2008', rv)
92
93
65 by Holger Rapp
Added custom date format
94
class TestCustomDate_RecursiveReplacementMissDayHitYear_ExceptCorrectResult(_CustomDate_Base):
438.1.6 by franku
run the script
95
65 by Holger Rapp
Added custom date format
96
    def runTest(self):
438.1.6 by franku
run the script
97
        now = datetime.datetime(2008, 9, 13, 00, 00, 01)
98
        rv = do_custom_date('j.m.y: %ND(j.m.%NY(Y))', self.date, 0, now)
99
        self.assertEqual('12.04.08: 12.04.', rv)
100
101
65 by Holger Rapp
Added custom date format
102
class TestCustomDate_RecursiveReplacementHitDayTodayHitYear_ExceptCorrectResult(_CustomDate_Base):
438.1.6 by franku
run the script
103
65 by Holger Rapp
Added custom date format
104
    def runTest(self):
438.1.6 by franku
run the script
105
        now = datetime.datetime(2008, 4, 12, 00, 00, 01)
106
        rv = do_custom_date('j.m.y: %ND(j.m.%NY(Y))', self.date, 0, now)
107
        self.assertEqual('12.04.08: today', rv)
65 by Holger Rapp
Added custom date format
108
109
110
#########
111
# FAILS #
112
#########
113
class TestCustomDate_FaultyDate_ExceptNoop(unittest.TestCase):
438.1.6 by franku
run the script
114
65 by Holger Rapp
Added custom date format
115
    def runTest(self):
438.1.6 by franku
run the script
116
        rv = do_custom_date('%c', (93, 93), 0)
117
        self.assertEqual('%c', rv)
65 by Holger Rapp
Added custom date format
118
119
if __name__ == '__main__':
120
    unittest.main()