Completed
Push — master ( 3de955...017fb0 )
by Alexander
120:07 queued 117:39
created

TestMarkdownExtraFilters.test_markdown2html_does_bleach_unsafe_code()   A

Complexity

Conditions 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 17
rs 9.85
c 0
b 0
f 0
cc 1
nop 1
1
# -*- coding: utf-8 -*-
2
import unittest
3
from tcms.core.templatetags.extra_filters import markdown2html
4
5
6
class TestMarkdownExtraFilters(unittest.TestCase):
7
8
    def test_markdown2html_convert_paragraphs(self):
9
        self.assertEqual(markdown2html("__*hello!*__"),
10
                         "<p><strong><em>hello!</em></strong></p>")
11
12
    def test_markdown2html_convert_tables(self):
13
        self.assertEqual(markdown2html("""|Stx |Desc |\n|----|-----|\n|Head|Title|\n|Txt|Txt |"""),
14
                         """<table>
15
<thead>
16
<tr>
17
<th>Stx</th>
18
<th>Desc</th>
19
</tr>
20
</thead>
21
<tbody>
22
<tr>
23
<td>Head</td>
24
<td>Title</td>
25
</tr>
26
<tr>
27
<td>Txt</td>
28
<td>Txt</td>
29
</tr>
30
</tbody>
31
</table>""")
32
33
    def test_markdown2html_convert_nl2br(self):
34
        self.assertEqual(markdown2html("""Line 1
35
Line 2"""), """<p>Line 1<br>
36
Line 2</p>""")
37
38
    def test_markdown2html_convert_fenced_code(self):
39
        self.assertEqual(markdown2html("""```{
40
"firstName": "John",
41
"lastName": "Smith",
42
"age": 25}``` """), """<p><code>{
43
"firstName": "John",
44
"lastName": "Smith",
45
"age": 25}</code> </p>""")
46
47
    def test_markdown2html_does_bleach_unsafe_code(self):
48
        self.assertEqual(markdown2html("### hello <script>alert('gotcha');</script>"),
49
                         "<h3>hello &lt;script&gt;alert('gotcha');&lt;/script&gt;</h3>")
50
51
        self.assertEqual(markdown2html("<canvas><bgsound><audio><applet>"),
52
                         "&lt;canvas&gt;&lt;bgsound&gt;&lt;audio&gt;&lt;applet&gt;")
53
54
        self.assertEqual(markdown2html("""_hello_ <html><head></head>
55
<body></body></html>"""), """<p><em>hello</em> &lt;html&gt;&lt;head&gt;&lt;/head&gt;<br>
56
&lt;body&gt;&lt;/body&gt;&lt;/html&gt;</p>""")
57
58
        self.assertEqual(markdown2html("""__hello__ <xmp><video><track>
59
<title><rt><ruby><param>"""), """<p><strong>hello</strong> &lt;xmp&gt;&lt;video&gt;&lt;track&gt;<br>
60
&lt;title&gt;&lt;rt&gt;&lt;ruby&gt;&lt;param&gt;</p>""")
61
62
        self.assertEqual(markdown2html("""*hello* <object><link><iframe>
63
<frame><frameset><embed>"""), """<p><em>hello</em> &lt;object&gt;&lt;link&gt;&lt;iframe&gt;<br>
64
&lt;frame&gt;&lt;frameset&gt;&lt;embed&gt;</p>""")
65