|
1
|
|
|
from qtodotxt2.lib import task_htmlizer, tasklib |
|
2
|
|
|
import unittest |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
class TestHtmlizer(unittest.TestCase): |
|
6
|
|
|
@classmethod |
|
7
|
|
|
def setUpClass(cls): |
|
8
|
|
|
cls.htmlizer = task_htmlizer.TaskHtmlizer() |
|
9
|
|
|
|
|
10
|
|
|
def test_01(self): |
|
11
|
|
|
# Simple task should return simple html |
|
12
|
|
|
task = tasklib.Task('this is my task') |
|
13
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
14
|
|
|
'<tt> </tt> this is my task') |
|
15
|
|
|
|
|
16
|
|
|
def test_02(self): |
|
17
|
|
|
# Test task with a single context at the end |
|
18
|
|
|
task = tasklib.Task('this is my task @context') |
|
19
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
20
|
|
|
'<tt> </tt> this is my task <font style="color:green">@context</font>') |
|
21
|
|
|
|
|
22
|
|
|
def test_03(self): |
|
23
|
|
|
# Test task with a single context at the center |
|
24
|
|
|
task = tasklib.Task('this is my task @context and some more words') |
|
25
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
26
|
|
|
'<tt> </tt> this is my task ' |
|
27
|
|
|
'<font style="color:green">@context</font> and some more words') |
|
28
|
|
|
|
|
29
|
|
|
def test_04(self): |
|
30
|
|
|
# Test task with a single project at the end |
|
31
|
|
|
task = tasklib.Task('this is my task +project') |
|
32
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
33
|
|
|
'<tt> </tt> this is my task ' |
|
34
|
|
|
'<font style="color:#64AAD0">+project</font>') |
|
35
|
|
|
|
|
36
|
|
|
def test_05(self): |
|
37
|
|
|
# Test task with a single project at the center |
|
38
|
|
|
task = tasklib.Task('this is my task +project and some more words') |
|
39
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
40
|
|
|
'<tt> </tt> this is my task ' |
|
41
|
|
|
'<font style="color:#64AAD0">+project</font> and ' |
|
42
|
|
|
'some more words') |
|
43
|
|
|
|
|
44
|
|
|
def test_06(self): |
|
45
|
|
|
# Test task with a single context and a single project |
|
46
|
|
|
task = tasklib.Task('this is my task @context and +project and some more words') |
|
47
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
48
|
|
|
'<tt> </tt> this is my task ' |
|
49
|
|
|
'<font style="color:green">@context</font> and ' |
|
50
|
|
|
'<font style="color:#64AAD0">+project</font> and some more words') |
|
51
|
|
|
|
|
52
|
|
|
def test_07(self): |
|
53
|
|
|
# Test task with a two contexts and a three projects |
|
54
|
|
|
task = tasklib.Task('this is my task @context1 and @context2 and ' |
|
55
|
|
|
'+project1 +project2 and +project3 some more ' |
|
56
|
|
|
'words') |
|
57
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
58
|
|
|
'<tt> </tt> this is my task ' |
|
59
|
|
|
'<font style="color:green">@context1</font> and ' |
|
60
|
|
|
'<font style="color:green">@context2</font> and ' |
|
61
|
|
|
'<font style="color:#64AAD0">+project1</font> ' |
|
62
|
|
|
'<font style="color:#64AAD0">+project2</font> and ' |
|
63
|
|
|
'<font style="color:#64AAD0">+project3</font>' |
|
64
|
|
|
' some more words') |
|
65
|
|
|
|
|
66
|
|
|
def test_08(self): |
|
67
|
|
|
# Test task with priority A |
|
68
|
|
|
task = tasklib.Task('(A) this is my task') |
|
69
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
70
|
|
|
'<font style="color:red"><tt>(A)</tt> </font>this is my task') |
|
71
|
|
|
|
|
72
|
|
|
def test_09(self): |
|
73
|
|
|
# Test task with priority B |
|
74
|
|
|
task = tasklib.Task('(B) this is my task') |
|
75
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
76
|
|
|
'<font style="color:green"><tt>(B)</tt> </font>this is my task') |
|
77
|
|
|
|
|
78
|
|
|
def test_10(self): |
|
79
|
|
|
# Test task with priority C |
|
80
|
|
|
task = tasklib.Task('(C) this is my task') |
|
81
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
82
|
|
|
'<font style="color:navy"><tt>(C)</tt> </font>this is my task') |
|
83
|
|
|
|
|
84
|
|
|
def test_11(self): |
|
85
|
|
|
# Test task with priority D |
|
86
|
|
|
task = tasklib.Task('(D) this is my task') |
|
87
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
88
|
|
|
'<tt>(D)</tt> this is my task') |
|
89
|
|
|
|
|
90
|
|
|
def test_12(self): |
|
91
|
|
|
# Test task with a valid due date |
|
92
|
|
|
task = tasklib.Task('this is my task due:2014-04-01') |
|
93
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
94
|
|
|
'<tt> </tt> this is my task <b>' |
|
95
|
|
|
'<font style="color:red">due:2014-04-01</font></b>') |
|
96
|
|
|
|
|
97
|
|
|
def test_13(self): |
|
98
|
|
|
# Test task with a valid due date and time |
|
99
|
|
|
task = tasklib.Task('this is my task due:2014-04-01T12:34') |
|
100
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
101
|
|
|
'<tt> </tt> this is my task <b>' |
|
102
|
|
|
'<font style="color:red">due:2014-04-01 12:34</font></b>') |
|
103
|
|
|
|
|
104
|
|
|
def test_14(self): |
|
105
|
|
|
# Test task with an invalid due date |
|
106
|
|
|
task = tasklib.Task('this is my task due:abc') |
|
107
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
108
|
|
|
'<tt> </tt> this is my task <b>' |
|
109
|
|
|
'<font style="color:red">*** due:abc Invalid date format, ' |
|
110
|
|
|
'expected yyyy-mm-dd or yyyy-mm-ddThh:mm. ***</font></b>') |
|
111
|
|
|
|
|
112
|
|
|
def test_15(self): |
|
113
|
|
|
# Test task with an invalid due date |
|
114
|
|
|
task = tasklib.Task('this is my task due:2014-04') |
|
115
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
116
|
|
|
'<tt> </tt> this is my task <b>' |
|
117
|
|
|
'<font style="color:red">*** due:2014-04 Invalid date format, ' |
|
118
|
|
|
'expected yyyy-mm-dd or yyyy-mm-ddThh:mm. ***</font></b>') |
|
119
|
|
|
|
|
120
|
|
|
def test_16(self): |
|
121
|
|
|
# Test task with an invalid due month |
|
122
|
|
|
task = tasklib.Task('this is my task due:2014-13-01') |
|
123
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
124
|
|
|
'<tt> </tt> this is my task <b>' |
|
125
|
|
|
'<font style="color:red">*** due:2014-13-01 Invalid date format, ' |
|
126
|
|
|
'expected yyyy-mm-dd or yyyy-mm-ddThh:mm. ***</font></b>') |
|
127
|
|
|
|
|
128
|
|
|
def test_17(self): |
|
129
|
|
|
# Test task with an invalid due day |
|
130
|
|
|
task = tasklib.Task('this is my task due:2014-04-31') |
|
131
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
132
|
|
|
'<tt> </tt> this is my task <b>' |
|
133
|
|
|
'<font style="color:red">*** due:2014-04-31 Invalid date format, ' |
|
134
|
|
|
'expected yyyy-mm-dd or yyyy-mm-ddThh:mm. ***</font></b>') |
|
135
|
|
|
|
|
136
|
|
|
def test_18(self): |
|
137
|
|
|
# Test task with space in due time instead of T. This is valid, but gives an unexpected result |
|
138
|
|
|
task = tasklib.Task('this is my task due:2014-04-01 12:34') |
|
139
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
140
|
|
|
'<tt> </tt> this is my task <b>' |
|
141
|
|
|
'<font style="color:red">due:2014-04-01</font></b> 12:34') |
|
142
|
|
|
|
|
143
|
|
|
def test_19(self): |
|
144
|
|
|
# Test task with a valid due time corner case |
|
145
|
|
|
task = tasklib.Task('this is my task due:2014-04-01T00:00') |
|
146
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
147
|
|
|
'<tt> </tt> this is my task <b>' |
|
148
|
|
|
'<font style="color:red">due:2014-04-01</font></b>') |
|
149
|
|
|
|
|
150
|
|
|
def test_20(self): |
|
151
|
|
|
# Test task with a valid due time corner case |
|
152
|
|
|
task = tasklib.Task('this is my task due:2014-04-01T00:01') |
|
153
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
154
|
|
|
'<tt> </tt> this is my task <b>' |
|
155
|
|
|
'<font style="color:red">due:2014-04-01 00:01</font></b>') |
|
156
|
|
|
|
|
157
|
|
|
def test_21(self): |
|
158
|
|
|
# Test task with a valid due time corner case |
|
159
|
|
|
task = tasklib.Task('this is my task due:2014-04-01T23:59') |
|
160
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
161
|
|
|
'<tt> </tt> this is my task <b>' |
|
162
|
|
|
'<font style="color:red">due:2014-04-01 23:59</font></b>') |
|
163
|
|
|
|
|
164
|
|
|
def test_22(self): |
|
165
|
|
|
# Test task with an invalid due time corner case |
|
166
|
|
|
task = tasklib.Task('this is my task due:2014-04-01T24:00') |
|
167
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
168
|
|
|
'<tt> </tt> this is my task <b>' |
|
169
|
|
|
'<font style="color:red">*** due:2014-04-01T24:00 Invalid date format, ' |
|
170
|
|
|
'expected yyyy-mm-dd or yyyy-mm-ddThh:mm. ***</font></b>') |
|
171
|
|
|
|
|
172
|
|
|
def test_23(self): |
|
173
|
|
|
# Test task with a valid threshold date |
|
174
|
|
|
task = tasklib.Task('this is my task t:2014-04-01') |
|
175
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
176
|
|
|
'<tt> </tt> this is my task ' |
|
177
|
|
|
'<font style="color:orange">t:2014-04-01</font>') |
|
178
|
|
|
|
|
179
|
|
|
def test_24(self): |
|
180
|
|
|
# Test task with a valid threshold date and time |
|
181
|
|
|
task = tasklib.Task('this is my task t:2014-04-01T12:34') |
|
182
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
183
|
|
|
'<tt> </tt> this is my task ' |
|
184
|
|
|
'<font style="color:orange">t:2014-04-01 12:34</font>') |
|
185
|
|
|
|
|
186
|
|
|
def test_25(self): |
|
187
|
|
|
# Test task with an invalid threshold date |
|
188
|
|
|
task = tasklib.Task('this is my task t:abc') |
|
189
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
190
|
|
|
'<tt> </tt> this is my task <b>' |
|
191
|
|
|
'<font style="color:red">*** t:abc Invalid date format, ' |
|
192
|
|
|
'expected yyyy-mm-dd or yyyy-mm-ddThh:mm. ***</font></b>') |
|
193
|
|
|
|
|
194
|
|
|
def test_26(self): |
|
195
|
|
|
# Test task with an invalid threshold date |
|
196
|
|
|
task = tasklib.Task('this is my task t:2014-04') |
|
197
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
198
|
|
|
'<tt> </tt> this is my task <b>' |
|
199
|
|
|
'<font style="color:red">*** t:2014-04 Invalid date format, ' |
|
200
|
|
|
'expected yyyy-mm-dd or yyyy-mm-ddThh:mm. ***</font></b>') |
|
201
|
|
|
|
|
202
|
|
|
def test_27(self): |
|
203
|
|
|
# Test task with an invalid threshold month |
|
204
|
|
|
task = tasklib.Task('this is my task t:2014-13-01') |
|
205
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
206
|
|
|
'<tt> </tt> this is my task <b>' |
|
207
|
|
|
'<font style="color:red">*** t:2014-13-01 Invalid date format, ' |
|
208
|
|
|
'expected yyyy-mm-dd or yyyy-mm-ddThh:mm. ***</font></b>') |
|
209
|
|
|
|
|
210
|
|
|
def test_28(self): |
|
211
|
|
|
# Test task with an invalid threshold day |
|
212
|
|
|
task = tasklib.Task('this is my task t:2014-04-31') |
|
213
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
214
|
|
|
'<tt> </tt> this is my task <b>' |
|
215
|
|
|
'<font style="color:red">*** t:2014-04-31 Invalid date format, ' |
|
216
|
|
|
'expected yyyy-mm-dd or yyyy-mm-ddThh:mm. ***</font></b>') |
|
217
|
|
|
|
|
218
|
|
|
def test_29(self): |
|
219
|
|
|
# Test task with an invalid threshold hour |
|
220
|
|
|
task = tasklib.Task('this is my task t:2014-04-31T99:34') |
|
221
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
222
|
|
|
'<tt> </tt> this is my task <b>' |
|
223
|
|
|
'<font style="color:red">*** t:2014-04-31T99:34 Invalid date format, ' |
|
224
|
|
|
'expected yyyy-mm-dd or yyyy-mm-ddThh:mm. ***</font></b>') |
|
225
|
|
|
|
|
226
|
|
|
def test_30(self): |
|
227
|
|
|
# Test task with an invalid threshold minute |
|
228
|
|
|
task = tasklib.Task('this is my task t:2014-04-31T12:99') |
|
229
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
230
|
|
|
'<tt> </tt> this is my task <b>' |
|
231
|
|
|
'<font style="color:red">*** t:2014-04-31T12:99 Invalid date format, ' |
|
232
|
|
|
'expected yyyy-mm-dd or yyyy-mm-ddThh:mm. ***</font></b>') |
|
233
|
|
|
|
|
234
|
|
|
def test_31(self): |
|
235
|
|
|
# Test task with an URL |
|
236
|
|
|
task = tasklib.Task('Download https://github.com/mNantern/QTodoTxt/archive/master.zip and extract') |
|
237
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
238
|
|
|
'<tt> </tt> Download ' |
|
239
|
|
|
'<a style="color:none;" href="https://github.com/mNantern/QTodoTxt/archive/master.zip">' |
|
240
|
|
|
'https://github.com/...</a> and extract') |
|
241
|
|
|
|
|
242
|
|
|
def test_32(self): |
|
243
|
|
|
# Test task with solely an URL |
|
244
|
|
|
task = tasklib.Task('https://github.com/mNantern/QTodoTxt/archive/master.zip') |
|
245
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
246
|
|
|
'<tt> </tt> ' |
|
247
|
|
|
'<a style="color:none;" href="https://github.com/mNantern/QTodoTxt/archive/master.zip">' |
|
248
|
|
|
'https://github.com/...</a>') |
|
249
|
|
|
|
|
250
|
|
|
def test_33(self): |
|
251
|
|
|
# Test task with an URL in context |
|
252
|
|
|
task = tasklib.Task('Test @https://github.com/mNantern/QTodoTxt/') |
|
253
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
254
|
|
|
'<tt> </tt> Test <font style="color:green">' |
|
255
|
|
|
'@<a style="color:green;" href="https://github.com/mNantern/QTodoTxt/">' |
|
256
|
|
|
'https://github.com/...</a></font>') |
|
257
|
|
|
|
|
258
|
|
|
def test_34(self): |
|
259
|
|
|
# Test task with an URL in project |
|
260
|
|
|
task = tasklib.Task('Test +https://github.com/mNantern/QTodoTxt/') |
|
261
|
|
|
self.assertEqual(self.htmlizer.task2html(task), |
|
262
|
|
|
'<tt> </tt> Test <font style="color:#64AAD0">' |
|
263
|
|
|
'+<a style="color:#64AAD0;" href="https://github.com/mNantern/QTodoTxt/">' |
|
264
|
|
|
'https://github.com/...</a></font>') |
|
265
|
|
|
|