incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [14/14] git commit: [#6480] Refactor import_tool() params
Date Wed, 07 Aug 2013 13:37:07 GMT
[#6480] Refactor import_tool() params

- project and user are the only guaranteed params for every
  importer, and should therefore be the only positional args
- All other args to import_tool, even project_name (which refers
  to the name of the project being imported), should be passed
  by keyword.

Signed-off-by: Tim Van Steenburgh <tvansteenburgh@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/36cb8497
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/36cb8497
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/36cb8497

Branch: refs/heads/tv/6480
Commit: 36cb84975b4fa22a549d7e034292203b2296277f
Parents: 426a129
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Wed Aug 7 13:32:14 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Wed Aug 7 13:32:14 2013 +0000

----------------------------------------------------------------------
 ForgeImporters/forgeimporters/base.py                     | 10 +++++-----
 ForgeImporters/forgeimporters/google/code.py              |  6 +++---
 ForgeImporters/forgeimporters/google/tests/test_code.py   |  4 +++-
 ForgeImporters/forgeimporters/google/tracker.py           |  3 ++-
 .../forgeimporters/tests/google/test_tracker.py           |  5 +++--
 ForgeImporters/forgeimporters/tests/test_base.py          |  5 +++--
 ForgeImporters/forgeimporters/trac/tests/test_tickets.py  |  5 ++---
 ForgeImporters/forgeimporters/trac/tests/test_wiki.py     |  5 ++---
 ForgeImporters/forgeimporters/trac/tickets.py             |  9 ++++-----
 ForgeImporters/forgeimporters/trac/wiki.py                |  9 ++++-----
 10 files changed, 31 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/36cb8497/ForgeImporters/forgeimporters/base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/base.py b/ForgeImporters/forgeimporters/base.py
index 7ad720c..3aea8c0 100644
--- a/ForgeImporters/forgeimporters/base.py
+++ b/ForgeImporters/forgeimporters/base.py
@@ -50,11 +50,10 @@ class ProjectImportForm(schema.Schema):
 
 
 @task
-def import_tool(importer_name, project_name, mount_point=None, mount_label=None, **kw):
+def import_tool(importer_name, project_name=None, mount_point=None, mount_label=None, **kw):
     importer = ToolImporter.by_name(importer_name)
-    importer.import_tool(project=c.project, user=c.user,
-            mount_point=mount_point,
-            mount_label=mount_label, **kw)
+    importer.import_tool(c.project, c.user, project_name=project_name,
+            mount_point=mount_point, mount_label=mount_label, **kw)
 
 
 class ProjectImporter(BaseController):
@@ -209,7 +208,8 @@ class ToolImporter(object):
                 importers[ep.name] = importer()
         return importers
 
-    def import_tool(self, project, project_name, mount_point=None, mount_label=None):
+    def import_tool(self, project, user, project_name=None,
+            mount_point=None, mount_label=None, **kw):
         """
         Override this method to perform the tool import.
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/36cb8497/ForgeImporters/forgeimporters/google/code.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/code.py b/ForgeImporters/forgeimporters/google/code.py
index 4457b55..c88d42a 100644
--- a/ForgeImporters/forgeimporters/google/code.py
+++ b/ForgeImporters/forgeimporters/google/code.py
@@ -86,7 +86,7 @@ class GoogleRepoImportController(BaseController):
     @require_post()
     @validate(GoogleRepoImportSchema(), error_handler=index)
     def create(self, gc_project_name, mount_point, mount_label, **kw):
-        app = GoogleRepoImporter.import_tool(c.project,
+        app = GoogleRepoImporter().import_tool(c.project, c.user,
                 project_name=gc_project_name,
                 mount_point=mount_point,
                 mount_label=mount_label)
@@ -100,8 +100,8 @@ class GoogleRepoImporter(ToolImporter):
     tool_label = 'Google Code Source Importer'
     tool_description = 'Import your SVN, Git, or Hg repo from Google Code'
 
-    def import_tool(self, project, project_name, mount_point=None, mount_label=None):
-    def import_tool(self, project, project_name, mount_point=None, mount_label=None, **kw):
+    def import_tool(self, project, user, project_name=None, mount_point=None,
+            mount_label=None, **kw):
         """ Import a Google Code repo into a new SVN, Git, or Hg Allura tool.
 
         """

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/36cb8497/ForgeImporters/forgeimporters/google/tests/test_code.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/tests/test_code.py b/ForgeImporters/forgeimporters/google/tests/test_code.py
index fe6943b..13ec0c3 100644
--- a/ForgeImporters/forgeimporters/google/tests/test_code.py
+++ b/ForgeImporters/forgeimporters/google/tests/test_code.py
@@ -62,7 +62,8 @@ class TestGoogleRepoImporter(TestCase):
         gcpe.return_value.get_repo_type.return_value = 'git'
         get_repo_url.return_value = 'http://remote/clone/url/'
         p = self._make_project(gc_proj_name='myproject')
-        GoogleRepoImporter().import_tool(p, 'project_name')
+        GoogleRepoImporter().import_tool(p, Mock(name='c.user'),
+                project_name='project_name')
         get_repo_url.assert_called_once_with('project_name', 'git')
         p.install_app.assert_called_once_with('Git',
                 mount_point='code',
@@ -89,6 +90,7 @@ class TestGoogleRepoImportController(TestController, TestCase):
     @patch('forgeimporters.google.code.GoogleRepoImporter')
     def test_create(self, gri):
         from allura import model as M
+        gri = gri.return_value
         gri.import_tool.return_value = Mock()
         gri.import_tool.return_value.url.return_value = '/p/{}/mymount'.format(test_project_with_repo)
         params = dict(gc_project_name='poop',

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/36cb8497/ForgeImporters/forgeimporters/google/tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/google/tracker.py b/ForgeImporters/forgeimporters/google/tracker.py
index 4d37a16..95f53e4 100644
--- a/ForgeImporters/forgeimporters/google/tracker.py
+++ b/ForgeImporters/forgeimporters/google/tracker.py
@@ -42,7 +42,8 @@ class GoogleCodeTrackerImporter(ToolImporter):
             type='select',
         )
 
-    def import_tool(self, project, project_name, mount_point=None, mount_label=None):
+    def import_tool(self, project, user, project_name=None, mount_point=None,
+            mount_label=None, **kw):
         c.app = project.install_app('tracker', mount_point, mount_label)
         c.app.globals.open_status_names = ['New', 'Accepted', 'Started']
         c.app.globals.closed_status_names = ['Fixed', 'Verified', 'Invalid', 'Duplicate',
'WontFix', 'Done']

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/36cb8497/ForgeImporters/forgeimporters/tests/google/test_tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/google/test_tracker.py b/ForgeImporters/forgeimporters/tests/google/test_tracker.py
index d54ac90..e49f279 100644
--- a/ForgeImporters/forgeimporters/tests/google/test_tracker.py
+++ b/ForgeImporters/forgeimporters/tests/google/test_tracker.py
@@ -33,14 +33,15 @@ class TestTrackerImporter(TestCase):
         importer.process_labels = mock.Mock()
         importer.process_comments = mock.Mock()
         importer.postprocess_custom_fields = mock.Mock()
-        project = mock.Mock()
+        project, user = mock.Mock(), mock.Mock()
         app = project.install_app.return_value
         extractor = gdata.return_value
         issues = extractor.iter_issues.return_value = [mock.Mock(), mock.Mock()]
         tickets = TM.Ticket.new.side_effect = [mock.Mock(), mock.Mock()]
         comments = extractor.iter_comments.side_effect = [mock.Mock(), mock.Mock()]
 
-        importer.import_tool(project, 'project_name', 'mount_point', 'mount_label')
+        importer.import_tool(project, user, project_name='project_name',
+                mount_point='mount_point', mount_label='mount_label')
 
         project.install_app.assert_called_once_with('tracker', 'mount_point', 'mount_label')
         gdata.assert_called_once_with('project_name')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/36cb8497/ForgeImporters/forgeimporters/tests/test_base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/tests/test_base.py b/ForgeImporters/forgeimporters/tests/test_base.py
index 18b83ac..68be24d 100644
--- a/ForgeImporters/forgeimporters/tests/test_base.py
+++ b/ForgeImporters/forgeimporters/tests/test_base.py
@@ -28,10 +28,11 @@ from .. import base
 def test_import_tool(c, by_name):
     c.project = mock.Mock(name='project')
     c.user = mock.Mock(name='user')
-    base.import_tool('importer_name', 'project_name', 'mount_point', 'mount_label')
+    base.import_tool('importer_name', project_name='project_name',
+            mount_point='mount_point', mount_label='mount_label')
     by_name.assert_called_once_with('importer_name')
     by_name.return_value.import_tool.assert_called_once_with(c.project,
-            'project_name', user=c.user, mount_point='mount_point',
+            c.user, project_name='project_name', mount_point='mount_point',
             mount_label='mount_label')
 
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/36cb8497/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 2cce886..5f88eef 100644
--- a/ForgeImporters/forgeimporters/trac/tests/test_tickets.py
+++ b/ForgeImporters/forgeimporters/trac/tests/test_tickets.py
@@ -45,11 +45,10 @@ class TestTracTicketImporter(TestCase):
         project = Mock(name='Project', shortname='myproject')
         project.install_app.return_value = app
         user = Mock(name='User', _id='id')
-        res = importer.import_tool(project=project,
+        res = importer.import_tool(project, user,
                 mount_point='bugs',
                 mount_label='Bugs',
-                trac_url='http://example.com/trac/url',
-                user=user)
+                trac_url='http://example.com/trac/url')
         self.assertEqual(res, app)
         project.install_app.assert_called_once_with(
                 'Tickets', mount_point='bugs', mount_label='Bugs')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/36cb8497/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 71cc8b5..738e49b 100644
--- a/ForgeImporters/forgeimporters/trac/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/trac/tests/test_wiki.py
@@ -50,11 +50,10 @@ class TestWikiTicketImporter(TestCase):
         project = Mock(name='Project', shortname='myproject')
         project.install_app.return_value = app
         user = Mock(name='User', _id='id')
-        res = importer.import_tool(project=project,
+        res = importer.import_tool(project, user,
                 mount_point='pages',
                 mount_label='Pages',
-                trac_url='http://example.com/trac/url',
-                user=user)
+                trac_url='http://example.com/trac/url')
         self.assertEqual(res, app)
         project.install_app.assert_called_once_with(
                 'Wiki', mount_point='pages', mount_label='Pages')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/36cb8497/ForgeImporters/forgeimporters/trac/tickets.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/trac/tickets.py b/ForgeImporters/forgeimporters/trac/tickets.py
index 78d8d17..f7d50b4 100644
--- a/ForgeImporters/forgeimporters/trac/tickets.py
+++ b/ForgeImporters/forgeimporters/trac/tickets.py
@@ -69,11 +69,10 @@ 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, c.user,
                 mount_point=mount_point,
                 mount_label=mount_label,
-                trac_url=trac_url,
-                user=c.user)
+                trac_url=trac_url)
         redirect(app.url())
 
 
@@ -84,8 +83,8 @@ class TracTicketImporter(ToolImporter):
     tool_label = 'Trac Ticket Importer'
     tool_description = 'Import your tickets from Trac'
 
-    def import_tool(self, project=None, mount_point=None, mount_label=None,
-            trac_url=None, user=None, **kw):
+    def import_tool(self, project, user, project_name=None, mount_point=None,
+            mount_label=None, trac_url=None, **kw):
         """ Import Trac tickets into a new Allura Tracker tool.
 
         """

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/36cb8497/ForgeImporters/forgeimporters/trac/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/trac/wiki.py b/ForgeImporters/forgeimporters/trac/wiki.py
index 00f0d48..300b476 100644
--- a/ForgeImporters/forgeimporters/trac/wiki.py
+++ b/ForgeImporters/forgeimporters/trac/wiki.py
@@ -68,11 +68,10 @@ 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, c.user,
                 mount_point=mount_point,
                 mount_label=mount_label,
-                trac_url=trac_url,
-                user=c.user)
+                trac_url=trac_url)
         redirect(app.url())
 
 
@@ -83,8 +82,8 @@ class TracWikiImporter(ToolImporter):
     tool_label = 'Trac Wiki Importer'
     tool_description = 'Import your wiki from Trac'
 
-    def import_tool(self, project=None, mount_point=None, mount_label=None,
-            trac_url=None, user=None, **kw):
+    def import_tool(self, project, user, project_name=None, mount_point=None,
+            mount_label=None, trac_url=None, **kw):
         """ Import Trac wiki into a new Allura Wiki tool.
 
         """


Mime
View raw message