You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/07/19 23:32:22 UTC

[3/3] git commit: [#3154] ticket:392 added tests ForgeLink REST API

[#3154]  ticket:392 added tests ForgeLink REST API


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

Branch: refs/heads/master
Commit: 0e8c64712bd9f8c4798421213e3510d55d3bb815
Parents: 123a49c
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Mon Jul 15 11:26:36 2013 +0400
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Fri Jul 19 21:02:53 2013 +0000

----------------------------------------------------------------------
 ForgeLink/forgelink/link_main.py                |  2 +-
 .../forgelink/tests/functional/test_rest.py     | 49 ++++++++++++++++++--
 2 files changed, 46 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0e8c6471/ForgeLink/forgelink/link_main.py
----------------------------------------------------------------------
diff --git a/ForgeLink/forgelink/link_main.py b/ForgeLink/forgelink/link_main.py
index a4794a2..370e6cc 100644
--- a/ForgeLink/forgelink/link_main.py
+++ b/ForgeLink/forgelink/link_main.py
@@ -126,7 +126,7 @@ class RootRestController(BaseController):
 
     @expose('json:')
     def index(self, url='', **kw):
-        if request.method == 'POST':
+        if (request.method == 'POST') and (url != ''):
             require_access(c.app, 'configure')
             c.app.config.options.url = url
         return dict(url=c.app.config.options.get('url'))

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0e8c6471/ForgeLink/forgelink/tests/functional/test_rest.py
----------------------------------------------------------------------
diff --git a/ForgeLink/forgelink/tests/functional/test_rest.py b/ForgeLink/forgelink/tests/functional/test_rest.py
index 338094f..05a55a2 100644
--- a/ForgeLink/forgelink/tests/functional/test_rest.py
+++ b/ForgeLink/forgelink/tests/functional/test_rest.py
@@ -20,20 +20,61 @@
 from nose.tools import assert_equal
 from allura.tests import decorators as td
 from alluratest.controller import TestRestApiBase
+from allura import model as M
+from allura.lib import helpers as h
 
 
 class TestLinkApi(TestRestApiBase):
 
+    def setUp(self):
+        super(TestLinkApi, self).setUp()
+        self.setup_with_tools()
+
     @td.with_link
+    def setup_with_tools(self):
+        h.set_context('test', 'link', neighborhood='Projects')
+
     def test_rest_link(self):
         r = self.api_get(u'/rest/p/test/link'.encode('utf-8'))
         assert_equal(r.json['url'], None)
 
-        data = {'url': 'http://google.com'}
-        r = self.api_post(u'/rest/p/test/link'.encode('utf-8'), **data)
+        r = self.api_post(u'/rest/p/test/link'.encode('utf-8'), url='http://google.com')
         assert_equal(r.json['url'], 'http://google.com')
 
-        data = {'url': 'http://yahoo.com'}
-        self.api_post(u'/rest/p/test/link'.encode('utf-8'), **data)
+        self.api_post(u'/rest/p/test/link'.encode('utf-8'), url='http://yahoo.com')
         r = self.api_get(u'/rest/p/test/link'.encode('utf-8'))
         assert_equal(r.json['url'], 'http://yahoo.com')
+
+        self.api_post(u'/rest/p/test/link'.encode('utf-8'))
+        r = self.api_get(u'/rest/p/test/link'.encode('utf-8'))
+        assert_equal(r.json['url'], 'http://yahoo.com')
+
+    def test_rest_link_get_permissions(self):
+        self.app.get('/rest/p/test/link', extra_environ={'username': '*anonymous'}, status=200)
+        p = M.Project.query.get(shortname='test')
+        acl = p.app_instance('link').config.acl
+        anon = M.ProjectRole.by_name('*anonymous')._id
+        anon_read = M.ACE.allow(anon, 'read')
+        acl.remove(anon_read)
+        self.app.get('/rest/p/test/link', extra_environ={'username': '*anonymous'}, status=401)
+
+    def test_rest_link_post_permissions(self):
+        self.app.post('/rest/p/test/link',
+                      params={'url': 'http://yahoo.com'},
+                      extra_environ={'username': '*anonymous'},
+                      status=401)
+        p = M.Project.query.get(shortname='test')
+        acl = p.app_instance('link').config.acl
+        anon = M.ProjectRole.by_name('*anonymous')._id
+        anon_configure = M.ACE.allow(anon, 'configure')
+        acl.append(anon_configure)
+        self.app.post('/rest/p/test/link',
+                      params={'url': 'http://yahoo.com'},
+                      extra_environ={'username': '*anonymous'},
+                      status=200)
+        r = self.api_get(u'/rest/p/test/link'.encode('utf-8'))
+        assert_equal(r.json['url'], 'http://yahoo.com')
+
+
+
+