You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/08/07 18:48:07 UTC
[05/11] git commit: [#6480] Add tests for Trac wiki importer
[#6480] Add tests for Trac wiki importer
Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/2379488a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/2379488a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/2379488a
Branch: refs/heads/master
Commit: 2379488ac978b40c027f28720c92a97d9d54a585
Parents: 8a365f7
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Tue Aug 6 21:59:58 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Aug 7 16:47:24 2013 +0000
----------------------------------------------------------------------
.../forgeimporters/trac/tests/test_tickets.py | 1 +
.../forgeimporters/trac/tests/test_wiki.py | 88 ++++++++++++++++++++
ForgeImporters/forgeimporters/trac/tickets.py | 2 +-
ForgeImporters/forgeimporters/trac/wiki.py | 2 +-
4 files changed, 91 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2379488a/ForgeImporters/forgeimporters/trac/tests/test_tickets.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/trac/tests/test_tickets.py b/ForgeImporters/forgeimporters/trac/tests/test_tickets.py
index 8b102a9..2cce886 100644
--- a/ForgeImporters/forgeimporters/trac/tests/test_tickets.py
+++ b/ForgeImporters/forgeimporters/trac/tests/test_tickets.py
@@ -84,6 +84,7 @@ class TestTracTicketImportController(TestController, TestCase):
@patch('forgeimporters.trac.tickets.TracTicketImporter')
def test_create(self, importer):
from allura import model as M
+ importer = importer.return_value
importer.import_tool.return_value = Mock()
importer.import_tool.return_value.url.return_value = '/p/test/mymount'
params = dict(trac_url='http://example.com/trac/url',
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2379488a/ForgeImporters/forgeimporters/trac/tests/test_wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/trac/tests/test_wiki.py b/ForgeImporters/forgeimporters/trac/tests/test_wiki.py
index 77505f1..71cc8b5 100644
--- a/ForgeImporters/forgeimporters/trac/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/trac/tests/test_wiki.py
@@ -15,3 +15,91 @@
# specific language governing permissions and limitations
# under the License.
+from unittest import TestCase
+from mock import Mock, patch
+
+from allura.tests import TestController
+from allura.tests.decorators import with_wiki
+
+from forgeimporters.trac.wiki import (
+ TracWikiImporter,
+ TracWikiImportController,
+ )
+
+
+class TestWikiTicketImporter(TestCase):
+ @patch('forgeimporters.trac.wiki.session')
+ @patch('forgeimporters.trac.wiki.tempfile.NamedTemporaryFile')
+ @patch('forgeimporters.trac.wiki.g')
+ @patch('forgeimporters.trac.wiki.WikiFromTrac')
+ @patch('forgeimporters.trac.wiki.load_data')
+ @patch('forgeimporters.trac.wiki.argparse.Namespace')
+ @patch('forgeimporters.trac.wiki.WikiExporter')
+ @patch('forgeimporters.trac.wiki.ApiTicket')
+ @patch('forgeimporters.trac.wiki.datetime')
+ def test_import_tool(self, dt, ApiTicket, WikiExporter, Namespace,
+ load_data, WikiFromTrac, g, NamedTemporaryFile, session):
+ from datetime import datetime, timedelta
+ now = datetime.utcnow()
+ dt.utcnow.return_value = now
+ export_file = NamedTemporaryFile.return_value.__enter__.return_value
+ export_file.name = '/my/file'
+
+ importer = TracWikiImporter()
+ app = Mock(name='ForgeWikiApp')
+ project = Mock(name='Project', shortname='myproject')
+ project.install_app.return_value = app
+ user = Mock(name='User', _id='id')
+ res = importer.import_tool(project=project,
+ mount_point='pages',
+ mount_label='Pages',
+ trac_url='http://example.com/trac/url',
+ user=user)
+ self.assertEqual(res, app)
+ project.install_app.assert_called_once_with(
+ 'Wiki', mount_point='pages', mount_label='Pages')
+ ApiTicket.assert_called_once_with(
+ user_id=user._id,
+ capabilities={"import": ["Projects", "myproject"]},
+ expires=now + timedelta(minutes=60))
+ WikiExporter.assert_called_once_with('http://example.com/trac/url/',
+ Namespace.return_value)
+ WikiExporter.return_value.export.assert_called_once_with(export_file)
+ load_data.assert_called_once_with('/my/file',
+ WikiFromTrac.parser.return_value, Namespace.return_value)
+ g.post_event.assert_called_once_with('project_updated')
+
+
+class TestTracWikiImportController(TestController, TestCase):
+ def setUp(self):
+ """Mount Trac import controller on the Wiki admin controller"""
+ super(self.__class__, self).setUp()
+ from forgewiki.wiki_main import WikiAdminController
+ WikiAdminController._importer = TracWikiImportController()
+
+ @with_wiki
+ def test_index(self):
+ r = self.app.get('/p/test/admin/wiki/_importer/')
+ self.assertIsNotNone(r.html.find(attrs=dict(name="trac_url")))
+ self.assertIsNotNone(r.html.find(attrs=dict(name="mount_label")))
+ self.assertIsNotNone(r.html.find(attrs=dict(name="mount_point")))
+
+ @with_wiki
+ @patch('forgeimporters.trac.wiki.TracWikiImporter')
+ def test_create(self, importer):
+ from allura import model as M
+ importer = importer.return_value
+ importer.import_tool.return_value = Mock()
+ importer.import_tool.return_value.url.return_value = '/p/test/mymount'
+ params = dict(trac_url='http://example.com/trac/url',
+ mount_label='mylabel',
+ mount_point='mymount',
+ )
+ r = self.app.post('/p/test/admin/wiki/_importer/create', params,
+ status=302)
+ project = M.Project.query.get(shortname='test')
+ self.assertEqual(r.location, 'http://localhost/p/test/mymount')
+ self.assertEqual(project._id, importer.import_tool.call_args[0][0]._id)
+ self.assertEqual(u'mymount', importer.import_tool.call_args[1]['mount_point'])
+ self.assertEqual(u'mylabel', importer.import_tool.call_args[1]['mount_label'])
+ self.assertEqual(u'http://example.com/trac/url', importer.import_tool.call_args[1]['trac_url'])
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2379488a/ForgeImporters/forgeimporters/trac/tickets.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/trac/tickets.py b/ForgeImporters/forgeimporters/trac/tickets.py
index 0f13649..78d8d17 100644
--- a/ForgeImporters/forgeimporters/trac/tickets.py
+++ b/ForgeImporters/forgeimporters/trac/tickets.py
@@ -69,7 +69,7 @@ class TracTicketImportController(BaseController):
@require_post()
@validate(TracTicketImportSchema(), error_handler=index)
def create(self, trac_url, mount_point, mount_label, **kw):
- app = TracTicketImporter.import_tool(c.project,
+ app = TracTicketImporter().import_tool(c.project,
mount_point=mount_point,
mount_label=mount_label,
trac_url=trac_url,
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2379488a/ForgeImporters/forgeimporters/trac/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/trac/wiki.py b/ForgeImporters/forgeimporters/trac/wiki.py
index e7ead86..00f0d48 100644
--- a/ForgeImporters/forgeimporters/trac/wiki.py
+++ b/ForgeImporters/forgeimporters/trac/wiki.py
@@ -68,7 +68,7 @@ class TracWikiImportController(BaseController):
@require_post()
@validate(TracWikiImportSchema(), error_handler=index)
def create(self, trac_url, mount_point, mount_label, **kw):
- app = TracWikiImporter.import_tool(c.project,
+ app = TracWikiImporter().import_tool(c.project,
mount_point=mount_point,
mount_label=mount_label,
trac_url=trac_url,