You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/08/28 16:34:48 UTC
[07/50] git commit: [#3154] ticket:409 fixed bulk export for nbhd and
user projects
[#3154] ticket:409 fixed bulk export for nbhd and user projects
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/526063a5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/526063a5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/526063a5
Branch: refs/heads/tv/6526
Commit: 526063a5c67058d8baba83a8e0975cb1ba99984b
Parents: cf72c2e
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Tue Aug 13 18:15:28 2013 +0400
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Aug 22 20:04:44 2013 +0000
----------------------------------------------------------------------
Allura/allura/ext/admin/admin_main.py | 2 +-
Allura/allura/model/project.py | 18 ++++++++++++++++--
Allura/allura/tasks/export_tasks.py | 5 +++--
Allura/allura/tests/functional/test_admin.py | 23 +++++++++++++++++++++--
Allura/allura/tests/test_tasks.py | 10 +++++-----
5 files changed, 46 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/526063a5/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 0dbc5a5..d1f98da 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -649,7 +649,7 @@ class ProjectAdminController(BaseController):
if c.project.bulk_export_status() == 'busy':
flash('Export for project %s already running' % c.project.shortname, 'info')
redirect('export')
- export_tasks.bulk_export.post(c.project.shortname, tools, c.user.username)
+ export_tasks.bulk_export.post(c.project.shortname, tools, c.user.username, c.project.neighborhood.name)
flash('Export scheduled', 'ok')
redirect('export')
return {
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/526063a5/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 1b21d37..18bd934 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -846,12 +846,26 @@ class Project(MappedClass, ActivityNode, ActivityObject):
))
def bulk_export_path(self):
+ shortname = self.shortname
+ if self.is_nbhd_project:
+ shortname = self.url().strip('/')
+ elif self.is_user_project:
+ shortname = self.shortname.split('/')[1]
+ elif not self.is_root:
+ shortname = self.shortname.split('/')[0]
return config['bulk_export_path'].format(
nbhd=self.neighborhood.url_prefix.strip('/'),
- project=self.shortname)
+ project=shortname)
def bulk_export_filename(self):
- return '%s.zip' % self.shortname
+ shortname = self.shortname
+ if self.is_nbhd_project:
+ shortname = self.url().strip('/')
+ elif self.is_user_project:
+ shortname = self.shortname.split('/')[1]
+ elif not self.is_root:
+ shortname = self.shortname.split('/')[1]
+ return '%s.zip' % shortname
def bulk_export_status(self):
fn = os.path.join(self.bulk_export_path(), self.bulk_export_filename())
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/526063a5/Allura/allura/tasks/export_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/export_tasks.py b/Allura/allura/tasks/export_tasks.py
index 9933e26..0eb99e0 100644
--- a/Allura/allura/tasks/export_tasks.py
+++ b/Allura/allura/tasks/export_tasks.py
@@ -34,8 +34,9 @@ log = logging.getLogger(__name__)
@task
-def bulk_export(project_shortname, tools, username):
- project = M.Project.query.get(shortname=project_shortname)
+def bulk_export(project_shortname, tools, username, neighborhood):
+ neighborhood = M.Neighborhood.query.get(name=neighborhood)
+ project = M.Project.query.get(shortname=project_shortname, neighborhood_id=neighborhood._id)
if not project:
log.error('Project %s not found' % project_shortname)
return
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/526063a5/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 4fd0d19..9ee232f 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -825,14 +825,14 @@ class TestExport(TestController):
r = self.app.post('/admin/export', {'tools': u'wiki'})
assert_in('ok', self.webflash(r))
export_tasks.bulk_export.post.assert_called_once_with(
- 'test', [u'wiki'], u'test-admin')
+ 'test', [u'wiki'], u'test-admin', u'Projects')
@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(
- 'test', [u'wiki', u'wiki2'], u'test-admin')
+ 'test', [u'wiki', u'wiki2'], u'test-admin', u'Projects')
@patch('allura.ext.admin.admin_main.export_tasks')
def test_export_in_progress(self, export_tasks):
@@ -855,3 +855,22 @@ class TestExport(TestController):
r = self.app.get('/admin/export')
assert_in('<h2>Careful!</h2>', r)
shutil.rmtree(p.bulk_export_path(), ignore_errors=True)
+
+ @td.with_user_project('test-user')
+ def test_bulk_export_path_for_user_project(self):
+ project = M.Project.query.get(shortname='u/test-user')
+ assert_equals(project.bulk_export_path(), '/tmp/bulk_export/u/test-user')
+
+ @td.with_user_project('test-user')
+ def test_bulk_export_filename_for_user_project(self):
+ project = M.Project.query.get(shortname='u/test-user')
+ assert_equals(project.bulk_export_filename(), 'test-user.zip')
+
+ def test_bulk_export_filename_for_nbhd(self):
+ project = M.Project.query.get(name='Home Project for Projects')
+ assert_equals(project.bulk_export_filename(), 'p.zip')
+
+ def test_bulk_export_path_for_nbhd(self):
+ project = M.Project.query.get(name='Home Project for Projects')
+ assert_equals(project.bulk_export_path(), '/tmp/bulk_export/p/p')
+
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/526063a5/Allura/allura/tests/test_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_tasks.py b/Allura/allura/tests/test_tasks.py
index c772253..a1e09c3 100644
--- a/Allura/allura/tests/test_tasks.py
+++ b/Allura/allura/tests/test_tasks.py
@@ -342,12 +342,12 @@ class TestExportTasks(unittest.TestCase):
@mock.patch('allura.tasks.export_tasks.log')
def test_bulk_export_invalid_project(self, log):
- export_tasks.bulk_export('bad', [u'wiki'], 'test-admin')
+ export_tasks.bulk_export('bad', [u'wiki'], 'test-admin', 'Projects')
log.error.assert_called_once_with('Project bad not found')
@mock.patch('allura.tasks.export_tasks.log')
def test_bulk_export_invalid_tool(self, log):
- export_tasks.bulk_export('test', [u'bugs', u'blog'], 'test-admin')
+ export_tasks.bulk_export('test', [u'bugs', u'blog'], 'test-admin', 'Projects')
assert_equal(log.info.call_count, 2)
assert_equal(log.info.call_args_list, [
mock.call('Can not load app for bugs mount point. Skipping.'),
@@ -360,7 +360,7 @@ class TestExportTasks(unittest.TestCase):
@td.with_tool('test', 'Blog', 'blog')
def test_bulk_export_not_exportable_tool(self, mail_tasks, app, log):
app.return_value.exportable = False
- export_tasks.bulk_export('test', [u'bugs', u'blog'], 'test-admin')
+ export_tasks.bulk_export('test', [u'bugs', u'blog'], 'test-admin', 'Projects')
assert_equal(log.info.call_count, 2)
assert_equal(log.info.call_args_list, [
mock.call('Tool bugs is not exportable. Skipping.'),
@@ -374,7 +374,7 @@ class TestExportTasks(unittest.TestCase):
@td.with_wiki
def test_bulk_export(self, log, wiki_bulk_export, zipdir, shutil, project_json):
M.MonQTask.query.remove()
- export_tasks.bulk_export('test', [u'wiki'], 'test-admin')
+ export_tasks.bulk_export('test', [u'wiki'], 'test-admin', 'Projects')
assert_equal(log.info.call_count, 1)
assert_equal(log.info.call_args_list, [
mock.call('Exporting wiki...')])
@@ -403,7 +403,7 @@ class TestExportTasks(unittest.TestCase):
project = M.Project.query.get(shortname='test')
export_tasks.create_export_dir(project)
assert_equal(project.bulk_export_status(), 'busy')
- export_tasks.bulk_export('test', [u'wiki'], 'test-admin')
+ export_tasks.bulk_export('test', [u'wiki'], 'test-admin', 'Projects')
log.info.assert_called_once_with('Another export is running for project test. Skipping.')
assert_equal(wiki_bulk_export.call_count, 0)