allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [1/4] git commit: [#6804] ticket:468 code refactoing and added tests
Date Fri, 01 Nov 2013 20:10:58 GMT
Updated Branches:
  refs/heads/master 2ccaae5a5 -> 573d35eec


[#6804] ticket:468 code refactoing 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/6278af08
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/6278af08
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/6278af08

Branch: refs/heads/master
Commit: 6278af081b5232dd4d7d381ae1efb2c90693d482
Parents: cd98a7c
Author: coldmind <sokandpal@yandex.ru>
Authored: Thu Oct 31 16:49:26 2013 +0200
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Fri Nov 1 19:54:33 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/rest.py           | 32 +++++++++++++-
 Allura/allura/ext/admin/admin_main.py       | 16 +++----
 Allura/allura/tests/functional/test_rest.py | 53 ++++++++++++++++++++----
 3 files changed, 82 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6278af08/Allura/allura/controllers/rest.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/rest.py b/Allura/allura/controllers/rest.py
index bd098b4..20f6634 100644
--- a/Allura/allura/controllers/rest.py
+++ b/Allura/allura/controllers/rest.py
@@ -35,6 +35,8 @@ 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,7 +300,33 @@ class ProjectRestController(object):
         return c.project.__json__()
 
     @expose('json:')
-    def install_tool(self, tool, mount_point, mount_label, **kw):
+    @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:
@@ -324,7 +352,7 @@ class ProjectRestController(object):
             'mount_point': mount_point,
             'mount_label': mount_label
         }
-        controller.update_mounts(new=data, called_by_api=True)
+        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)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6278af08/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 86fb96e..a19242b 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -575,10 +575,7 @@ class ProjectAdminController(BaseController):
                 c.project.app_config(p['mount_point']).options.ordinal = int(p['ordinal'])
         redirect('tools')
 
-    @h.vardec
-    @expose()
-    @require_post()
-    def update_mounts(self, subproject=None, tool=None, new=None, called_by_api=False, **kw):
+    def _update_mounts(self, subproject=None, tool=None, new=None, **kw):
         if subproject is None: subproject = []
         if tool is None: tool = []
         for sp in subproject:
@@ -634,10 +631,13 @@ class ProjectAdminController(BaseController):
             flash('%s: %s' % (exc.__class__.__name__, exc.args[0]),
                   'error')
         g.post_event('project_updated')
-        if not called_by_api:
-            redirect('tools')
-        else:
-            return True
+
+    @h.vardec
+    @expose()
+    @require_post()
+    def update_mounts(self, subproject=None, tool=None, new=None, **kw):
+        self._update_mounts(subproject, tool, new, **kw)
+        redirect('tools')
 
     @expose('jinja:allura.ext.admin:templates/export.html')
     def export(self, tools=None):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6278af08/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 d663261..3137fe9 100644
--- a/Allura/allura/tests/functional/test_rest.py
+++ b/Allura/allura/tests/functional/test_rest.py
@@ -225,28 +225,63 @@ class TestRestHome(TestRestApiBase):
         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')
+        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
-        r = self.api_post('/rest/p/test/install_tool/tickets/tickets_mount1/tickets_label1')
+        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
-        r = self.api_post('/rest/p/test/install_tool/tickets/ticketsmount1/tickets_label1')
+        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'))
+                     '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')
+        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
-        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
+        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