from django.template.loader import get_template
from zerver.lib.exceptions import InvalidMarkdownIncludeStatement
from zerver.lib.test_classes import (
ZulipTestCase,
)
class TemplateTestCase(ZulipTestCase):
def test_markdown_in_template(self) -> None:
template = get_template("tests/test_markdown.html")
context = {
'markdown_test_file': "zerver/tests/markdown/test_markdown.md"
}
content = template.render(context)
content_sans_whitespace = content.replace(" ", "").replace('\n', '')
self.assertEqual(content_sans_whitespace,
'header Thisissomeboldtext. tags. This is a
# consequence of how the Markdown renderer converts newlines to HTML
# and how elements are delimited by newlines and so forth. However,
# stray tags are usually matched with closing tags by HTML renderers
# so this doesn't affect the final rendered UI in any visible way.
expected_html = """
header
iOS instructions Desktop/browser instructionsHeading
Desktop/browser instructions
Android instructions
Instructions for all platforms
Alistitemwithanindentedcodeblock:
indentedcodeblockwithmultiplelines
'
'non-indentedcodeblockwithmultiplelines
footer')
self.assertEqual(content_sans_whitespace, expected)
def test_custom_markdown_include_extension(self) -> None:
template = get_template("tests/test_markdown.html")
context = {
'markdown_test_file': "zerver/tests/markdown/test_custom_include_extension.md"
}
with self.assertRaisesRegex(InvalidMarkdownIncludeStatement, "Invalid markdown include statement"):
template.render(context)
def test_custom_markdown_include_extension_empty_macro(self) -> None:
template = get_template("tests/test_markdown.html")
context = {
'markdown_test_file': "zerver/tests/markdown/test_custom_include_extension_empty.md"
}
content = template.render(context)
content_sans_whitespace = content.replace(" ", "").replace('\n', '')
expected = 'headerfooter'
self.assertEqual(content_sans_whitespace, expected)