~netlandish/django-wiki

39402b5f43b82536e4821aa77b995c7211047e5a — Mathias Rav 6 years ago a0efe12
Add more tests
2 files changed, 48 insertions(+), 19 deletions(-)

M tests/plugins/macros/test_links.py
M tests/plugins/redlinks/test_redlinks.py
M tests/plugins/macros/test_links.py => tests/plugins/macros/test_links.py +1 -1
@@ 7,5 7,5 @@ class WikiLinksTests(RequireRootArticleMixin, TestBase):
        md = markdown.ArticleMarkdown(article=self.root_article)
        md_text = md.convert('[[Root Article]]')
        self.assertEqual(
            md_text, '<p><a class="wiki_wikilink wiki_external" href="/Root_Article/">Root Article</a></p>'
            md_text, '<p><a class="wiki_wikilink wiki-external" href="/Root_Article/">Root Article</a></p>'
        )

M tests/plugins/redlinks/test_redlinks.py => tests/plugins/redlinks/test_redlinks.py +47 -18
@@ 1,25 1,54 @@
from tests.base import RequireRootArticleMixin, TestBase
from wiki.core import markdown
from wiki.models import URLPath


class RedlinksTests(RequireRootArticleMixin, TestBase):
    def test_internal(self):
        md = markdown.ArticleMarkdown(article=self.root_article)
        md_text = md.convert("[Internal](.)")
        self.assertIn("wiki-internal", md_text)
        self.assertNotIn("wiki-external", md_text)
        self.assertNotIn("wiki-broken", md_text)
    def setUp(self):
        super().setUp()
        self.child = URLPath.create_urlpath(self.root, 'child')

    def test_root_to_self(self):
        self.assert_internal(self.root, "[Internal](./)")

    def test_root_to_child(self):
        self.assert_internal(self.root, "[Child](child/)")

    def test_child_to_self(self):
        self.assert_internal(self.child, "[Child](../child/)")

    def test_child_to_self_no_slash(self):
        self.assert_internal(self.child, "[Child](../child)")

    def test_root_to_outside(self):
        self.assert_external(self.root, "[Outside](../test/)")

    def test_external(self):
        md = markdown.ArticleMarkdown(article=self.root_article)
        md_text = md.convert("[External](/)")
        self.assertNotIn("wiki-internal", md_text)
        self.assertIn("wiki-external", md_text)
        self.assertNotIn("wiki-broken", md_text)

    def test_broken(self):
        md = markdown.ArticleMarkdown(article=self.root_article)
        md_text = md.convert("[Broken](broken)")
        self.assertNotIn("wiki-internal", md_text)
        self.assertNotIn("wiki-external", md_text)
        self.assertIn("wiki-broken", md_text)
        self.assert_external(self.root, "[External](/)")

    def test_child_to_broken(self):
        self.assert_broken(self.child, "[Broken](../broken/)")

    def test_root_to_broken(self):
        self.assert_broken(self.root, "[Broken](broken/)")

    def assert_internal(self, urlpath, md_text):
        md = markdown.ArticleMarkdown(article=urlpath.article)
        html = md.convert(md_text)
        self.assertIn("wiki-internal", html)
        self.assertNotIn("wiki-external", html)
        self.assertNotIn("wiki-broken", html)

    def assert_external(self, urlpath, md_text):
        md = markdown.ArticleMarkdown(article=urlpath.article)
        html = md.convert(md_text)
        self.assertNotIn("wiki-internal", html)
        self.assertIn("wiki-external", html)
        self.assertNotIn("wiki-broken", html)

    def assert_broken(self, urlpath, md_text):
        md = markdown.ArticleMarkdown(article=urlpath.article)
        html = md.convert(md_text)
        self.assertNotIn("wiki-internal", html)
        self.assertNotIn("wiki-external", html)
        self.assertIn("wiki-broken", html)