initial
This commit is contained in:
0
tests/plugins/macros/__init__.py
Normal file
0
tests/plugins/macros/__init__.py
Normal file
14
tests/plugins/macros/test_links.py
Normal file
14
tests/plugins/macros/test_links.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from wiki.core import markdown
|
||||
|
||||
from tests.base import RequireRootArticleMixin
|
||||
from tests.base import TestBase
|
||||
|
||||
|
||||
class WikiLinksTests(RequireRootArticleMixin, TestBase):
|
||||
def test_wikilink(self):
|
||||
md = markdown.ArticleMarkdown(article=self.root_article)
|
||||
md_text = md.convert("[[Root Article]]")
|
||||
self.assertEqual(
|
||||
md_text,
|
||||
'<p><a class="wiki_wikilink wiki-broken" href="/Root_Article/">Root Article</a></p>',
|
||||
)
|
||||
18
tests/plugins/macros/test_macro.py
Normal file
18
tests/plugins/macros/test_macro.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from wiki.core import markdown
|
||||
|
||||
from tests.base import RequireRootArticleMixin
|
||||
from tests.base import TestBase
|
||||
|
||||
|
||||
class MacroTests(RequireRootArticleMixin, TestBase):
|
||||
def test_article_list(self):
|
||||
md = markdown.ArticleMarkdown(article=self.root_article)
|
||||
md_text = md.convert("[article_list depth:2]")
|
||||
self.assertIn("Nothing below this level", md_text)
|
||||
self.assertNotIn("[article_list depth:2]", md_text)
|
||||
|
||||
def test_escape(self):
|
||||
md = markdown.ArticleMarkdown(article=self.root_article)
|
||||
md_text = md.convert("`[article_list depth:2]`")
|
||||
self.assertNotIn("Nothing below this level", md_text)
|
||||
self.assertIn("[article_list depth:2]", md_text)
|
||||
345
tests/plugins/macros/test_toc.py
Normal file
345
tests/plugins/macros/test_toc.py
Normal file
@@ -0,0 +1,345 @@
|
||||
from django.test import TestCase
|
||||
from markdown import Markdown
|
||||
from wiki.core import markdown
|
||||
from wiki.plugins.macros.mdx.toc import WikiTocExtension
|
||||
|
||||
from tests.base import RequireRootArticleMixin
|
||||
from tests.base import TestBase
|
||||
|
||||
|
||||
class TocMacroTests(TestCase):
|
||||
maxDiff = None
|
||||
|
||||
def test_toc_renders_table_of_content(self):
|
||||
"""Verifies that the [TOC] wiki code renders a Table of Content"""
|
||||
md = Markdown(extensions=["extra", WikiTocExtension()])
|
||||
text = (
|
||||
"[TOC]\n"
|
||||
"\n"
|
||||
"# First title.\n"
|
||||
"\n"
|
||||
"Paragraph 1\n"
|
||||
"\n"
|
||||
"## Subsection\n"
|
||||
"\n"
|
||||
"Paragraph 2"
|
||||
)
|
||||
expected_output = (
|
||||
'<div class="toc">\n'
|
||||
"<ul>\n"
|
||||
'<li><a href="#wiki-toc-first-title">First title.</a><ul>\n'
|
||||
'<li><a href="#wiki-toc-subsection">Subsection</a></li>\n'
|
||||
"</ul>\n"
|
||||
"</li>\n"
|
||||
"</ul>\n"
|
||||
"</div>\n"
|
||||
'<h1 id="wiki-toc-first-title">First title.</h1>\n'
|
||||
"<p>Paragraph 1</p>\n"
|
||||
'<h2 id="wiki-toc-subsection">Subsection</h2>\n'
|
||||
"<p>Paragraph 2</p>"
|
||||
)
|
||||
self.assertEqual(md.convert(text), expected_output)
|
||||
|
||||
def test_toc_renders_table_of_content_with_kwargs(self):
|
||||
"""Verifies that the [TOC] wiki code renders a Table of Content"""
|
||||
md = Markdown(extensions=["extra", WikiTocExtension(title="test")])
|
||||
text = (
|
||||
"[TOC]\n"
|
||||
"\n"
|
||||
"# First title.\n"
|
||||
"\n"
|
||||
"Paragraph 1\n"
|
||||
"\n"
|
||||
"## Subsection\n"
|
||||
"\n"
|
||||
"Paragraph 2"
|
||||
)
|
||||
expected_output = (
|
||||
'<div class="toc"><span class="toctitle">test</span><ul>\n'
|
||||
'<li><a href="#wiki-toc-first-title">First title.</a><ul>\n'
|
||||
'<li><a href="#wiki-toc-subsection">Subsection</a></li>\n'
|
||||
"</ul>\n"
|
||||
"</li>\n"
|
||||
"</ul>\n"
|
||||
"</div>\n"
|
||||
'<h1 id="wiki-toc-first-title">First title.</h1>\n'
|
||||
"<p>Paragraph 1</p>\n"
|
||||
'<h2 id="wiki-toc-subsection">Subsection</h2>\n'
|
||||
"<p>Paragraph 2</p>"
|
||||
)
|
||||
self.assertEqual(md.convert(text), expected_output)
|
||||
|
||||
|
||||
class TocMacroTestsInWiki(RequireRootArticleMixin, TestBase):
|
||||
def test_toc_renders_table_of_content_in_wiki(self):
|
||||
md = markdown.ArticleMarkdown(article=self.root_article)
|
||||
text = (
|
||||
"[TOC]\n"
|
||||
"\n"
|
||||
"# First title.\n"
|
||||
"\n"
|
||||
"Paragraph 1\n"
|
||||
"\n"
|
||||
"## Subsection\n"
|
||||
"\n"
|
||||
"Paragraph 2"
|
||||
)
|
||||
expected_output = (
|
||||
'<div class="toc"><span class="toctitle">Contents</span><ul>\n'
|
||||
'<li><a href="#wiki-toc-first-title">First title.</a><ul>\n'
|
||||
'<li><a href="#wiki-toc-subsection">Subsection</a></li>\n'
|
||||
"</ul>\n"
|
||||
"</li>\n"
|
||||
"</ul>\n"
|
||||
"</div>\n"
|
||||
'<h1 id="wiki-toc-first-title">First title.<a class="article-edit-title-link" '
|
||||
'href="/_plugin/editsection/header/wiki-toc-first-title/">[edit]</a></h1>\n'
|
||||
"<p>Paragraph 1</p>\n"
|
||||
'<h2 id="wiki-toc-subsection">Subsection<a class="article-edit-title-link" '
|
||||
'href="/_plugin/editsection/header/wiki-toc-subsection/">[edit]</a></h2>\n'
|
||||
"<p>Paragraph 2</p>"
|
||||
)
|
||||
self.assertEqual(md.convert(text), expected_output)
|
||||
|
||||
def test_toc_renders_table_of_content_with_toc_class(self):
|
||||
md = markdown.ArticleMarkdown(article=self.root_article)
|
||||
text = (
|
||||
"[TOC toc_class:'nontoc test']\n"
|
||||
"\n"
|
||||
"# First title.\n"
|
||||
"\n"
|
||||
"Paragraph 1\n"
|
||||
"\n"
|
||||
"## Subsection\n"
|
||||
"\n"
|
||||
"Paragraph 2"
|
||||
)
|
||||
expected_output = (
|
||||
'<div class="nontoc test"><span class="toctitle">Contents</span><ul>\n'
|
||||
'<li><a href="#wiki-toc-first-title">First title.</a><ul>\n'
|
||||
'<li><a href="#wiki-toc-subsection">Subsection</a></li>\n'
|
||||
"</ul>\n"
|
||||
"</li>\n"
|
||||
"</ul>\n"
|
||||
"</div>\n"
|
||||
'<h1 id="wiki-toc-first-title">First title.<a class="article-edit-title-link" '
|
||||
'href="/_plugin/editsection/header/wiki-toc-first-title/">[edit]</a></h1>\n'
|
||||
"<p>Paragraph 1</p>\n"
|
||||
'<h2 id="wiki-toc-subsection">Subsection<a class="article-edit-title-link" '
|
||||
'href="/_plugin/editsection/header/wiki-toc-subsection/">[edit]</a></h2>\n'
|
||||
"<p>Paragraph 2</p>"
|
||||
)
|
||||
self.assertEqual(md.convert(text), expected_output)
|
||||
|
||||
def test_toc_renders_table_of_content_in_wiki_with_kwargs(self):
|
||||
md = markdown.ArticleMarkdown(article=self.root_article)
|
||||
text = (
|
||||
"[TOC title:test]\n"
|
||||
"\n"
|
||||
"# First title.\n"
|
||||
"\n"
|
||||
"Paragraph 1\n"
|
||||
"\n"
|
||||
"## Subsection\n"
|
||||
"\n"
|
||||
"Paragraph 2"
|
||||
)
|
||||
expected_output = (
|
||||
'<div class="toc"><span class="toctitle">test</span><ul>\n'
|
||||
'<li><a href="#wiki-toc-first-title">First title.</a><ul>\n'
|
||||
'<li><a href="#wiki-toc-subsection">Subsection</a></li>\n'
|
||||
"</ul>\n"
|
||||
"</li>\n"
|
||||
"</ul>\n"
|
||||
"</div>\n"
|
||||
'<h1 id="wiki-toc-first-title">First title.<a class="article-edit-title-link" '
|
||||
'href="/_plugin/editsection/header/wiki-toc-first-title/">[edit]</a></h1>\n'
|
||||
"<p>Paragraph 1</p>\n"
|
||||
'<h2 id="wiki-toc-subsection">Subsection<a class="article-edit-title-link" '
|
||||
'href="/_plugin/editsection/header/wiki-toc-subsection/">[edit]</a></h2>\n'
|
||||
"<p>Paragraph 2</p>"
|
||||
)
|
||||
self.assertEqual(md.convert(text), expected_output)
|
||||
|
||||
def test_toc_renders_table_of_content_in_wiki_with_depth(self):
|
||||
md = markdown.ArticleMarkdown(article=self.root_article)
|
||||
text = (
|
||||
"[TOC toc_depth:1]\n"
|
||||
"\n"
|
||||
"# First title.\n"
|
||||
"\n"
|
||||
"Paragraph 1\n"
|
||||
"\n"
|
||||
"## Subsection\n"
|
||||
"\n"
|
||||
"Paragraph 2"
|
||||
)
|
||||
expected_output = (
|
||||
'<div class="toc"><span class="toctitle">Contents</span><ul>\n'
|
||||
'<li><a href="#wiki-toc-first-title">First title.</a></li>\n'
|
||||
"</ul>\n"
|
||||
"</div>\n"
|
||||
'<h1 id="wiki-toc-first-title">First title.<a class="article-edit-title-link" '
|
||||
'href="/_plugin/editsection/header/wiki-toc-first-title/">[edit]</a></h1>\n'
|
||||
"<p>Paragraph 1</p>\n"
|
||||
'<h2 id="wiki-toc-subsection">Subsection<a class="article-edit-title-link" '
|
||||
'href="/_plugin/editsection/header/wiki-toc-subsection/">[edit]</a></h2>\n'
|
||||
"<p>Paragraph 2</p>"
|
||||
)
|
||||
self.assertEqual(md.convert(text), expected_output)
|
||||
|
||||
def test_toc_renders_table_of_content_in_wiki_with_multi_kwargs(self):
|
||||
md = markdown.ArticleMarkdown(article=self.root_article)
|
||||
text = (
|
||||
"[TOC title:'test' toc_depth:'1' anchorlink:'True']\n"
|
||||
"\n"
|
||||
"# First title.\n"
|
||||
"\n"
|
||||
"Paragraph 1\n"
|
||||
"\n"
|
||||
"## Subsection\n"
|
||||
"\n"
|
||||
"Paragraph 2"
|
||||
)
|
||||
expected_output = (
|
||||
'<div class="toc"><span class="toctitle">test</span><ul>\n'
|
||||
'<li><a href="#wiki-toc-first-title">First title.</a></li>\n'
|
||||
"</ul>\n"
|
||||
"</div>\n"
|
||||
'<h1 id="wiki-toc-first-title"><a class="toclink" '
|
||||
'href="#wiki-toc-first-title">First title.</a><a '
|
||||
'class="article-edit-title-link" '
|
||||
'href="/_plugin/editsection/header/wiki-toc-first-title/">[edit]</a></h1>\n'
|
||||
"<p>Paragraph 1</p>\n"
|
||||
'<h2 id="wiki-toc-subsection"><a class="toclink" '
|
||||
'href="#wiki-toc-subsection">Subsection</a><a class="article-edit-title-link" '
|
||||
'href="/_plugin/editsection/header/wiki-toc-subsection/">[edit]</a></h2>\n'
|
||||
"<p>Paragraph 2</p>"
|
||||
)
|
||||
self.assertEqual(md.convert(text), expected_output)
|
||||
|
||||
def test_toc_renders_table_of_content_in_wiki_wrong_type(self):
|
||||
md = markdown.ArticleMarkdown(article=self.root_article)
|
||||
text = (
|
||||
"[TOC anchorlink:Yes]\n"
|
||||
"\n"
|
||||
"# First title.\n"
|
||||
"\n"
|
||||
"Paragraph 1\n"
|
||||
"\n"
|
||||
"## Subsection\n"
|
||||
"\n"
|
||||
"Paragraph 2"
|
||||
)
|
||||
expected_output = (
|
||||
'<div class="toc"><span class="toctitle">Contents</span><ul>\n'
|
||||
'<li><a href="#wiki-toc-first-title">First title.</a><ul>\n'
|
||||
'<li><a href="#wiki-toc-subsection">Subsection</a></li>\n'
|
||||
"</ul>\n"
|
||||
"</li>\n"
|
||||
"</ul>\n"
|
||||
"</div>\n"
|
||||
'<h1 id="wiki-toc-first-title">First title.<a class="article-edit-title-link" '
|
||||
'href="/_plugin/editsection/header/wiki-toc-first-title/">[edit]</a></h1>\n'
|
||||
"<p>Paragraph 1</p>\n"
|
||||
'<h2 id="wiki-toc-subsection">Subsection<a class="article-edit-title-link" '
|
||||
'href="/_plugin/editsection/header/wiki-toc-subsection/">[edit]</a></h2>\n'
|
||||
"<p>Paragraph 2</p>"
|
||||
)
|
||||
self.assertEqual(md.convert(text), expected_output)
|
||||
|
||||
def test_toc_renders_table_of_content_in_wiki_test_bool_one(self):
|
||||
# Test if the integer is 1 and should be True
|
||||
md = markdown.ArticleMarkdown(article=self.root_article)
|
||||
text = (
|
||||
"[TOC anchorlink:1]\n"
|
||||
"\n"
|
||||
"# First title.\n"
|
||||
"\n"
|
||||
"Paragraph 1\n"
|
||||
"\n"
|
||||
"## Subsection\n"
|
||||
"\n"
|
||||
"Paragraph 2"
|
||||
)
|
||||
expected_output = (
|
||||
'<div class="toc"><span class="toctitle">Contents</span><ul>\n'
|
||||
'<li><a href="#wiki-toc-first-title">First title.</a><ul>\n'
|
||||
'<li><a href="#wiki-toc-subsection">Subsection</a></li>\n'
|
||||
"</ul>\n"
|
||||
"</li>\n"
|
||||
"</ul>\n"
|
||||
"</div>\n"
|
||||
'<h1 id="wiki-toc-first-title"><a class="toclink" '
|
||||
'href="#wiki-toc-first-title">First title.</a><a '
|
||||
'class="article-edit-title-link" '
|
||||
'href="/_plugin/editsection/header/wiki-toc-first-title/">[edit]</a></h1>\n'
|
||||
"<p>Paragraph 1</p>\n"
|
||||
'<h2 id="wiki-toc-subsection"><a class="toclink" '
|
||||
'href="#wiki-toc-subsection">Subsection</a><a class="article-edit-title-link" '
|
||||
'href="/_plugin/editsection/header/wiki-toc-subsection/">[edit]</a></h2>\n'
|
||||
"<p>Paragraph 2</p>"
|
||||
)
|
||||
self.assertEqual(md.convert(text), expected_output)
|
||||
|
||||
def test_toc_renders_table_of_content_in_wiki_test_bool_zero(self):
|
||||
# Test if the integer is zero and should be false
|
||||
md = markdown.ArticleMarkdown(article=self.root_article)
|
||||
text = (
|
||||
"[TOC anchorlink:0]\n"
|
||||
"\n"
|
||||
"# First title.\n"
|
||||
"\n"
|
||||
"Paragraph 1\n"
|
||||
"\n"
|
||||
"## Subsection\n"
|
||||
"\n"
|
||||
"Paragraph 2"
|
||||
)
|
||||
expected_output = (
|
||||
'<div class="toc"><span class="toctitle">Contents</span><ul>\n'
|
||||
'<li><a href="#wiki-toc-first-title">First title.</a><ul>\n'
|
||||
'<li><a href="#wiki-toc-subsection">Subsection</a></li>\n'
|
||||
"</ul>\n"
|
||||
"</li>\n"
|
||||
"</ul>\n"
|
||||
"</div>\n"
|
||||
'<h1 id="wiki-toc-first-title">First title.<a class="article-edit-title-link" '
|
||||
'href="/_plugin/editsection/header/wiki-toc-first-title/">[edit]</a></h1>\n'
|
||||
"<p>Paragraph 1</p>\n"
|
||||
'<h2 id="wiki-toc-subsection">Subsection<a class="article-edit-title-link" '
|
||||
'href="/_plugin/editsection/header/wiki-toc-subsection/">[edit]</a></h2>\n'
|
||||
"<p>Paragraph 2</p>"
|
||||
)
|
||||
self.assertEqual(md.convert(text), expected_output)
|
||||
|
||||
def test_toc_renders_table_of_content_in_wiki_test_bool_wrong(self):
|
||||
# Test if the integer is wrong value
|
||||
md = markdown.ArticleMarkdown(article=self.root_article)
|
||||
text = (
|
||||
"[TOC anchorlink:5]\n"
|
||||
"\n"
|
||||
"# First title.\n"
|
||||
"\n"
|
||||
"Paragraph 1\n"
|
||||
"\n"
|
||||
"## Subsection\n"
|
||||
"\n"
|
||||
"Paragraph 2"
|
||||
)
|
||||
expected_output = (
|
||||
'<div class="toc"><span class="toctitle">Contents</span><ul>\n'
|
||||
'<li><a href="#wiki-toc-first-title">First title.</a><ul>\n'
|
||||
'<li><a href="#wiki-toc-subsection">Subsection</a></li>\n'
|
||||
"</ul>\n"
|
||||
"</li>\n"
|
||||
"</ul>\n"
|
||||
"</div>\n"
|
||||
'<h1 id="wiki-toc-first-title">First title.<a class="article-edit-title-link" '
|
||||
'href="/_plugin/editsection/header/wiki-toc-first-title/">[edit]</a></h1>\n'
|
||||
"<p>Paragraph 1</p>\n"
|
||||
'<h2 id="wiki-toc-subsection">Subsection<a class="article-edit-title-link" '
|
||||
'href="/_plugin/editsection/header/wiki-toc-subsection/">[edit]</a></h2>\n'
|
||||
"<p>Paragraph 2</p>"
|
||||
)
|
||||
self.assertEqual(md.convert(text), expected_output)
|
||||
Reference in New Issue
Block a user