Mercurial > public > sg101
changeset 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 | 05d618e3f353 |
children | |
files | core/mdexts/deleted.py core/tests/test_markup.py |
diffstat | 2 files changed, 60 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/core/mdexts/deleted.py Fri Jun 06 08:18:35 2025 -0500 +++ b/core/mdexts/deleted.py Sat Jun 07 08:28:27 2025 -0500 @@ -1,6 +1,6 @@ """ A python-markdown extension to add support for <del>. -The Markdown syntax is --this is deleted text--. +The Markdown syntax is ---this is deleted text---. """ import markdown
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/tests/test_markup.py Sat Jun 07 08:28:27 2025 -0500 @@ -0,0 +1,59 @@ +""" +Tests for the core markup module. + +""" +import textwrap +import unittest + +from django.test import TestCase + +from core.markup import Markdown, markdown, SiteMarkup, site_markup + + +class MarkdownTestCase(unittest.TestCase): + + TEST_TEXT = textwrap.dedent("""\ + Some text. + https://example.com + ---deleted text--- + """) + + EXPECTED = textwrap.dedent(u"""\ + <p>Some text.<br> + <a href="https://example.com">https://example.com</a><br> + <del>deleted text</del></p>""") + + def test_markdown_class(self): + md = Markdown() + output = md.convert(self.TEST_TEXT) + self.assertEqual(output, self.EXPECTED) + + def test_markdown_function(self): + output = markdown(self.TEST_TEXT) + self.assertEqual(output, self.EXPECTED) + + +class SiteMarkdupTestCase(TestCase): + fixtures = ['smilies.json'] + + TEST_TEXT = textwrap.dedent("""\ + Some text. + https://example.com + ---deleted text--- + :sg101: + """) + + EXPECTED = textwrap.dedent(u"""\ + <p>Some text.<br> + <a href="https://example.com">https://example.com</a><br> + <del>deleted text</del><br> + <img src="/media/smiley/images/icon_sg101.gif" alt="SG101!" title="SG101!"></p>""") + + def test_site_markup_class(self): + sm = SiteMarkup() + output = sm.convert(self.TEST_TEXT) + self.assertEqual(output, self.EXPECTED) + + def test_site_markup_function(self): + output = site_markup(self.TEST_TEXT) + self.assertEqual(output, self.EXPECTED)