incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [11/15] git commit: [#6456] Changed target_app to allow list and added by_app to ToolImporter
Date Mon, 22 Jul 2013 22:54:18 GMT
[#6456] Changed target_app to allow list and added by_app to ToolImporter

Signed-off-by: Cory Johns <cjohns@slashdotmedia.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/b12e82eb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/b12e82eb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/b12e82eb

Branch: refs/heads/cj/6456
Commit: b12e82ebf833b680b77a76eb29f8dbdef9b0784d
Parents: f091124
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Mon Jul 22 21:43:49 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Mon Jul 22 21:43:49 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/base.py           | 14 +++++-
 .../forgeimporters/tests/test_base.py           | 48 ++++++++++++++++----
 2 files changed, 50 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b12e82eb/ForgeImporters/forgeimporters/base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/base.py b/ForgeImporters/forgeimporters/base.py
index 01e614a..6632f37 100644
--- a/ForgeImporters/forgeimporters/base.py
+++ b/ForgeImporters/forgeimporters/base.py
@@ -18,6 +18,7 @@
 from pkg_resources import iter_entry_points
 
 from tg import expose
+from paste.deploy.converters import aslist
 from formencode import validators as fev
 
 from ming.utils import LazyProperty
@@ -77,6 +78,15 @@ class ToolImporter(object):
         for ep in iter_entry_points('allura.importers', name):
             return ep.load()()
 
+    @classmethod
+    def by_app(self, app):
+        importers = {}
+        for ep in iter_entry_points('allura.importers'):
+            importer = ep.load()
+            if app in aslist(importer.target_app):
+                importers[ep.name] = importer()
+        return importers
+
     def import_tool(self, project=None, mount_point=None):
         """
         Override this method to perform the tool import.
@@ -85,11 +95,11 @@ class ToolImporter(object):
 
     @property
     def tool_label(self):
-        return getattr(self.target_app, 'tool_label', None)
+        return getattr(aslist(self.target_app)[0], 'tool_label', None)
 
     @property
     def tool_description(self):
-        return getattr(self.target_app, 'tool_description', None)
+        return getattr(aslist(self.target_app)[0], 'tool_description', None)
 
 
 class ToolsValidator(fev.Set):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/b12e82eb/ForgeImporters/forgeimporters/tests/test_base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/test_base.py b/ForgeImporters/forgeimporters/tests/test_base.py
index a6a4d18..64096fd 100644
--- a/ForgeImporters/forgeimporters/tests/test_base.py
+++ b/ForgeImporters/forgeimporters/tests/test_base.py
@@ -23,17 +23,20 @@ import mock
 from .. import base
 
 
-def ep(name, source=None):
-    mep = mock.Mock(name='mock_ep')
+def ep(name, source=None, importer=None, **kw):
+    mep = mock.Mock(name='mock_ep', **kw)
     mep.name = name
-    mep.load.return_value.source = source
-    mep.lv = mep.load.return_value.return_value
-    mep.lv.source = source
+    if importer is not None:
+        mep.load.return_value = importer
+    else:
+        mep.load.return_value.source = source
+        mep.lv = mep.load.return_value.return_value
+        mep.lv.source = source
     return mep
 
 
 class TestProjectImporterDispatcher(TestCase):
-    @mock.patch('forgeimporters.base.iter_entry_points')
+    @mock.patch.object(base, 'iter_entry_points')
     def test_lookup(self, iep):
         eps = iep.return_value = [ep('ep1', 'first'), ep('ep2', 'second')]
         result = base.ProjectImporterDispatcher()._lookup('source', 'rest1', 'rest2')
@@ -42,7 +45,7 @@ class TestProjectImporterDispatcher(TestCase):
 
 
 class TestProjectImporter(TestCase):
-    @mock.patch('forgeimporters.base.iter_entry_points')
+    @mock.patch.object(base, 'iter_entry_points')
     def test_tool_importers(self, iep):
         eps = iep.return_value = [ep('ep1', 'foo'), ep('ep2', 'bar'), ep('ep3', 'foo')]
         pi = base.ProjectImporter()
@@ -51,16 +54,24 @@ class TestProjectImporter(TestCase):
         iep.assert_called_once_with('allura.importers')
 
 
+
+TA1 = mock.Mock(tool_label='foo', tool_description='foo_desc')
+TA2 = mock.Mock(tool_label='qux', tool_description='qux_desc')
+TA3 = mock.Mock(tool_label='baz', tool_description='baz_desc')
+
 class TestToolImporter(TestCase):
     class TI1(base.ToolImporter):
-        target_app = mock.Mock(tool_label='foo', tool_description='foo_desc')
+        target_app = TA1
 
     class TI2(base.ToolImporter):
-        target_app = mock.Mock(tool_label='foo', tool_description='foo_desc')
+        target_app = TA2
         tool_label = 'bar'
         tool_description = 'bar_desc'
 
-    @mock.patch('forgeimporters.base.iter_entry_points')
+    class TI3(base.ToolImporter):
+        target_app = [TA2, TA2]
+
+    @mock.patch.object(base, 'iter_entry_points')
     def test_by_name(self, iep):
         eps = iep.return_value = [ep('my-name', 'my-source')]
         importer = base.ToolImporter.by_name('my-name')
@@ -73,13 +84,30 @@ class TestToolImporter(TestCase):
         iep.assert_called_once_with('allura.importers', 'other-name')
         self.assertEqual(importer, None)
 
+    @mock.patch.object(base, 'iter_entry_points')
+    def test_by_app(self, iep):
+        eps = iep.return_value = [
+                ep('importer1', importer=self.TI1),
+                ep('importer2', importer=self.TI2),
+                ep('importer3', importer=self.TI3),
+            ]
+        importers = base.ToolImporter.by_app(TA2)
+        self.assertEqual(set(importers.keys()), set([
+                'importer2',
+                'importer3',
+            ]))
+        self.assertIsInstance(importers['importer2'], self.TI2)
+        self.assertIsInstance(importers['importer3'], self.TI3)
+
     def test_tool_label(self):
         self.assertEqual(self.TI1().tool_label, 'foo')
         self.assertEqual(self.TI2().tool_label, 'bar')
+        self.assertEqual(self.TI3().tool_label, 'qux')
 
     def test_tool_description(self):
         self.assertEqual(self.TI1().tool_description, 'foo_desc')
         self.assertEqual(self.TI2().tool_description, 'bar_desc')
+        self.assertEqual(self.TI3().tool_description, 'qux_desc')
 
 
 class TestToolsValidator(TestCase):


Mime
View raw message