You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/08/26 16:00:42 UTC

[03/50] git commit: [#3154] ticket:388 Export wiki

[#3154] ticket:388 Export wiki


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

Branch: refs/heads/tv/6595
Commit: b5f79e6fa5a9dd405f59bc1890026de8d97e018e
Parents: 449d9e7
Author: Igor Bondarenko <je...@gmail.com>
Authored: Fri Jul 5 13:45:13 2013 +0300
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Aug 22 20:04:40 2013 +0000

----------------------------------------------------------------------
 ForgeWiki/forgewiki/tests/test_app.py | 78 ++++++++++++++++++++++++++++++
 ForgeWiki/forgewiki/wiki_main.py      | 15 ++++--
 2 files changed, 90 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b5f79e6f/ForgeWiki/forgewiki/tests/test_app.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/tests/test_app.py b/ForgeWiki/forgewiki/tests/test_app.py
new file mode 100644
index 0000000..b6db6a2
--- /dev/null
+++ b/ForgeWiki/forgewiki/tests/test_app.py
@@ -0,0 +1,78 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+
+import datetime
+import tempfile
+import json
+import operator
+
+from nose.tools import assert_equal
+
+from allura import model as M
+from allura.tests import decorators as td
+from alluratest.controller import setup_basic_test, setup_global_objects
+from forgewiki import model as WM
+
+
+class TestBulkExport(object):
+
+    def setUp(self):
+        setup_basic_test()
+        setup_global_objects()
+        self.setup_with_tools()
+
+    @td.with_wiki
+    def setup_with_tools(self):
+        self.project = M.Project.query.get(shortname='test')
+        self.wiki = self.project.app_instance('wiki')
+        page = WM.Page.upsert('A New Hope')
+        page.text = 'Star Wars Episode IV: A New Hope'
+        page.mod_date = datetime.datetime(2013, 7, 5)
+        page.labels = ['star wars', 'movies']
+        page.commit()
+        page.discussion_thread.add_post(text='Embrace the Dark Side')
+        page.discussion_thread.add_post(text='Nope')
+        page = WM.Page.upsert('The Empire Strikes Back')
+        page.text = 'Star Wars Episode V: The Empire Strikes Back'
+        page.commit()
+        page = WM.Page.upsert('Return of the Jedi')
+        page.text = 'Star Wars Episode VI: Return of the Jedi'
+        page.commit()
+        page = WM.Page.query.get(app_config_id=self.wiki.config._id, title='Home')
+        page.deleted = True
+        page.commit()
+
+    def test_bulk_export(self):
+        f = tempfile.TemporaryFile()
+        self.wiki.bulk_export(f)
+        f.seek(0)
+        wiki = json.loads(f.read())
+        pages = sorted(wiki['pages'], key=operator.itemgetter('title'))
+        assert_equal(len(pages), 3)
+        assert_equal(pages[0]['title'], 'A New Hope')
+        assert_equal(pages[0]['text'], 'Star Wars Episode IV: A New Hope')
+        assert_equal(pages[0]['mod_date'], '2013-07-05 00:00:00')
+        assert_equal(pages[0]['labels'], ['star wars', 'movies'])
+        assert_equal(len(pages[0]['discussion_thread']['posts']), 2)
+
+        assert_equal(pages[1]['title'], 'Return of the Jedi')
+        assert_equal(pages[1]['text'], 'Star Wars Episode VI: Return of the Jedi')
+        assert_equal(len(pages[1]['discussion_thread']['posts']), 0)
+
+        assert_equal(pages[2]['title'], 'The Empire Strikes Back')
+        assert_equal(pages[2]['text'], 'Star Wars Episode V: The Empire Strikes Back')
+        assert_equal(len(pages[2]['discussion_thread']['posts']), 0)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b5f79e6f/ForgeWiki/forgewiki/wiki_main.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index 30b4860..f27ff73 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -16,13 +16,14 @@
 #       under the License.
 
 #-*- python -*-
+import json
 import logging
 from pprint import pformat
 from urllib import unquote
 from datetime import datetime
 
 # Non-stdlib imports
-from tg import expose, validate, redirect, response, flash
+from tg import expose, validate, redirect, response, flash, jsonify
 from tg.decorators import with_trailing_slash, without_trailing_slash
 from tg.controllers import RestController
 from pylons import tmpl_context as c, app_globals as g
@@ -287,8 +288,16 @@ The wiki uses [Markdown](%s) syntax.
         super(ForgeWikiApp, self).uninstall(project)
 
     def bulk_export(self, f):
-        # TODO: implement this
-        f.write('{}\n')
+        f.write('{"pages": [')
+        pages = WM.Page.query.find(dict(
+            app_config_id=self.config._id,
+            deleted=False)).all()
+        count = len(pages)
+        for i, page in enumerate(pages):
+            json.dump(page, f, cls=jsonify.GenericJSON)
+            if i < (count - 1):
+                f.write(',')
+        f.write(']}')
 
 
 class RootController(BaseController, DispatchIndex, FeedController):