incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [25/50] git commit: [#6534] ticket:442 refactored code and fixed tests
Date Wed, 09 Oct 2013 12:48:41 GMT
[#6534] ticket:442 refactored code and fixed tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/0d66ce83
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/0d66ce83
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/0d66ce83

Branch: refs/heads/cj/6422
Commit: 0d66ce83295d7aedb2311fb060f0633ec3b4e0ad
Parents: f8a82e7
Author: coldmind <sokandpal@yandex.ru>
Authored: Thu Sep 26 15:37:32 2013 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Oct 4 14:21:23 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_wiki.py    | 50 +++++++++-----------
 ForgeImporters/forgeimporters/github/wiki.py    | 37 ++++++++++-----
 2 files changed, 48 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0d66ce83/ForgeImporters/forgeimporters/github/tests/test_wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_wiki.py b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
index 0f6bf26..46e58e4 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -143,8 +143,8 @@ class TestGitHubWikiImporter(TestCase):
     @patch('forgeimporters.github.wiki.WM.Page.upsert')
     @patch('forgeimporters.github.wiki.mediawiki2markdown')
     def test_with_history_mediawiki(self, md2mkm, upsert):
-        self.commit2.stats.files = {"Home.md": self.blob1}
-        self.commit2.tree = {"Home.md": self.blob1}
+        self.commit2.stats.files = {"Home.mediawiki": self.blob1}
+        self.commit2.tree = {"Home.mediawiki": self.blob1}
         importer = GitHubWikiImporter()
         importer.github_wiki_url = 'https://github.com/a/b/wiki'
         importer.app = Mock()
@@ -256,7 +256,7 @@ Our website is <http://sf.net>.
 
 [External link](https://github.com/a/b/issues/1)\n\n'''
 
-        assert_equal(f(source, 'test.md', None), result)
+        assert_equal(f(source, 'test.md'), result)
 
     @without_module('html2text')
     def test_convert_markup_without_html2text(self):
@@ -284,7 +284,7 @@ Our website is [[http://sf.net]].
 <p><a class="" href="/p/test/wiki/Page" rel="nofollow">External link to the wiki
page</a></p>
 <p><a class="" href="https://github.com/a/b/issues/1" rel="nofollow">External
link</a></p></div>'''
 
-        assert_equal(f(source, 'test.md', None), result)
+        assert_equal(f(source, 'test.md'), result)
 
     def test_rewrite_links(self):
         f = GitHubWikiImporter().rewrite_links
@@ -301,38 +301,32 @@ Our website is [[http://sf.net]].
         assert_equal(f(u'<a href="https://github/a/b/wiki/Test Page">Test <b>Page</b></a>',
prefix, new),
                      u'<a href="/p/test/wiki/Test Page">Test <b>Page</b></a>')
 
+    @skipif(module_not_available('html2text'))
     def test_convert_markup_with_mediawiki2markdown(self):
         importer = GitHubWikiImporter()
         importer.github_wiki_url = 'https://github.com/a/b/wiki'
         importer.app = Mock()
         importer.app.url = '/p/test/wiki/'
         f = importer.convert_markup
-        source = u'''Look at [[this page|Some Page]]
-
-More info at: [[MoreInfo]] [[Even More Info]]
-
-Our website is [[http://sf.net]].
-
-'[[Escaped Tag]]
-
-[External link to the wiki page](https://github.com/a/b/wiki/Page)
-
-[External link](https://github.com/a/b/issues/1)'''
-
-        result = u'''Look at [this page](Some Page) 
-
-More info at: [MoreInfo] [Even More Info] 
-
-Our website is [[http://sf.net](http://sf.net)]. 
-
-[[Escaped Tag]] 
-
-[External link to the wiki page](https://github.com/a/b/wiki/Page) 
-
-[External link](https://github.com/a/b/issues/1) 
+        source = u'''
+''-- Al'fredas 235 BC''
+== See also ==
+* [https://github/a/b/wiki/AgentSpring-running-instructions-for-d13n-model Test1]
+* [https://github/a/b/wiki/AgentSpring-conventions Test2]
+* [https://github/a/b/wiki/AgentSpring-Q&A Test3]
+* [https://github/a/b/wiki/Extensions Test4]'''
+
+        result = u'''_-- Al'fredas 235 BC_
+
+## See also
+
+  * [Test1](https://github/a/b/wiki/AgentSpring-running-instructions-for-d13n-model)
+  * [Test2](https://github/a/b/wiki/AgentSpring-conventions)
+  * [Test3](https://github/a/b/wiki/AgentSpring-Q&A)
+  * [Test4](https://github/a/b/wiki/Extensions)
 '''
 
-        assert_equal(f(source, 'test.md', 'md'), result)
+        assert_equal(f(source, 'test.mediawiki'), result)
 
 
 class TestGitHubWikiImportController(TestController, TestCase):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0d66ce83/ForgeImporters/forgeimporters/github/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/wiki.py b/ForgeImporters/forgeimporters/github/wiki.py
index 0f0693a..fa08d0c 100644
--- a/ForgeImporters/forgeimporters/github/wiki.py
+++ b/ForgeImporters/forgeimporters/github/wiki.py
@@ -194,7 +194,7 @@ class GitHubWikiImporter(ToolImporter):
         name = self._convert_page_name(name)
         wiki_page = WM.Page.upsert(name)
         if filename in commit.tree:
-            wiki_page.text = self.convert_markup(h.really_unicode(text), filename, ext)
+            wiki_page.text = self.convert_markup(h.really_unicode(text), filename)
             wiki_page.timestamp = wiki_page.mod_date = mod_date
             wiki_page.viewable_by = ['all']
         else:
@@ -218,7 +218,7 @@ class GitHubWikiImporter(ToolImporter):
                 self._with_history(commit)
         rmtree(wiki_path)
 
-    def convert_markup(self, text, filename, ext):
+    def convert_markup(self, text, filename):
         """Convert any supported github markup into Allura-markdown.
 
         Conversion happens in 4 phases:
@@ -238,17 +238,32 @@ class GitHubWikiImporter(ToolImporter):
         except ImportError:
             html2text = None
 
-        if html2text and ext in ['md', 'mediawiki']:
-            text = mediawiki2markdown(text)
-            text = self.convert_gollum_tags(text)
+        name_and_ext = filename.split('.', 1)
+        if len(name_and_ext) == 1:
+            name, ext = name_and_ext[0], None
         else:
-            text = h.render_any_markup(filename, text)
+            name, ext = name_and_ext
 
-        text = self.rewrite_links(text, self.github_wiki_url, self.app.url)
-        if html2text and ext not in ['md', 'mediawiki']:
-            text = html2text.html2text(text)
-            text = self.convert_gollum_tags(text)
-        return text
+        is_mediawiki = False
+        if ext and ext in ['wiki', 'mediawiki']:
+            is_mediawiki = True
+
+        if is_mediawiki:
+            if html2text:
+                text = mediawiki2markdown(text)
+                text = self.convert_gollum_tags(text)
+                text = text.replace(self.github_wiki_url, self.app.url)
+            else:
+                text = h.render_any_markup(filename, text)
+                text = self.rewrite_links(text, self.github_wiki_url, self.app.url)
+            return text
+        else:
+            text = h.render_any_markup(filename, text)
+            text = self.rewrite_links(text, self.github_wiki_url, self.app.url)
+            if html2text:
+                text = html2text.html2text(text)
+                text = self.convert_gollum_tags(text)
+            return text
 
     def convert_gollum_tags(self, text):
         tag_re = re.compile(r'''


Mime
View raw message