incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [4/4] git commit: [#6804] Moved endpoint to new ProjectAdminRestController and split and improved tests
Date Fri, 01 Nov 2013 20:11:01 GMT
[#6804] Moved endpoint to new ProjectAdminRestController and split and improved tests

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

Branch: refs/heads/master
Commit: 573d35eecab2d2f558663a866b8293e1f65a313f
Parents: 6278af0
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Fri Nov 1 19:51:07 2013 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Fri Nov 1 19:54:34 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/rest.py            | 62 ---------------
 Allura/allura/ext/admin/admin_main.py        | 58 ++++++++++++++
 Allura/allura/tests/functional/test_admin.py | 97 +++++++++++++++++++++++
 Allura/allura/tests/functional/test_rest.py  | 67 ----------------
 4 files changed, 155 insertions(+), 129 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/573d35ee/Allura/allura/controllers/rest.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/rest.py b/Allura/allura/controllers/rest.py
index 20f6634..5c223f5 100644
--- a/Allura/allura/controllers/rest.py
+++ b/Allura/allura/controllers/rest.py
@@ -34,9 +34,6 @@ from allura.lib import helpers as h
 from allura.lib import security
 from allura.lib import plugin
 from allura.lib.exceptions import Invalid
-from allura.ext.admin.admin_main import ProjectAdminController, AdminApp
-from allura.lib.security import require_access
-from allura.lib.decorators import require_post
 
 log = logging.getLogger(__name__)
 action_logger = h.log_action(log, 'API:')
@@ -298,62 +295,3 @@ class ProjectRestController(object):
     @expose('json:')
     def index(self, **kw):
         return c.project.__json__()
-
-    @expose('json:')
-    @require_post()
-    def install_tool(self, tool=None, mount_point=None, mount_label=None, **kw):
-        """API for installing tools in current project.
-
-           Requires a valid tool, mount point and mount label names.
-           (All arguments are required.)
-
-           Usage example::
-                POST to:
-               /rest/p/testproject/install_tool/
-
-               with params:
-               {
-                    'tool': 'tickets',
-                    'mount_point': 'mountpoint',
-                    'mount_label': 'mountlabel'
-               }
-
-           Example output (in successful case)::
-
-                {
-                    "info": "Tool tickets with mount_point mountpoint and mount_label mountlabel
was created.",
-                    "success": true
-                }
-
-        """
-        require_access(c.project, 'admin')
-        controller = ProjectAdminController()
-
-        if not tool or not mount_point or not mount_label:
-            return {'success': False,
-                    'info': 'All arguments required.'
-                    }
-
-        installable_tools = AdminApp.installable_tools_for(c.project)
-        tools_names = [t['name'] for t in installable_tools]
-        if not tool in tools_names:
-            return {'success': False,
-                    'info': 'Incorrect tool name.'
-                    }
-        if not h.re_tool_mount_point.match(mount_point) or c.project.app_instance(mount_point)
is not None:
-            return {'success': False,
-                    'info': 'Incorrect mount point name, or mount point already exists.'
-                    }
-
-        data = {
-            'install': 'install',
-            'ep_name': tool,
-            'ordinal': '1',
-            'mount_point': mount_point,
-            'mount_label': mount_label
-        }
-        controller._update_mounts(new=data)
-        return {'success': True,
-                'info': 'Tool %s with mount_point %s and mount_label %s was created.'
-                        % (tool, mount_point, mount_label)
-        }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/573d35ee/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 a19242b..8d38bfe 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -722,6 +722,64 @@ class ProjectAdminRestController(BaseController):
         status = c.project.bulk_export_status()
         return {'status': status or 'ready'}
 
+    @expose('json:')
+    @require_post()
+    def install_tool(self, tool=None, mount_point=None, mount_label=None, **kw):
+        """API for installing tools in current project.
+
+           Requires a valid tool, mount point and mount label names.
+           (All arguments are required.)
+
+           Usage example::
+                POST to:
+               /rest/p/testproject/admin/install_tool/
+
+               with params:
+               {
+                    'tool': 'tickets',
+                    'mount_point': 'mountpoint',
+                    'mount_label': 'mountlabel'
+               }
+
+           Example output (in successful case)::
+
+                {
+                    "info": "Tool tickets with mount_point mountpoint and mount_label mountlabel
was created.",
+                    "success": true
+                }
+
+        """
+        controller = ProjectAdminController()
+
+        if not tool or not mount_point or not mount_label:
+            return {'success': False,
+                    'info': 'All arguments required.'
+                    }
+
+        installable_tools = AdminApp.installable_tools_for(c.project)
+        tools_names = [t['name'] for t in installable_tools]
+        if not tool in tools_names:
+            return {'success': False,
+                    'info': 'Incorrect tool name.'
+                    }
+        if not h.re_tool_mount_point.match(mount_point) or c.project.app_instance(mount_point)
is not None:
+            return {'success': False,
+                    'info': 'Incorrect mount point name, or mount point already exists.'
+                    }
+
+        data = {
+            'install': 'install',
+            'ep_name': tool,
+            'ordinal': len(installable_tools) + len(c.project.direct_subprojects),
+            'mount_point': mount_point,
+            'mount_label': mount_label
+        }
+        controller._update_mounts(new=data)
+        return {'success': True,
+                'info': 'Tool %s with mount_point %s and mount_label %s was created.'
+                        % (tool, mount_point, mount_label)
+        }
+
 
 class PermissionsController(BaseController):
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/573d35ee/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 49992fd..4f63723 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -30,6 +30,8 @@ from tg import expose
 from pylons import tmpl_context as c, app_globals as g
 import mock
 from BeautifulSoup import BeautifulSoup
+from webtest.app import AppError
+
 
 try:
     import sfx
@@ -1026,3 +1028,98 @@ class TestRestExport(TestRestApiBase):
                 'status': 'in progress',
             })
         bulk_export.post.assert_called_once_with(['tickets', 'discussion'], 'test.zip', send_email=False)
