snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
138
zerver/tests/test_templates.py
Normal file
138
zerver/tests/test_templates.py
Normal file
@@ -0,0 +1,138 @@
|
||||
from django.template.loader import get_template
|
||||
|
||||
from zerver.lib.exceptions import InvalidMarkdownIncludeStatementError
|
||||
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<h1id="hello">Hello!</h1><p>Thisissome<em>boldtext</em>.</p>footer',
|
||||
)
|
||||
|
||||
def test_markdown_tabbed_sections_extension(self) -> None:
|
||||
template = get_template("tests/test_markdown.html")
|
||||
context = {
|
||||
"markdown_test_file": "zerver/tests/markdown/test_tabbed_sections.md",
|
||||
}
|
||||
content = template.render(context)
|
||||
content_sans_whitespace = content.replace(" ", "").replace("\n", "")
|
||||
|
||||
# Note that the expected HTML has a lot of stray <p> 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 <p> 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
|
||||
|
||||
<h1 id="heading">Heading</h1>
|
||||
<p>
|
||||
<div class="tabbed-section has-tabs" markdown="1">
|
||||
<ul class="nav">
|
||||
<li class="active" data-tab-key="ios" tabindex="0">iOS</li>
|
||||
<li class="" data-tab-key="desktop-web" tabindex="0">Desktop/Web</li>
|
||||
</ul>
|
||||
<div class="blocks">
|
||||
<div class="tab-content active" data-tab-key="ios" markdown="1"></p>
|
||||
<p>iOS instructions</p>
|
||||
<p></div>
|
||||
<div class="tab-content" data-tab-key="desktop-web" markdown="1"></p>
|
||||
<p>Desktop/browser instructions</p>
|
||||
<p></div>
|
||||
</div>
|
||||
</div>
|
||||
</p>
|
||||
|
||||
<h2 id="heading-2">Heading 2</h2>
|
||||
<p>
|
||||
<div class="tabbed-section has-tabs" markdown="1">
|
||||
<ul class="nav">
|
||||
<li class="active" data-tab-key="desktop-web" tabindex="0">Desktop/Web</li>
|
||||
<li class="" data-tab-key="android" tabindex="0">Android</li>
|
||||
</ul>
|
||||
<div class="blocks">
|
||||
<div class="tab-content active" data-tab-key="desktop-web" markdown="1"></p>
|
||||
<p>Desktop/browser instructions</p>
|
||||
<p></div>
|
||||
<div class="tab-content" data-tab-key="android" markdown="1"></p>
|
||||
<p>Android instructions</p>
|
||||
<p></div>
|
||||
</div>
|
||||
</div>
|
||||
</p>
|
||||
|
||||
<h2 id="heading-3">Heading 3</h2>
|
||||
<p>
|
||||
<div class="tabbed-section no-tabs" markdown="1">
|
||||
<ul class="nav">
|
||||
<li class="active" data-tab-key="instructions-for-all-platforms" tabindex="0">Instructions for all platforms</li>
|
||||
</ul>
|
||||
<div class="blocks">
|
||||
<div class="tab-content active" data-tab-key="instructions-for-all-platforms" markdown="1"></p>
|
||||
<p>Instructions for all platforms</p>
|
||||
<p></div>
|
||||
</div>
|
||||
</div>
|
||||
</p>
|
||||
|
||||
footer
|
||||
"""
|
||||
|
||||
expected_html_sans_whitespace = expected_html.replace(" ", "").replace("\n", "")
|
||||
self.assertEqual(content_sans_whitespace, expected_html_sans_whitespace)
|
||||
|
||||
def test_markdown_tabbed_sections_missing_tabs(self) -> None:
|
||||
template = get_template("tests/test_markdown.html")
|
||||
context = {
|
||||
"markdown_test_file": "zerver/tests/markdown/test_tabbed_sections_missing_tabs.md",
|
||||
}
|
||||
expected_regex = "^Tab 'minix' is not present in TAB_SECTION_LABELS in zerver/lib/markdown/tabbed_sections.py$"
|
||||
with self.assertRaisesRegex(ValueError, expected_regex):
|
||||
template.render(context)
|
||||
|
||||
def test_markdown_nested_code_blocks(self) -> None:
|
||||
template = get_template("tests/test_markdown.html")
|
||||
context = {
|
||||
"markdown_test_file": "zerver/tests/markdown/test_nested_code_blocks.md",
|
||||
}
|
||||
content = template.render(context)
|
||||
|
||||
content_sans_whitespace = content.replace(" ", "").replace("\n", "")
|
||||
expected = (
|
||||
'header<h1id="this-is-a-heading">Thisisaheading.</h1><ol>'
|
||||
'<li><p>Alistitemwithanindentedcodeblock:</p><divclass="codehilite">'
|
||||
"<pre>indentedcodeblockwithmultiplelines</pre></div></li></ol>"
|
||||
'<divclass="codehilite"><pre><span></span><code>'
|
||||
"non-indentedcodeblockwithmultiplelines</code></pre></div>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(
|
||||
InvalidMarkdownIncludeStatementError, "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)
|
||||
Reference in New Issue
Block a user