23
24
from templatetags.wl_markdown import do_wl_markdown
25
27
class TestWlMarkdown(DBTestCase):
27
a = Article.objects.create(title="MainPage")
28
a = Article.objects.create(title="HalloWelt")
29
a = Article.objects.create(title="NoWikiWord")
30
a = Article.objects.create(title="WikiWord")
30
a = Article.objects.create(title='MainPage')
31
a = Article.objects.create(title='HalloWelt')
32
a = Article.objects.create(title='NoWikiWord')
33
a = Article.objects.create(title='WikiWord')
32
35
def _check(self, input, wanted):
33
36
res = do_wl_markdown(input)
34
self.assertEqual(wanted,res)
37
self.assertEqual(wanted, res)
36
39
def test_simple_case__correct_result(self):
37
40
input = u"Hallo Welt"
38
41
wanted = u"<p>Hallo Welt</p>"
39
self._check(input,wanted)
42
self._check(input, wanted)
41
44
def test_wikiwords_simple__except_correct_result(self):
42
45
input = u"Na Du HalloWelt, Du?"
43
46
wanted = u"""<p>Na Du <a href="/wiki/HalloWelt">HalloWelt</a>, Du?</p>"""
44
self._check(input,wanted)
47
self._check(input, wanted)
46
49
def test_wikiwords_avoid__except_correct_result(self):
47
50
input = u"Hi !NotAWikiWord Moretext"
48
51
wanted = u"""<p>Hi NotAWikiWord Moretext</p>"""
49
self._check(input,wanted)
52
self._check(input, wanted)
51
54
def test_wikiwords_in_link__except_correct_result(self):
52
55
input = u"""WikiWord [NoWikiWord](/forum/)"""
53
56
wanted = u"""<p><a href="/wiki/WikiWord">WikiWord</a> <a href="/forum/">NoWikiWord</a></p>"""
54
self._check(input,wanted)
57
self._check(input, wanted)
56
59
def test_wikiwords_external_links__except_correct_result(self):
57
60
input = u"""[NoWikiWord](http://www.sun.com)"""
58
61
wanted = u"""<p><a href="http://www.sun.com" class="external">NoWikiWord</a></p>"""
59
self._check(input,wanted)
62
self._check(input, wanted)
61
64
def test_wikiwords_noexternal_links__except_correct_result(self):
62
65
input = u"""[NoWikiWord](http://%s/blahfasel/wiki)""" % _domain
63
wanted = u"""<p><a href="http://%s/blahfasel/wiki">NoWikiWord</a></p>""" %_domain
64
self._check(input,wanted)
66
wanted = u"""<p><a href="http://%s/blahfasel/wiki">NoWikiWord</a></p>""" % _domain
67
self._check(input, wanted)
66
69
def test_wikiwords_noclasschangeforimage_links__except_correct_result(self):
67
70
input = u"""<a href="http://www.ccc.de"><img src="/blub" /></a>"""
68
71
wanted = u"""<p><a href="http://www.ccc.de"><img src="/blub" /></a></p>"""
69
self._check(input,wanted)
72
self._check(input, wanted)
72
75
def test_existing_link_html(self):
73
76
input = u"""<a href="/wiki/MainPage">this page</a>"""
74
77
wanted = u"""<p><a href="/wiki/MainPage">this page</a></p>"""
75
self._check(input,wanted)
78
self._check(input, wanted)
77
80
def test_existing_link_markdown(self):
78
81
input = u"""[this page](/wiki/MainPage)"""
79
82
wanted = u"""<p><a href="/wiki/MainPage">this page</a></p>"""
80
self._check(input,wanted)
83
self._check(input, wanted)
82
85
def test_existing_link_wikiword(self):
83
86
input = u"""MainPage"""
84
87
wanted = u"""<p><a href="/wiki/MainPage">MainPage</a></p>"""
85
self._check(input,wanted)
88
self._check(input, wanted)
87
90
def test_existing_editlink_wikiword(self):
88
91
input = u"""<a href="/wiki/MainPage/edit/">this page</a>"""
89
92
wanted = u"""<p><a href="/wiki/MainPage/edit/">this page</a></p>"""
90
self._check(input,wanted)
93
self._check(input, wanted)
93
96
def test_missing_link_html(self):
94
97
input = u"""<a href="/wiki/MissingPage">this page</a>"""
95
98
wanted = u"""<p><a href="/wiki/MissingPage" class="missing">this page</a></p>"""
96
self._check(input,wanted)
99
self._check(input, wanted)
98
101
def test_missing_link_markdown(self):
99
102
input = u"""[this page](/wiki/MissingPage)"""
100
103
wanted = u"""<p><a href="/wiki/MissingPage" class="missing">this page</a></p>"""
101
self._check(input,wanted)
104
self._check(input, wanted)
103
106
def test_missing_link_wikiword(self):
104
107
input = u"""BlubMissingPage"""
109
112
def test_missing_editlink_wikiword(self):
110
113
input = u"""<a href="/wiki/MissingPage/edit/">this page</a>"""
111
114
wanted = u"""<p><a href="/wiki/MissingPage/edit/" class="missing">this page</a></p>"""
112
self._check(input,wanted)
115
self._check(input, wanted)
115
118
def test_smiley_angel(self):
116
119
input = """O:-)"""
117
120
wanted = u"""<p><img src="/wlmedia/img/smileys/face-angel.png" alt="face-angel.png" /></p>"""
118
self._check(input,wanted)
121
self._check(input, wanted)
119
123
def test_smiley_crying(self):
120
124
input = """:'-("""
121
125
wanted = u"""<p><img src="/wlmedia/img/smileys/face-crying.png" alt="face-crying.png" /></p>"""
122
self._check(input,wanted)
126
self._check(input, wanted)
123
128
def test_smiley_devilish(self):
124
129
input = """>:-)"""
125
130
wanted = u"""<p><img src="/wlmedia/img/smileys/face-devilish.png" alt="face-devilish.png" /></p>"""
126
self._check(input,wanted)
131
self._check(input, wanted)
127
133
def test_smiley_glasses(self):
128
134
input = """8-)"""
129
135
wanted = u"""<p><img src="/wlmedia/img/smileys/face-glasses.png" alt="face-glasses.png" /></p>"""
130
self._check(input,wanted)
136
self._check(input, wanted)
131
138
def test_smiley_kiss(self):
132
139
input = """:-x"""
133
140
wanted = u"""<p><img src="/wlmedia/img/smileys/face-kiss.png" alt="face-kiss.png" /></p>"""
134
self._check(input,wanted)
141
self._check(input, wanted)
135
143
def test_smiley_plain(self):
136
144
input = """:-|"""
137
145
wanted = u"""<p><img src="/wlmedia/img/smileys/face-plain.png" alt="face-plain.png" /></p>"""
138
self._check(input,wanted)
146
self._check(input, wanted)
139
148
def test_smiley_sad(self):
140
149
input = """:-("""
141
150
wanted = u"""<p><img src="/wlmedia/img/smileys/face-sad.png" alt="face-sad.png" /></p>"""
142
self._check(input,wanted)
151
self._check(input, wanted)
143
153
def test_smiley_smilebig(self):
144
154
input = """:))"""
145
155
wanted = u"""<p><img src="/wlmedia/img/smileys/face-smile-big.png" alt="face-smile-big.png" /></p>"""
146
self._check(input,wanted)
156
self._check(input, wanted)
147
158
def test_smiley_smile(self):
148
159
input = """:-)"""
149
160
wanted = u"""<p><img src="/wlmedia/img/smileys/face-smile.png" alt="face-smile.png" /></p>"""
150
self._check(input,wanted)
161
self._check(input, wanted)
151
163
def test_smiley_surprise(self):
152
164
input = """:-O"""
153
165
wanted = u"""<p><img src="/wlmedia/img/smileys/face-surprise.png" alt="face-surprise.png" /></p>"""
154
self._check(input,wanted)
166
self._check(input, wanted)
155
168
def test_smiley_wink(self):
156
169
input = """;-)"""
157
170
wanted = u"""<p><img src="/wlmedia/img/smileys/face-wink.png" alt="face-wink.png" /></p>"""
158
self._check(input,wanted)
171
self._check(input, wanted)
159
173
def test_smiley_grin(self):
161
175
wanted = u"""<p><img src="/wlmedia/img/smileys/face-grin.png" alt="face-grin.png" /></p>"""
162
self._check(input,wanted)
176
self._check(input, wanted)
163
178
def test_smiley_sad(self):
165
180
wanted = u"""<p><img src="/wlmedia/img/smileys/face-sad.png" alt="face-sad.png" /></p>"""
166
self._check(input,wanted)
181
self._check(input, wanted)
167
183
def test_smiley_smile(self):
169
185
wanted = u"""<p><img src="/wlmedia/img/smileys/face-smile.png" alt="face-smile.png" /></p>"""
170
self._check(input,wanted)
186
self._check(input, wanted)
171
188
def test_smiley_surprise(self):
173
190
wanted = u"""<p><img src="/wlmedia/img/smileys/face-surprise.png" alt="face-surprise.png" /></p>"""
174
self._check(input,wanted)
191
self._check(input, wanted)
175
193
def test_smiley_wink(self):
177
195
wanted = u"""<p><img src="/wlmedia/img/smileys/face-wink.png" alt="face-wink.png" /></p>"""
178
self._check(input,wanted)
196
self._check(input, wanted)
179
198
def test_smiley_monkey(self):
180
199
input = """:(|)"""
181
200
wanted = u"""<p><img src="/wlmedia/img/smileys/face-monkey.png" alt="face-monkey.png" /></p>"""
182
self._check(input,wanted)
201
self._check(input, wanted)
186
204
def test_wiki_rootlink(self):
187
205
input = u"""<a href="/wiki">this page</a>"""
188
206
wanted = u"""<p><a href="/wiki">this page</a></p>"""
189
self._check(input,wanted)
207
self._check(input, wanted)
190
209
def test_wiki_rootlink_with_slash(self):
191
210
input = u"""<a href="/wiki/">this page</a>"""
192
211
wanted = u"""<p><a href="/wiki/">this page</a></p>"""
193
self._check(input,wanted)
212
self._check(input, wanted)
196
215
def test_wiki_specialpage(self):
197
216
input = u"""<a href="/wiki/list">this page</a>"""
198
217
wanted = u"""<p><a href="/wiki/list">this page</a></p>"""
199
self._check(input,wanted)
218
self._check(input, wanted)
200
220
def test_wiki_specialpage_markdown(self):
201
221
input = u"""[list](/wiki/list)"""
202
222
wanted = u"""<p><a href="/wiki/list">list</a></p>"""
203
self._check(input,wanted)
223
self._check(input, wanted)
205
225
# Special problem with emphasis
206
226
def test_markdown_emphasis_problem(self):
207
227
input = u"""*This is bold* _This too_\n\n"""
208
228
wanted = u"""<p><em>This is bold</em> <em>This too</em></p>"""
209
self._check(input,wanted)
229
self._check(input, wanted)
211
231
# Another markdown problem with alt tag escaping
212
232
def test_markdown_alt_problem(self):
254
self._check(input,wanted)
255
def test_svnrevision_replacement( self ):
274
self._check(input, wanted)
276
def test_svnrevision_replacement(self):
256
277
input = u"- Fixed this bug (bzr:r3222)"
257
278
wanted = u"""<ul>\n<li>Fixed this bug (<a href="http://bazaar.launchpad.net/%7Ewidelands-dev/widelands/trunk/revision/3222" class="external">r3222</a>)</li>\n</ul>"""
258
self._check(input,wanted)
259
def test_svnrevision_multiple_replacement( self ):
279
self._check(input, wanted)
281
def test_svnrevision_multiple_replacement(self):
260
282
input = u"- Fixed this bug (bzr:r3222, bzr:r3424)"
261
283
wanted = u"""<ul>\n<li>Fixed this bug (<a href="http://bazaar.launchpad.net/%7Ewidelands-dev/widelands/trunk/revision/3222" class="external">r3222</a>, <a href="http://bazaar.launchpad.net/%7Ewidelands-dev/widelands/trunk/revision/3424" class="external">r3424</a>)</li>\n</ul>"""
262
self._check(input,wanted)
284
self._check(input, wanted)
265
287
if __name__ == '__main__':
267
289
# k = TestWlMarkdown_WikiWordsInLink_ExceptCorrectResult()
268
290
# unittest.TextTestRunner().run(k)