+
+
+class TestRestInstallTool(TestRestApiBase):
+    def test_missing_mount_info(self):
+        r = self.api_get('/rest/p/test/')
+        tools_names = [t['name'] for t in r.json['tools']]
+        assert 'tickets' not in tools_names
+
+        data = {
+            'tool': 'tickets'
+        }
+        r = self.api_post('/rest/p/test/admin/install_tool/', **data)
+        assert_equals(r.json['success'], False)
+        assert_equals(r.json['info'], 'All arguments required.')
+
+    def test_invalid_tool(self):
+        r = self.api_get('/rest/p/test/')
+        tools_names = [t['name'] for t in r.json['tools']]
+        assert 'tickets' not in tools_names
+
+        data = {
+            'tool': 'something',
+            'mount_point': 'ticketsmount1',
+            'mount_label': 'tickets_label1'
+        }
+        r = self.api_post('/rest/p/test/admin/install_tool/', **data)
+        assert_equals(r.json['success'], False)
+        assert_equals(r.json['info'], 'Incorrect tool name.')
+
+    def test_bad_mount(self):
+        r = self.api_get('/rest/p/test/')
+        tools_names = [t['name'] for t in r.json['tools']]
+        assert 'tickets' not in tools_names
+
+        data = {
+            'tool': 'tickets',
+            'mount_point': 'tickets_mount1',
+            'mount_label': 'tickets_label1'
+        }
+        r = self.api_post('/rest/p/test/admin/install_tool/', **data)
+        assert_equals(r.json['success'], False)
+        assert_equals(r.json['info'], 'Incorrect mount point name, or mount point already
exists.')
+
+    def test_install_tool_ok(self):
+        r = self.api_get('/rest/p/test/')
+        tools_names = [t['name'] for t in r.json['tools']]
+        assert 'tickets' not in tools_names
+
+        data = {
+            'tool': 'tickets',
+            'mount_point': 'ticketsmount1',
+            'mount_label': 'tickets_label1'
+        }
+        r = self.api_post('/rest/p/test/admin/install_tool/', **data)
+        assert_equals(r.json['success'], True)
+        assert_equals(r.json['info'],
+                     'Tool %s with mount_point %s and mount_label %s was created.'
+                     % ('tickets', 'ticketsmount1', 'tickets_label1'))
+
+        project = M.Project.query.get(shortname='test')
+        assert_equals(project.ordered_mounts()[-1]['ac'].options.mount_point, 'ticketsmount1')
+        audit_log = M.AuditLog.query.find({'project_id': project._id}).sort({'_id': -1}).first()
+        assert_equals(audit_log.message, 'install tool ticketsmount1')
+
+    def test_tool_exists(self):
+        r = self.api_get('/rest/p/test/')
+        tools_names = [t['name'] for t in r.json['tools']]
+        assert 'tickets' not in tools_names
+
+        data = {
+            'tool': 'tickets',
+            'mount_point': 'ticketsmount1',
+            'mount_label': 'tickets_label1'
+        }
+        c.project.install_app('tickets', mount_point=data['mount_point'])
+        r = self.api_post('/rest/p/test/admin/install_tool/', **data)
+        assert_equals(r.json['success'], False)
+        assert_equals(r.json['info'], 'Incorrect mount point name, or mount point already
exists.')
+
+    def test_unauthorized(self):
+        r = self.api_get('/rest/p/test/')
+        tools_names = [t['name'] for t in r.json['tools']]
+        assert 'tickets' not in tools_names
+
+        data = {
+            'tool': 'wiki',
+            'mount_point': 'wikimount1',
+            'mount_label': 'wiki_label1'
+        }
+        r = self.app.post('/rest/p/test/admin/install_tool/',
+                             extra_environ={'username': '*anonymous'},
+                             status=401,
+                             params=data)
+        assert_equals(r.status, '401 Unauthorized')
+

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/573d35ee/Allura/allura/tests/functional/test_rest.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_rest.py b/Allura/allura/tests/functional/test_rest.py
index 3137fe9..ea4b769 100644
--- a/Allura/allura/tests/functional/test_rest.py
+++ b/Allura/allura/tests/functional/test_rest.py
@@ -30,7 +30,6 @@ from alluratest.controller import TestRestApiBase
 from allura.lib import helpers as h
 from allura.lib.exceptions import Invalid
 from allura import model as M
-from webtest.app import AppError
 
 
 class TestRestHome(TestRestApiBase):
@@ -219,69 +218,3 @@ class TestRestHome(TestRestApiBase):
             Provider.get().shortname_validator.to_python.side_effect = Invalid('name', 'value',
{})
             r = self.api_get('/rest/p/test/')
             assert r.status_int == 404
-
-    def test_install_tool(self):
-        r = self.api_get('/rest/p/test/')
-        tools_names = [t['name'] for t in r.json['tools']]
-        assert 'tickets' not in tools_names
-
-        data = {
-            'tool': 'tickets'
-        }
-        r = self.api_post('/rest/p/test/install_tool/', **data)
-        assert_equal(r.json['success'], False)
-        assert_equal(r.json['info'], 'All arguments required.')
-
-        # check incorrect tool name
-        data = {
-            'tool': 'something',
-            'mount_point': 'ticketsmount1',
-            'mount_label': 'tickets_label1'
-        }
-        r = self.api_post('/rest/p/test/install_tool/', **data)
-        assert_equal(r.json['success'], False)
-        assert_equal(r.json['info'], 'Incorrect tool name.')
-
-        # check incorrect mount_point name
-        data = {
-            'tool': 'tickets',
-            'mount_point': 'tickets_mount1',
-            'mount_label': 'tickets_label1'
-        }
-        r = self.api_post('/rest/p/test/install_tool/', **data)
-        assert_equal(r.json['success'], False)
-        assert_equal(r.json['info'], 'Incorrect mount point name, or mount point already
exists.')
-
-        # check that tool was installed
-        data = {
-            'tool': 'tickets',
-            'mount_point': 'ticketsmount1',
-            'mount_label': 'tickets_label1'
-        }
-        r = self.api_post('/rest/p/test/install_tool/', **data)
-        assert_equal(r.json['success'], True)
-        assert_equal(r.json['info'],
-                     'Tool %s with mount_point %s and mount_label %s was created.'
-                     % ('tickets', 'ticketsmount1', 'tickets_label1'))
-
-        r = self.api_get('/rest/p/test/')
-        tools_names = [t['name'] for t in r.json['tools']]
-        assert 'tickets' in tools_names
-
-        # check that tool already exists
-        r = self.api_post('/rest/p/test/install_tool/', **data)
-        assert_equal(r.json['success'], False)
-        assert_equal(r.json['info'], 'Incorrect mount point name, or mount point already
exists.')
-
-        # test that unauthorized can't install tool
-        data = {
-            'tool': 'wiki',
-            'mount_point': 'wikimount1',
-            'mount_label': 'wiki_label1'
-        }
-        r = self.app.post('/rest/p/test/install_tool/',
-                             extra_environ={'username': '*anonymous'},
-                             status=401,
-                             params=data)
-        assert_equal(r.status, '401 Unauthorized')
-


Mime
View raw message