incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [4/5] git commit: [#7014] ticket:524 Added additional tests for TroveCategories
Date Mon, 24 Feb 2014 15:16:59 GMT
[#7014] ticket:524 Added additional tests for TroveCategories

Added functional tests for TroveCategoryController.
Added tests for created/updated/deleted events TroveCategory model.


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

Branch: refs/heads/master
Commit: 2fdefbffa8e1e500c800d50357d57f16c277ed0f
Parents: 6ca710e
Author: Ferens Dmitriy <ferensdima@gmail.com>
Authored: Fri Jan 31 23:32:36 2014 +0200
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Mon Feb 24 15:15:41 2014 +0000

----------------------------------------------------------------------
 .../allura/controllers/basetest_project_root.py |  2 +-
 Allura/allura/controllers/root.py               |  3 +-
 Allura/allura/controllers/trovecategories.py    | 15 ++---
 Allura/allura/templates/user_skills.html        |  2 +-
 .../tests/functional/test_trovecategory.py      | 62 ++++++++++++++++++++
 Allura/test.ini                                 |  2 +
 6 files changed, 75 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2fdefbff/Allura/allura/controllers/basetest_project_root.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/basetest_project_root.py b/Allura/allura/controllers/basetest_project_root.py
index 638d28d..d1ca3f7 100644
--- a/Allura/allura/controllers/basetest_project_root.py
+++ b/Allura/allura/controllers/basetest_project_root.py
@@ -68,7 +68,7 @@ class BasetestProjectRootController(WsgiDispatchController, ProjectController):
         proxy_root = RootController()
         self.dispatch = DispatchTest()
         self.security = SecurityTests()
-        for attr in ('index', 'browse', 'auth', 'nf', 'error'):
+        for attr in ('index', 'browse', 'auth', 'nf', 'error', 'categories'):
             setattr(self, attr, getattr(proxy_root, attr))
         self.gsearch = proxy_root.search
         self.rest = RestController()

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2fdefbff/Allura/allura/controllers/root.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/root.py b/Allura/allura/controllers/root.py
index 01420e8..f5848d8 100644
--- a/Allura/allura/controllers/root.py
+++ b/Allura/allura/controllers/root.py
@@ -70,8 +70,7 @@ class RootController(WsgiDispatchController):
     nf = NewForgeController()
     search = SearchController()
     rest = RestController()
-    if config.get('trovecategories.enableediting', 'false') != 'false':
-        categories = TroveCategoryController()
+    categories = TroveCategoryController()
 
     def __init__(self):
         n_url_prefix = '/%s/' % request.path.split('/')[1]

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2fdefbff/Allura/allura/controllers/trovecategories.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/trovecategories.py b/Allura/allura/controllers/trovecategories.py
index 22b161f..ceba651 100644
--- a/Allura/allura/controllers/trovecategories.py
+++ b/Allura/allura/controllers/trovecategories.py
@@ -18,6 +18,7 @@
 from tg import expose, flash, redirect, validate, config
 from pylons import tmpl_context as c
 from string import digits, lowercase
+from webob.exc import HTTPForbidden
 
 from allura import model as M
 from allura.controllers import BaseController
@@ -40,7 +41,13 @@ class TroveCategoryController(BaseController):
         return TroveCategoryController(category=cat), remainder
 
     def _check_security(self):
-        if config.get('trovecategories.enableediting', 'false') == 'admin':
+        enable_editing = config.get('trovecategories.enableediting', 'false')
+        if enable_editing == 'false':
+            raise HTTPForbidden()
+
+        require_authenticated()
+
+        if enable_editing == 'admin':
             with h.push_context(config.get('site_admin_project', 'allura'),
                                 neighborhood=config.get('site_admin_project_nbhd', 'Projects')):
                 require_access(c.project, 'admin')
@@ -51,8 +58,6 @@ class TroveCategoryController(BaseController):
 
     @expose('jinja:allura:templates/trovecategories.html')
     def index(self, **kw):
-        require_authenticated()
-
         if self.category:
             selected_cat = self.category
             l = self.category.subcategories
@@ -74,8 +79,6 @@ class TroveCategoryController(BaseController):
     @require_post()
     @validate(F.add_category_form, error_handler=index)
     def create(self, **kw):
-        require_authenticated()
-
         name = kw.get('categoryname')
         upper_id = int(kw.get('uppercategory_id', 0))
 
@@ -121,8 +124,6 @@ class TroveCategoryController(BaseController):
     @require_post()
     @validate(F.remove_category_form, error_handler=index)
     def remove(self, **kw):
-        require_authenticated()
-
         cat = M.TroveCategory.query.get(trove_cat_id=int(kw['categoryid']))
         if cat.trove_parent_id:
             parent = M.TroveCategory.query.get(

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2fdefbff/Allura/allura/templates/user_skills.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/user_skills.html b/Allura/allura/templates/user_skills.html
index 25b7aa5..0838a97 100644
--- a/Allura/allura/templates/user_skills.html
+++ b/Allura/allura/templates/user_skills.html
@@ -99,7 +99,7 @@
     <h3>Other possible actions</h3>
     <div class="grid-20" style="margin-bottom:10px;"/>
       <ul>
-        {%if tg.config.get('trovecategories.enableediting', 'false')=='true'%}
+        {%if tg.config.get('trovecategories.enableediting', 'false')!='false'%}
           {% if selected_skill %}
             <li>
               <a href="/categories/{{selected_skill.shortname}}">

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2fdefbff/Allura/allura/tests/functional/test_trovecategory.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_trovecategory.py b/Allura/allura/tests/functional/test_trovecategory.py
new file mode 100644
index 0000000..2f0bd54
--- /dev/null
+++ b/Allura/allura/tests/functional/test_trovecategory.py
@@ -0,0 +1,62 @@
+import mock
+
+from tg import config
+from nose.tools import assert_equals, assert_true
+from ming.orm import session
+from bson.objectid import ObjectId
+
+from allura import model as M
+from allura.lib import helpers as h
+from allura.tests import TestController
+
+
+class TestTroveCategory(TestController):
+
+    @mock.patch('allura.model.project.g.post_event')
+    def test_events(self, post_event):
+        # Create event
+        cfg = {'trovecategories.enableediting': 'true'}
+        with h.push_config(config, **cfg):
+            r = self.app.post('/categories/create/', params=dict(categoryname='test'))
+
+        category_id = post_event.call_args[0][1]
+        assert_true(isinstance(category_id, ObjectId))
+        assert_equals(post_event.call_args[0][0], 'trove_category_created')
+        category = M.TroveCategory.query.get(_id=category_id)
+
+        # Update event
+        category.fullname = 'test2'
+        session(M.TroveCategory).flush()
+        edited_category_id = post_event.call_args[0][1]
+        assert_true(isinstance(edited_category_id, ObjectId))
+        assert_equals(edited_category_id, category_id)
+        assert_equals(post_event.call_args[0][0], 'trove_category_updated')
+
+        # Delete event
+        M.TroveCategory.delete(category)
+        session(M.TroveCategory).flush()
+        deleted_category_id = post_event.call_args[0][1]
+        assert_true(isinstance(deleted_category_id, ObjectId))
+        assert_equals(deleted_category_id, category_id)
+        assert_equals(post_event.call_args[0][0], 'trove_category_deleted')        
+
+    def test_enableediting_setting(self):
+        def check_access(username=None, status=None):
+            self.app.get('/categories/', status=status,
+                         extra_environ=dict(username=username))
+
+        cfg = {'trovecategories.enableediting': 'true'}
+
+        with h.push_config(config, **cfg):
+            check_access(username='test-user', status=200)
+            check_access(username='root', status=200)
+
+        cfg['trovecategories.enableediting'] = 'false'
+        with h.push_config(config, **cfg):
+            check_access(username='test-user', status=403)
+            check_access(username='root', status=403)
+
+        cfg['trovecategories.enableediting'] = 'admin'
+        with h.push_config(config, **cfg):
+            check_access(username='test-user', status=403)
+            check_access(username='root', status=200)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/2fdefbff/Allura/test.ini
----------------------------------------------------------------------
diff --git a/Allura/test.ini b/Allura/test.ini
index b1880b8..a82fbf2 100644
--- a/Allura/test.ini
+++ b/Allura/test.ini
@@ -56,6 +56,8 @@ ming.main.uri = mim:///allura
 ming.project.uri = mim:///project-data
 ming.task.uri = mim:///task
 
+trovecategories.enableediting = true
+
 # ActivityStream
 activitystream.master = mim://
 activitystream.database = activitystream


Mime
View raw message