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

[02/21] git commit: [#3154] ticket:392 ForgeLink REST API

[#3154]  ticket:392 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/bf67ad1e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/bf67ad1e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/bf67ad1e

Branch: refs/heads/tv/6463
Commit: bf67ad1e56f174a68a8fa075bc5d9988130b6a96
Parents: 5cddfe0
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Wed Jul 10 16:14:38 2013 +0400
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Fri Jul 19 21:02:52 2013 +0000

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


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/bf67ad1e/ForgeLink/forgelink/link_main.py
----------------------------------------------------------------------
diff --git a/ForgeLink/forgelink/link_main.py b/ForgeLink/forgelink/link_main.py
index 1f5fb2e..d004fe1 100644
--- a/ForgeLink/forgelink/link_main.py
+++ b/ForgeLink/forgelink/link_main.py
@@ -60,6 +60,7 @@ class ForgeLinkApp(Application):
         Application.__init__(self, project, config)
         self.root = RootController()
         self.admin = LinkAdminController(self)
+        self.api_root = RootRestController()
 
     @property
     @h.exceptionless([], log)
@@ -115,3 +116,15 @@ class LinkAdminController(DefaultAdminController):
     def index(self, **kw):
         flash('External link URL updated.')
         redirect(c.project.url()+'admin/tools')
+
+class RootRestController(BaseController):
+
+    def _check_security(self):
+        require_access(c.app, 'read')
+
+    @expose('json:')
+    def index(self, url='', **kw):
+        if request.method == 'POST':
+            require_access(c.app, 'edit')
+            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/bf67ad1e/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
new file mode 100644
index 0000000..fa02ef1
--- /dev/null
+++ b/ForgeLink/forgelink/tests/functional/test_rest.py
@@ -0,0 +1,46 @@
+# coding: utf-8
+
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+
+from nose.tools import assert_equal
+from allura.tests import decorators as td
+from alluratest.controller import TestRestApiBase
+
+
+class TestLinkApi(TestRestApiBase):
+
+    @td.with_link
+    def test_get_link(self):
+        data = {'url':'http://google.com'}
+        r = self.api_get(u'/rest/p/test/link'.encode('utf-8'))
+        assert_equal(r.json['url'], None)
+        r = self.api_post(u'/rest/p/test/link'.encode('utf-8'), **data)
+        assert_equal(r.json['url'], 'http://google.com')
+        r = self.api_get(u'/rest/p/test/link'.encode('utf-8'))
+        assert_equal(r.json['url'], 'http://google.com')
+
+    @td.with_link
+    def test_update_link(self):
+        data = {'url':'http://google.com'}
+        r = self.api_post(u'/rest/p/test/link'.encode('utf-8'), **data)
+        assert_equal(r.json['url'], 'http://google.com')
+        data = {'url':'http://yahoo.com'}
+        r = self.api_post(u'/rest/p/test/link'.encode('utf-8'), **data)
+        assert_equal(r.json['url'], 'http://yahoo.com')
+        r = self.api_get(u'/rest/p/test/link'.encode('utf-8'))
+        assert_equal(r.json['url'], 'http://yahoo.com')