incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [50/50] git commit: [#6692] Refactored out duplication from export views
Date Tue, 22 Oct 2013 15:01:17 GMT
[#6692] Refactored out duplication from export views

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/f3f12795
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/f3f12795
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/f3f12795

Branch: refs/heads/cj/6692
Commit: f3f12795c7e90b966cf3478547a257b5c2254de4
Parents: c158729
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Mon Oct 7 19:36:53 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Tue Oct 22 15:00:02 2013 +0000

----------------------------------------------------------------------
 Allura/allura/ext/admin/admin_main.py        | 27 +++++++++--------------
 Allura/allura/tests/functional/test_admin.py |  7 +++---
 2 files changed, 14 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f3f12795/Allura/allura/ext/admin/admin_main.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/admin_main.py b/Allura/allura/ext/admin/admin_main.py
index aa13d51..c9ad7e2 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -639,25 +639,18 @@ class ProjectAdminController(BaseController):
     @expose('jinja:allura.ext.admin:templates/export.html')
     def export(self, tools=None):
         if not asbool(config.get('bulk_export_enabled', True)):
-            redirect('.')
-        exportable_tools = AdminApp.exportable_tools_for(c.project)
+            raise exc.HTTPNotFound()
         if request.method == 'POST':
-            if not tools:
-                flash('Select at least one tool to export', 'error')
-                redirect('export')
-            if isinstance(tools, basestring):
-                tools = [tools]
-            allowed = set(t.options.mount_point for t in exportable_tools)
-            if not set(tools).issubset(allowed):
-                flash('Wrong tools in input data', 'error')
-                redirect('export')
-            if c.project.bulk_export_status() == 'busy':
-                flash('Export for project %s already running' % c.project.shortname, 'info')
+            try:
+                ProjectAdminRestController().export(tools)
+            except (exc.HTTPBadRequest, exc.HTTPServiceUnavailable) as e:
+                flash(str(e), 'error')
+                redirect('.')
+            else:
+                flash('Export scheduled.  You will recieve an email with download instructions
when complete.', 'ok')
                 redirect('export')
-            export_tasks.bulk_export.post(tools)
-            flash('Export scheduled.  You will recieve an email with download instructions
when complete.', 'ok')
-            redirect('export')
 
+        exportable_tools = AdminApp.exportable_tools_for(c.project)
         return {
             'tools': exportable_tools,
             'status': c.project.bulk_export_status()
@@ -672,6 +665,8 @@ class ProjectAdminRestController(BaseController):
     @expose('json:')
     @require_post()
     def export(self, tools=None, **kw):
+        if not asbool(config.get('bulk_export_enabled', True)):
+            raise exc.HTTPNotFound()
         if not tools:
             raise exc.HTTPBadRequest('Must give at least one tool mount point to export')
         tools = aslist(tools,',')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f3f12795/Allura/allura/tests/functional/test_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_admin.py b/Allura/allura/tests/functional/test_admin.py
index 191d903..4af8d5b 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -899,8 +899,7 @@ class TestExport(TestController):
         tg.config['bulk_export_enabled'] = 'false'
         r = self.app.get('/admin/')
         assert_not_in('Export', r)
-        r = self.app.get('/admin/export').follow()
-        assert_equals(r.request.url, 'http://localhost/admin/')
+        r = self.app.get('/admin/export', status=404)
         tg.config['bulk_export_enabled'] = 'true'
         r = self.app.get('/admin/')
         assert_in('Export', r)
@@ -930,13 +929,13 @@ class TestExport(TestController):
     def test_selected_one_tool(self, export_tasks):
         r = self.app.post('/admin/export', {'tools': u'wiki'})
         assert_in('ok', self.webflash(r))
-        export_tasks.bulk_export.post.assert_called_once_with([u'wiki'])
+        export_tasks.bulk_export.post.assert_called_once_with([u'wiki'], 'test.zip')
 
     @mock.patch('allura.ext.admin.admin_main.export_tasks')
     def test_selected_multiple_tools(self, export_tasks):
         r = self.app.post('/admin/export', {'tools': [u'wiki', u'wiki2']})
         assert_in('ok', self.webflash(r))
-        export_tasks.bulk_export.post.assert_called_once_with([u'wiki', u'wiki2'])
+        export_tasks.bulk_export.post.assert_called_once_with([u'wiki', u'wiki2'], 'test.zip')
 
     def test_export_in_progress(self):
         from allura.tasks import export_tasks


Mime
View raw message