From 39402b5f43b82536e4821aa77b995c7211047e5a Mon Sep 17 00:00:00 2001 From: Mathias Rav Date: Thu, 26 Jul 2018 12:54:54 +0200 Subject: [PATCH] Add more tests --- tests/plugins/macros/test_links.py | 2 +- tests/plugins/redlinks/test_redlinks.py | 65 ++++++++++++++++++------- 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/tests/plugins/macros/test_links.py b/tests/plugins/macros/test_links.py index 0b6e48da..05267b4f 100644 --- a/tests/plugins/macros/test_links.py +++ b/tests/plugins/macros/test_links.py @@ -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, '

Root Article

' + md_text, '

Root Article

' ) diff --git a/tests/plugins/redlinks/test_redlinks.py b/tests/plugins/redlinks/test_redlinks.py index 5a9658f2..55c86985 100644 --- a/tests/plugins/redlinks/test_redlinks.py +++ b/tests/plugins/redlinks/test_redlinks.py @@ -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) -- 2.45.2