allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [38/50] [abbrv] allura git commit: [#7919] Add tests for new endpoints
Date Fri, 08 Jan 2016 19:30:43 GMT
[#7919] Add tests for new endpoints


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

Branch: refs/heads/master
Commit: 873bb09024f15d3e086c27d95c8306a51c97785c
Parents: 35af1bb
Author: Heith Seewald <heiths@gmail.com>
Authored: Thu Dec 17 16:06:40 2015 -0600
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Fri Jan 8 14:06:18 2016 -0500

----------------------------------------------------------------------
 Allura/allura/ext/admin/admin_main.py        | 44 +++++++-----
 Allura/allura/tests/functional/test_admin.py | 84 ++++++++++++++++++++++-
 2 files changed, 109 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/873bb090/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 9c90b58..68863ab 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -774,16 +774,22 @@ class ProjectAdminRestController(BaseController):
     @expose('json:')
     @require_post()
     def mount_order(self, **kw):
-        if kw:
-            for ordinal, mount_point in sorted(kw.items(), key=lambda x: int(x[0])):
-                try:
-                    c.project.app_config(mount_point).options.ordinal = int(ordinal)
-                except AttributeError as e:
-                    # Handle subproject
-                    p = M.Project.query.get(shortname="{}/{}".format(c.project.shortname,
mount_point),
-                                            neighborhood_id=c.project.neighborhood_id)
-                    if p:
-                        p.ordinal = int(ordinal)
+        if not kw:
+            raise exc.HTTPBadRequest('Expected kw params in the form of "ordinal: mount_point"')
+        try:
+            sorted_tools = sorted(kw.items(), key=lambda x: int(x[0]))
+        except ValueError:
+            raise exc.HTTPBadRequest('Invalid kw: expected "ordinal: mount_point"')
+
+        for ordinal, mount_point in sorted_tools:
+            try:
+                c.project.app_config(mount_point).options.ordinal = int(ordinal)
+            except AttributeError as e:
+                # Handle sub project
+                p = M.Project.query.get(shortname="{}/{}".format(c.project.shortname, mount_point),
+                                        neighborhood_id=c.project.neighborhood_id)
+                if p:
+                    p.ordinal = int(ordinal)
         M.AuditLog.log('Updated tool order')
         return {'status': 'ok'}
 
@@ -792,15 +798,13 @@ class ProjectAdminRestController(BaseController):
     def configure_tool_grouping(self, grouping_threshold='1', **kw):
         try:
             grouping_threshold = int(grouping_threshold)
-            if grouping_threshold < 1:
-                raise ValueError('Invalid threshold')
+            if grouping_threshold < 1 or grouping_threshold > 10:
+                raise exc.HTTPBadRequest('Invalid threshold. Expected a value between 1 and
10')
             c.project.set_tool_data(
                 'allura', grouping_threshold=grouping_threshold)
         except ValueError:
-            return {
-                'status': 'error',
-                'msg': 'Invalid threshold'
-            }
+            raise exc.HTTPBadRequest('Invalid threshold. Expected a value between 1 and 10')
+
         M.AuditLog.log('Updated tool grouping threshold')
         return {'status': 'ok'}
 
@@ -882,9 +886,13 @@ class ProjectAdminRestController(BaseController):
         """
         Returns the admin options for a given mount_point
         """
+
+        if not mount_point:
+            raise exc.HTTPBadRequest('Must provide a mount point')
+
         tool = c.project.app_instance(mount_point)
-        if not mount_point or tool is None:
-            raise exc.HTTPNotFound
+        if tool is None:
+            raise exc.HTTPBadRequest('The mount point you provided was invalid')
         admin_menu = tool.admin_menu()
         if tool.admin_menu_delete_button:
             admin_menu.append(tool.admin_menu_delete_button)

http://git-wip-us.apache.org/repos/asf/allura/blob/873bb090/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 c602243..1592f0b 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -25,7 +25,7 @@ import logging
 
 import tg
 import PIL
-from nose.tools import assert_equals, assert_in, assert_not_in
+from nose.tools import assert_equals, assert_in, assert_not_in, assert_is_not_none
 from ming.orm.ormsession import ThreadLocalORMSession
 from tg import expose
 from pylons import tmpl_context as c, app_globals as g
@@ -1380,3 +1380,85 @@ class TestRestInstallTool(TestRestApiBase):
 
         assert_equals(
             get_labels(), ['t1', 'Admin', 'Search', 'Activity', 'A Subproject', 'ta', 'tb',
'tc'])
+
+
+class TestRestAdminOptions(TestRestApiBase):
+    def test_no_mount_point(self):
+        r = self.api_get('/rest/p/test/admin/admin_options/')
+        assert_equals(r.status, '400 Bad Request')
+        assert_in('Must provide a mount point', r.body)
+
+    def test_invalid_mount_point(self):
+        r = self.api_get('/rest/p/test/admin/admin_options/?mount_point=asdf')
+        assert_equals(r.status, '400 Bad Request')
+        assert_in('The mount point you provided was invalid', r.body)
+
+    @td.with_tool('test', 'Git', 'git')
+    def test_valid_mount_point(self):
+        r = self.api_get('/rest/p/test/admin/admin_options/?mount_point=git')
+        assert_equals(r.status, '200 OK')
+        assert_is_not_none(r.json['options'])
+
+
+class TestRestMountOrder(TestRestApiBase):
+    def test_no_kw(self):
+        r = self.api_post('/rest/p/test/admin/mount_order/')
+        assert_equals(r.status, '400 Bad Request')
+        assert_in('Expected kw params in the form of "ordinal: mount_point"', r.body)
+
+    def test_invalid_kw(self):
+        data = {'1': 'git', 'two': 'admin'}
+        r = self.api_post('/rest/p/test/admin/mount_order/', **data)
+        assert_equals(r.status, '400 Bad Request')
+        assert_in('Invalid kw: expected "ordinal: mount_point"', r.body)
+
+    def test_reorder(self):
+        data = {
+            '0': u'sub1',
+            '1': u'activity',
+            '2': u'admin'
+        }
+
+        before_reorder = self.api_get('/p/test/_nav.json')
+        assert_equals(before_reorder.json['menu'][1]['mount_point'], 'sub1')
+
+        r = self.api_post('/rest/p/test/admin/mount_order/', **data)
+        assert_equals(r.json['status'], 'ok')
+
+        after_reorder = self.api_get('/p/test/_nav.json')
+        assert_equals(after_reorder.json['menu'][1]['mount_point'], 'activity')
+
+
+class TestRestToolGrouping(TestRestApiBase):
+    def test_invalid_grouping_threshold(self):
+        for invalid_value in ('100', 'asdf'):
+            r = self.api_post('/rest/p/test/admin/configure_tool_grouping/', grouping_threshold=invalid_value)
+            assert_equals(r.status, '400 Bad Request')
+            assert_in('Invalid threshold. Expected a value between 1 and 10', r.body)
+
+    @td.with_wiki
+    @td.with_tool('test', 'Wiki', 'wiki2')
+    @td.with_tool('test', 'Wiki', 'wiki3')
+    def test_valid_grouping_threshold(self):
+        # Set threshold to 2
+        r = self.api_post('/rest/p/test/admin/configure_tool_grouping/', grouping_threshold='2')
+        assert_equals(r.status, '200 OK')
+
+        # The 'wiki' mount_point should not exist at the top level
+        result1 = self.app.get('/p/test/_nav.json')
+        assert_not_in('wiki', [tool['mount_point'] for tool in result1.json['menu']])
+
+        # Set threshold to 3
+        r = self.api_post('/rest/p/test/admin/configure_tool_grouping/', grouping_threshold='3')
+        assert_equals(r.status, '200 OK')
+
+        # The wiki mount_point should now be at the top level of the menu
+        result2 = self.app.get('/p/test/_nav.json')
+        assert_in('wiki', [tool['mount_point'] for tool in result2.json['menu']])
+
+
+class TestInstallableTools(TestRestApiBase):
+    def test_installable_tools_response(self):
+        r = self.api_get('/rest/p/test/admin/installable_tools')
+        assert_equals(r.status, '200 OK')
+        assert_in('External Link', [tool['tool_label'] for tool in r.json['tools']])


Mime
View raw message