allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [2/4] git commit: [#6804] ticket:468 fixed API and added tests
Date Fri, 01 Nov 2013 20:10:59 GMT
[#6804] ticket:468 fixed API and added tests


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

Branch: refs/heads/master
Commit: cd98a7c0387495bc1f2ef67e543f711b66b0886a
Parents: 343065a
Author: coldmind <sokandpal@yandex.ru>
Authored: Wed Oct 30 14:22:15 2013 +0200
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Fri Nov 1 19:54:33 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/rest.py           |  7 +++--
 Allura/allura/tests/functional/test_rest.py | 33 ++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/cd98a7c0/Allura/allura/controllers/rest.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/rest.py b/Allura/allura/controllers/rest.py
index 0472e79..bd098b4 100644
--- a/Allura/allura/controllers/rest.py
+++ b/Allura/allura/controllers/rest.py
@@ -34,10 +34,12 @@ 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
 
 log = logging.getLogger(__name__)
 action_logger = h.log_action(log, 'API:')
 
+
 class RestController(object):
 
     def __init__(self):
@@ -297,8 +299,6 @@ class ProjectRestController(object):
 
     @expose('json:')
     def install_tool(self, tool, mount_point, mount_label, **kw):
-        from allura.ext.admin.admin_main import ProjectAdminController
-        from allura.ext.admin.admin_main import AdminApp
         controller = ProjectAdminController()
 
         if not tool or not mount_point or not mount_label:
@@ -312,7 +312,7 @@ class ProjectRestController(object):
             return {'success': False,
                     'info': 'Incorrect tool name.'
                     }
-        if not h.re_tool_mount_point.match(tool) or c.project.app_instance(mount_point) is
not None:
+        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.'
                     }
@@ -320,7 +320,6 @@ class ProjectRestController(object):
         data = {
             'install': 'install',
             'ep_name': tool,
-            # TODO:
             'ordinal': '1',
             'mount_point': mount_point,
             'mount_label': mount_label

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/cd98a7c0/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 52745fc..d663261 100644
--- a/Allura/allura/tests/functional/test_rest.py
+++ b/Allura/allura/tests/functional/test_rest.py
@@ -30,6 +30,8 @@ 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):
 
@@ -217,3 +219,34 @@ 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
+
+        r = self.api_post('/rest/p/test/install_tool/something/ticketsmount1/tickets_label1')
+        assert_equal(r.json['info'], 'Incorrect tool name.')
+
+        # check incorrect mount_point name
+        r = self.api_post('/rest/p/test/install_tool/tickets/tickets_mount1/tickets_label1')
+        assert_equal(r.json['info'], 'Incorrect mount point name, or mount point already
exists.')
+
+        # check that tool was installed
+        r = self.api_post('/rest/p/test/install_tool/tickets/ticketsmount1/tickets_label1')
+        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/tickets/ticketsmount1/tickets_label1')
+        assert_equal(r.json['info'], 'Incorrect mount point name, or mount point already
exists.')
+
+        # test that unauthorized can't install tool
+        try:
+            self.app.post('/rest/p/test/install_tool/wiki/wikimount1/wikilabel1', extra_environ={'username':
'*anonymous'})
+        except AppError, e:
+            assert '401 Unauthorized' in e.message
+


Mime
View raw message