[#4186] ticket:57 add test case

bolkimen bolkimen 2012-05-25

Dave Brondsema Dave Brondsema 2012-08-07

added ForgeWiki/forgewiki/converters.py
copied ForgeWiki/forgewiki/import_support.py -> ForgeWiki/forgewiki/tests/test_converters.py
ForgeWiki/forgewiki/converters.py Diff Switch to side-by-side view
Loading...
ForgeWiki/forgewiki/import_support.py to ForgeWiki/forgewiki/tests/test_converters.py
--- a/ForgeWiki/forgewiki/import_support.py
+++ b/ForgeWiki/forgewiki/tests/test_converters.py
@@ -1,28 +1,30 @@
-#-*- python -*-
-import html2text
-import bbcode
-# https://github.com/zikzakmedia/python-mediawiki.git
-from mediawiki import *
+from pylons import c, g
 
-class ImportSupport(object):
-    @staticmethod
-    def mediawiki2markdown(source):
-        p = bbcode.Parser(newline='\n', escape_html=False, replace_links=False, replace_cosmetic=False)
-        cleanbb_text = p.format(mediawiki_text)
-        wiki_content = wiki2html(cleanbb_text, True)
-        markdown_text = html2text.html2text(wiki_content)
-        return markdown_text
+from nose.tools import assert_equal
 
-if __name__ == "__main__":
-    mediawiki_text = """[b]bolded text[/b][i]italicized text[/i]
+from alluratest.controller import setup_basic_test, setup_global_objects
+from allura.tests import decorators as td
+from forgewiki import converters
 
+def setUp():
+    setup_basic_test()
+    setup_with_tools()
+
+@td.with_wiki
+def setup_with_tools():
+    setup_global_objects()
+    g.set_app('wiki')
+
+def test_mediawiki2markdown():
+    bbcode_text = "[b]bolded text[/b][i]italicized text[/i]"
+    bbcode_output = converters.mediawiki2markdown(bbcode_text)
+    assert "**bolded text**_italicized text_" in bbcode_output
+
+    mediawiki_text = """
 == Getting started ==
 * [http://www.mediawiki.org/wiki/Manual:Configuration_settings Configuration settings list]
 * [http://www.mediawiki.org/wiki/Manual:FAQ MediaWiki FAQ]
-* [http://lists.wikimedia.org/mailman/listinfo/mediawiki-announce MediaWiki release mailing list]
-
-This is a sample attachment:
-
-[[Image:MediaWikiSidebarLogo.png]]
-"""
-    markdown_text = ImportSupport.mediawiki2markdown(mediawiki_text)
+    """
+    mediawiki_output = converters.mediawiki2markdown(mediawiki_text)
+    assert "## Getting started" in mediawiki_output
+    assert "* [MediaWiki FAQ](http://www.mediawiki.org/wiki/Manual:FAQ)" in mediawiki_output