incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [01/50] git commit: [#6624] ticket:451 Rate limit improvements for GH importers
Date Tue, 22 Oct 2013 15:00:28 GMT
Updated Branches:
  refs/heads/cj/6692 68f5f38df -> f3f12795c (forced update)


[#6624] ticket:451 Rate limit improvements for GH importers


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

Branch: refs/heads/cj/6692
Commit: a9d892a40e9457899d2f00f002f72003b31606a3
Parents: af4521c
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Wed Oct 9 10:58:11 2013 +0300
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Mon Oct 14 15:06:04 2013 +0000

----------------------------------------------------------------------
 .../forgeimporters/github/tests/test_tracker.py  | 17 +++++++++++++++++
 .../forgeimporters/github/tests/test_wiki.py     | 17 +++++++++++++++++
 ForgeImporters/forgeimporters/github/tracker.py  | 17 ++++++++++-------
 ForgeImporters/forgeimporters/github/wiki.py     | 19 +++++++++++--------
 4 files changed, 55 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a9d892a4/ForgeImporters/forgeimporters/github/tests/test_tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tests/test_tracker.py b/ForgeImporters/forgeimporters/github/tests/test_tracker.py
index 1cc0297..938a194 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_tracker.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_tracker.py
@@ -17,9 +17,11 @@
 
 from unittest import TestCase
 from mock import patch
+from ming.odm import ThreadLocalORMSession
 
 from allura.tests import TestController
 from allura.tests.decorators import with_tool
+from allura import model as M
 
 # important to be distinct from 'test' which ForgeTracker uses, so that the tests can run
in parallel and not clobber each other
 test_project_with_tracker = 'test2'
@@ -52,3 +54,18 @@ class TestGitHubTrackerImportController(TestController, TestCase):
         self.assertEqual(u'issues', import_tool.post.call_args[1]['mount_point'])
         self.assertEqual(u'mulder', import_tool.post.call_args[1]['project_name'])
         self.assertEqual(u'spooky', import_tool.post.call_args[1]['user_name'])
+
+    @with_tracker
+    @patch('forgeimporters.base.import_tool')
+    def test_create_limit(self, import_tool):
+        p = M.Project.query.get(shortname=test_project_with_tracker)
+        p.set_tool_data('GitHubTrackerImporter', pending=1)
+        ThreadLocalORMSession.flush_all()
+        params = dict(
+            gh_user_name='spooky',
+            gh_project_name='mulder',
+            mount_point='issues',
+            mount_label='Issues')
+        r = self.app.post(self.url + 'create', params, status=302).follow()
+        self.assertIn('Please wait and try again', r)
+        self.assertEqual(import_tool.post.call_count, 0)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a9d892a4/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 d8465d5..0cced81 100644
--- a/ForgeImporters/forgeimporters/github/tests/test_wiki.py
+++ b/ForgeImporters/forgeimporters/github/tests/test_wiki.py
@@ -20,8 +20,10 @@
 from unittest import TestCase
 from nose.tools import assert_equal
 from mock import Mock, patch, call
+from ming.odm import ThreadLocalORMSession
 
 from IPython.testing.decorators import module_not_available, skipif
+from allura import model as M
 from allura.tests import TestController
 from allura.tests.decorators import with_tool, without_module
 from alluratest.controller import setup_basic_test
@@ -454,3 +456,18 @@ class TestGitHubWikiImportController(TestController, TestCase):
         self.assertEqual(u'mulder', args['project_name'])
         self.assertEqual(u'spooky', args['user_name'])
         self.assertEqual(u'', args['tool_option'])
+
+    @with_wiki
+    @patch('forgeimporters.base.import_tool')
+    def test_create_limit(self, import_tool):
+        p = M.Project.query.get(shortname=test_project_with_wiki)
+        p.set_tool_data('GitHubWikiImporter', pending=1)
+        ThreadLocalORMSession.flush_all()
+        params = dict(
+            gh_user_name='spooky',
+            gh_project_name='mulder',
+            mount_point='gh-wiki',
+            mount_label='GitHub Wiki')
+        r = self.app.post(self.url + 'create', params, status=302).follow()
+        self.assertIn('Please wait and try again', r)
+        self.assertEqual(import_tool.post.call_count, 0)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a9d892a4/ForgeImporters/forgeimporters/github/tracker.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/tracker.py b/ForgeImporters/forgeimporters/github/tracker.py
index c4153c4..ebed4ed 100644
--- a/ForgeImporters/forgeimporters/github/tracker.py
+++ b/ForgeImporters/forgeimporters/github/tracker.py
@@ -76,13 +76,16 @@ class GitHubTrackerImportController(BaseController):
     @require_post()
     @validate(GitHubTrackerImportForm(ForgeTrackerApp), error_handler=index)
     def create(self, gh_project_name, gh_user_name, mount_point, mount_label, **kw):
-        self.importer.post(
-                project_name=gh_project_name,
-                user_name=gh_user_name,
-                mount_point=mount_point,
-                mount_label=mount_label)
-        flash('Ticket import has begun. Your new tracker will be available '
-                'when the import is complete.')
+        if self.importer.enforce_limit(c.project):
+            self.importer.post(
+                    project_name=gh_project_name,
+                    user_name=gh_user_name,
+                    mount_point=mount_point,
+                    mount_label=mount_label)
+            flash('Ticket import has begun. Your new tracker will be available '
+                    'when the import is complete.')
+        else:
+            flash('There are too many imports pending at this time.  Please wait and try
again.', 'error')
         redirect(c.project.url() + 'admin/')
 
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a9d892a4/ForgeImporters/forgeimporters/github/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/github/wiki.py b/ForgeImporters/forgeimporters/github/wiki.py
index d95e6f0..8caa2b2 100644
--- a/ForgeImporters/forgeimporters/github/wiki.py
+++ b/ForgeImporters/forgeimporters/github/wiki.py
@@ -92,14 +92,17 @@ class GitHubWikiImportController(BaseController):
     @require_post()
     @validate(GitHubWikiImportForm(ForgeWikiApp), error_handler=index)
     def create(self, gh_project_name, gh_user_name, mount_point, mount_label, **kw):
-        self.importer.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.')
+        if self.importer.enforce_limit(c.project):
+            self.importer.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.')
+        else:
+            flash('There are too many imports pending at this time.  Please wait and try
again.', 'error')
         redirect(c.project.url() + 'admin/')
 
 


Mime
View raw message