comparison core/tests/test_markup.py @ 1236:df3473a1ee8c modernize tip

Add unit tests for core.markup
author Brian Neal <bgneal@gmail.com>
date Sat, 07 Jun 2025 08:28:27 -0500
parents
children
comparison
equal deleted inserted replaced
1235:05d618e3f353 1236:df3473a1ee8c
1 """
2 Tests for the core markup module.
3
4 """
5 import textwrap
6 import unittest
7
8 from django.test import TestCase
9
10 from core.markup import Markdown, markdown, SiteMarkup, site_markup
11
12
13 class MarkdownTestCase(unittest.TestCase):
14
15 TEST_TEXT = textwrap.dedent("""\
16 Some text.
17 https://example.com
18 ---deleted text---
19 """)
20
21 EXPECTED = textwrap.dedent(u"""\
22 <p>Some text.<br>
23 <a href="https://example.com">https://example.com</a><br>
24 <del>deleted text</del></p>""")
25
26 def test_markdown_class(self):
27 md = Markdown()
28 output = md.convert(self.TEST_TEXT)
29 self.assertEqual(output, self.EXPECTED)
30
31 def test_markdown_function(self):
32 output = markdown(self.TEST_TEXT)
33 self.assertEqual(output, self.EXPECTED)
34
35
36 class SiteMarkdupTestCase(TestCase):
37 fixtures = ['smilies.json']
38
39 TEST_TEXT = textwrap.dedent("""\
40 Some text.
41 https://example.com
42 ---deleted text---
43 :sg101:
44 """)
45
46 EXPECTED = textwrap.dedent(u"""\
47 <p>Some text.<br>
48 <a href="https://example.com">https://example.com</a><br>
49 <del>deleted text</del><br>
50 <img src="/media/smiley/images/icon_sg101.gif" alt="SG101!" title="SG101!"></p>""")
51
52 def test_site_markup_class(self):
53 sm = SiteMarkup()
54 output = sm.convert(self.TEST_TEXT)
55 self.assertEqual(output, self.EXPECTED)
56
57 def test_site_markup_function(self):
58 output = site_markup(self.TEST_TEXT)
59 self.assertEqual(output, self.EXPECTED)