~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to mainpage/utest/test_wl_markdown.py

  • Committer: franku
  • Date: 2016-12-13 18:28:51 UTC
  • mto: This revision was merged to the branch mainline in revision 443.
  • Revision ID: somal@arcor.de-20161213182851-bo5ebf8pdvw5beua
run the script

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
# Since we want to include something from one path up,
13
13
# we append the parent path to sys.path
14
 
import sys; sys.path.append("..")
 
14
import sys
 
15
sys.path.append('..')
15
16
 
16
17
import unittest
17
18
from wiki.models import Article
22
23
 
23
24
from templatetags.wl_markdown import do_wl_markdown
24
25
 
 
26
 
25
27
class TestWlMarkdown(DBTestCase):
 
28
 
26
29
    def setUp(self):
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')
31
34
 
32
35
    def _check(self, input, wanted):
33
36
        res = do_wl_markdown(input)
34
 
        self.assertEqual(wanted,res)
 
37
        self.assertEqual(wanted, res)
35
38
 
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)
40
43
 
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)
45
48
 
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)
50
53
 
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)
55
58
 
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)
60
63
 
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)
65
68
 
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)
70
73
 
71
74
    # Existing links
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)
76
79
 
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)
81
84
 
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)
86
89
 
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)
91
94
 
92
95
    # Missing links
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)
97
100
 
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)
102
105
 
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)
113
116
 
114
117
    # Check smileys
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)
 
122
 
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)
 
127
 
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)
 
132
 
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)
 
137
 
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)
 
142
 
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)
 
147
 
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)
 
152
 
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)
 
157
 
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)
 
162
 
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)
 
167
 
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)
 
172
 
159
173
    def test_smiley_grin(self):
160
174
        input = """:D"""
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)
 
177
 
163
178
    def test_smiley_sad(self):
164
179
        input = """:("""
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)
 
182
 
167
183
    def test_smiley_smile(self):
168
184
        input = """:)"""
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)
 
187
 
171
188
    def test_smiley_surprise(self):
172
189
        input = """:O"""
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)
 
192
 
175
193
    def test_smiley_wink(self):
176
194
        input = """;)"""
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)
 
197
 
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)
183
 
 
 
201
        self._check(input, wanted)
184
202
 
185
203
    # Occured errors
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)
 
208
 
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)
194
213
 
195
214
    # Special pages
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)
 
219
 
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)
204
224
 
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)
210
230
 
211
231
    # Another markdown problem with alt tag escaping
212
232
    def test_markdown_alt_problem(self):
214
234
        input = u"""![img_thisisNOTitalicplease_name.png](/wlmedia/blah.png)\n\n"""
215
235
        wanted = u'<p><img alt="img_thisisNOTitalicplease_name.png" src="/wlmedia/blah.png" /></p>'
216
236
        # }}}
217
 
        self._check(input,wanted)
 
237
        self._check(input, wanted)
218
238
 
219
239
    def test_emptystring_problem(self):
220
240
        # {{{ Test strings
221
241
        input = u''
222
242
        wanted = u''
223
243
        # }}}
224
 
        self._check(input,wanted)
 
244
        self._check(input, wanted)
225
245
 
226
246
    # Damned problem with tables
227
247
    def test_markdown_table_problem(self):
251
271
</tbody>
252
272
</table>"""
253
273
        # }}}
254
 
        self._check(input,wanted)
255
 
    def test_svnrevision_replacement( self ):
 
274
        self._check(input, wanted)
 
275
 
 
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)
 
280
 
 
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)
263
285
 
264
286
 
265
287
if __name__ == '__main__':
266
288
    unittest.main()
267
289
    # k = TestWlMarkdown_WikiWordsInLink_ExceptCorrectResult()
268
290
    # unittest.TextTestRunner().run(k)
269