incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [22/50] git commit: [#6534] ticket:443 Import wiki into existing project
Date Fri, 04 Oct 2013 18:07:06 GMT
[#6534] ticket:443 Import wiki into existing project


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

Branch: refs/heads/cj/6692
Commit: 2de9c9cfc760663b432e16bee003e8d1e146de4f
Parents: 0f5a8ff
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Thu Sep 19 12:48:46 2013 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Oct 4 14:21:21 2013 +0000

----------------------------------------------------------------------
 .../github/templates/wiki/index.html            | 41 ++++++++++++
 .../forgeimporters/github/tests/test_wiki.py    | 57 +++++++++++++++--
 ForgeImporters/forgeimporters/github/wiki.py    | 67 +++++++++++++++++++-
 3 files changed, 160 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2de9c9cf/ForgeImporters/forgeimporters/github/templates/wiki/index.html
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/templates/wiki/index.html b/ForgeImporters/forgeimporters/github/templates/wiki/index.html
new file mode 100644
index 0000000..703672e
--- /dev/null
+++ b/ForgeImporters/forgeimporters/github/templates/wiki/index.html
@@ -0,0 +1,41 @@
+{#-
+       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.
+-#}
+{% extends 'forgeimporters:templates/importer_base.html' %}
+
+{% block title %}
+{{c.project.name}} / Import your wiki from GitHub
+{% endblock %}
+
+{% block importer_fields %}
+<div>
+  <label for="gh_user_name">GitHub User Name</label>
+  <input name="gh_user_name" value="{{ c.form_values['gh_user_name'] }}" />
+  {{ error('gh_user_name') }}
+</div>
+<div>
+  <label for="gh_project_name">GitHub Project Name</label>
+  <input name="gh_project_name" value="{{ c.form_values['gh_project_name'] }}" />
+  {{ error('gh_project_name') }}
+</div>
+<div>
+  <label for="tool_option">Import wiki history</label>
+  <input name="tool_option" value="history_github_wiki" type="checkbox" {% if c.form_values['tool_option']
== 'history_github_wiki'  %} checked="checked"{% endif %}/>
+  {{ error('tool_option') }}
+</div>
+{% endblock %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2de9c9cf/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 d37abd1..83bc58a 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -15,13 +15,19 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
-import datetime
-
 from unittest import TestCase
 from nose.tools import assert_equal
 from mock import Mock, patch, call
-from forgeimporters.github.wiki import GitHubWikiImporter
+
+from allura.tests import TestController
+from allura.tests.decorators import with_tool
 from alluratest.controller import setup_basic_test
+from forgeimporters.github.wiki import GitHubWikiImporter
+
+
+# important to be distinct from 'test' which ForgeWiki uses, so that the tests can run in
parallel and not clobber each other
+test_project_with_wiki = 'test2'
+with_wiki = with_tool(test_project_with_wiki, 'wiki', 'w', 'wiki')
 
 
 class TestGitHubRepoImporter(TestCase):
@@ -114,4 +120,47 @@ class TestGitHubWikiImporter(TestCase):
         self.commit2.tree = {"Home.md": self.blob1}
         GitHubWikiImporter().get_blobs_with_history(self.commit2)
         assert_equal(upsert.call_args_list, [call('Home')])
-        assert_equal(render.call_args_list, [call('Home.md', u'# test message')])
\ No newline at end of file
+        assert_equal(render.call_args_list, [call('Home.md', u'# test message')])
+
+
+class TestGitHubWikiImportController(TestController, TestCase):
+
+    url = '/p/%s/admin/ext/import/github-wiki/' % test_project_with_wiki
+
+    @with_wiki
+    def test_index(self):
+        r = self.app.get(self.url)
+        self.assertIsNotNone(r.html.find(attrs=dict(name='gh_user_name')))
+        self.assertIsNotNone(r.html.find(attrs=dict(name='gh_project_name')))
+        self.assertIsNotNone(r.html.find(attrs=dict(name='mount_label')))
+        self.assertIsNotNone(r.html.find(attrs=dict(name='mount_point')))
+        self.assertIsNotNone(r.html.find(attrs=dict(name='tool_option', value='history_github_wiki')))
+
+    @with_wiki
+    @patch('forgeimporters.github.wiki.import_tool')
+    def test_create(self, import_tool):
+        params = dict(
+            gh_user_name='spooky',
+            gh_project_name='mulder',
+            mount_point='gh-wiki',
+            mount_label='GitHub Wiki',
+            tool_option='history_github_wiki')
+        r = self.app.post(self.url + 'create', params, status=302)
+        self.assertEqual(r.location, 'http://localhost/p/%s/admin/' % test_project_with_wiki)
+        args = import_tool.post.call_args[1]
+        self.assertEqual(u'GitHub Wiki', args['mount_label'])
+        self.assertEqual(u'gh-wiki', args['mount_point'])
+        self.assertEqual(u'mulder', args['project_name'])
+        self.assertEqual(u'spooky', args['user_name'])
+        self.assertEqual(u'history_github_wiki', args['tool_option'])
+
+        # without history
+        params.pop('tool_option')
+        r = self.app.post(self.url + 'create', params, status=302)
+        self.assertEqual(r.location, 'http://localhost/p/%s/admin/' % test_project_with_wiki)
+        args = import_tool.post.call_args[1]
+        self.assertEqual(u'GitHub Wiki', args['mount_label'])
+        self.assertEqual(u'gh-wiki', args['mount_point'])
+        self.assertEqual(u'mulder', args['project_name'])
+        self.assertEqual(u'spooky', args['user_name'])
+        self.assertEqual(u'', args['tool_option'])

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2de9c9cf/ForgeImporters/forgeimporters/github/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/wiki.py b/ForgeImporters/forgeimporters/github/wiki.py
index 3edf0c8..319b253 100644
--- a/ForgeImporters/forgeimporters/github/wiki.py
+++ b/ForgeImporters/forgeimporters/github/wiki.py
@@ -23,10 +23,30 @@ import git
 from pylons import app_globals as g
 from pylons import tmpl_context as c
 from ming.orm import ThreadLocalORMSession
+from formencode import validators as fev
+from tg import (
+        expose,
+        validate,
+        flash,
+        redirect,
+        )
+from tg.decorators import (
+        with_trailing_slash,
+        without_trailing_slash,
+        )
 
+from allura.controllers import BaseController
 from allura.lib import helpers as h
+from allura.lib.decorators import (
+        require_post,
+        task,
+        )
 from allura import model as M
-from forgeimporters.base import ToolImporter
+from forgeimporters.base import (
+        ToolImporter,
+        ToolImportForm,
+        ImportErrorHandler,
+        )
 from forgeimporters.github import GitHubProjectExtractor
 from forgewiki import model as WM
 
@@ -42,8 +62,53 @@ except ImportError:
     pass
 
 
+@task(notifications_disabled=True)
+def import_tool(**kw):
+    importer = GitHubWikiImporter()
+    with ImportErrorHandler(importer, kw.get('project_name'), c.project):
+        importer.import_tool(c.project, c.user, **kw)
+
+
+class GitHubWikiImportForm(ToolImportForm):
+    gh_project_name = fev.UnicodeString(not_empty=True)
+    gh_user_name = fev.UnicodeString(not_empty=True)
+    tool_option = fev.UnicodeString(if_missing=u'')
+
+
+class GitHubWikiImportController(BaseController):
+
+    def __init__(self):
+        self.importer = GitHubWikiImporter()
+
+    @property
+    def target_app(self):
+        return self.importer.target_app[0]
+
+    @with_trailing_slash
+    @expose('jinja:forgeimporters.github:templates/wiki/index.html')
+    def index(self, **kw):
+        return dict(importer=self.importer,
+                    target_app=self.target_app)
+
+    @without_trailing_slash
+    @expose()
+    @require_post()
+    @validate(GitHubWikiImportForm(ForgeWikiApp), error_handler=index)
+    def create(self, gh_project_name, gh_user_name, mount_point, mount_label, **kw):
+        import_tool.post(
+            project_name=gh_project_name,
+            user_name=gh_user_name,
+            mount_point=mount_point,
+            mount_label=mount_label,
+            tool_option=kw.get('tool_option'))
+        flash('Wiki import has begun. Your new wiki will be available '
+              'when the import is complete.')
+        redirect(c.project.url() + 'admin/')
+
+
 class GitHubWikiImporter(ToolImporter):
     target_app = TARGET_APPS
+    controller = GitHubWikiImportController
     source = 'GitHub'
     tool_label = 'Wiki'
     tool_description = 'Import your wiki from GitHub'


Mime
View raw message