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/05/29 17:58:06 UTC

[1/3] git commit: [#6267] ticket:360 A little more tests for wiki api

Updated Branches:
  refs/heads/master 82f675f70 -> 067705d61


[#6267] ticket:360 A little more tests for wiki 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/067705d6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/067705d6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/067705d6

Branch: refs/heads/master
Commit: 067705d61f4e28592a99904c007ea4be8a6eddce
Parents: a3e7f32
Author: Igor Bondarenko <je...@gmail.com>
Authored: Fri May 24 13:25:05 2013 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Mon May 27 09:02:18 2013 +0000

----------------------------------------------------------------------
 ForgeWiki/forgewiki/tests/functional/test_rest.py |   18 +++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/067705d6/ForgeWiki/forgewiki/tests/functional/test_rest.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/tests/functional/test_rest.py b/ForgeWiki/forgewiki/tests/functional/test_rest.py
index af1080a..f6f8714 100644
--- a/ForgeWiki/forgewiki/tests/functional/test_rest.py
+++ b/ForgeWiki/forgewiki/tests/functional/test_rest.py
@@ -1,3 +1,4 @@
+# coding: utf-8
 import json
 
 from nose.tools import assert_equal
@@ -32,7 +33,11 @@ class TestWikiApi(TestRestApiBase):
         r = json.loads(r.body)
         assert_equal(len(r['attachments']), 2)
 
-    def test_post_page(self):
+    def test_page_does_not_exist(self):
+        r = self.api_get('/rest/p/test/wiki/fake/')
+        assert_equal(r.status_int, 404)
+
+    def test_update_page(self):
         data = {
             'text': 'Embrace the Dark Side',
             'labels': 'head hunting,dark side'
@@ -42,3 +47,14 @@ class TestWikiApi(TestRestApiBase):
         r = self.api_get('/rest/p/test/wiki/Home/')
         assert_equal(r.json['text'], data['text'])
         assert_equal(r.json['labels'], data['labels'].split(','))
+
+    def test_create_page(self):
+        data = {
+            'text': 'Embrace the Dark Side',
+            'labels': 'head hunting,dark side'
+        }
+        r = self.api_post(u'/rest/p/test/wiki/tést/'.encode('utf-8'), **data)
+        assert_equal(r.status_int, 200)
+        r = self.api_get(u'/rest/p/test/wiki/tést/'.encode('utf-8'))
+        assert_equal(r.json['text'], data['text'])
+        assert_equal(r.json['labels'], data['labels'].split(','))


[3/3] git commit: [#6267] ticket:360 Test for wiki api post

Posted by br...@apache.org.
[#6267] ticket:360 Test for wiki api post


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

Branch: refs/heads/master
Commit: 1af5b404be848880c79864a601e57c700029398c
Parents: 82f675f
Author: Igor Bondarenko <je...@gmail.com>
Authored: Fri May 24 12:54:39 2013 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Mon May 27 09:02:18 2013 +0000

----------------------------------------------------------------------
 ForgeWiki/forgewiki/tests/functional/test_rest.py |   44 ++++++++++++++++
 ForgeWiki/forgewiki/tests/functional/test_root.py |   15 -----
 2 files changed, 44 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1af5b404/ForgeWiki/forgewiki/tests/functional/test_rest.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/tests/functional/test_rest.py b/ForgeWiki/forgewiki/tests/functional/test_rest.py
new file mode 100644
index 0000000..af1080a
--- /dev/null
+++ b/ForgeWiki/forgewiki/tests/functional/test_rest.py
@@ -0,0 +1,44 @@
+import json
+
+from nose.tools import assert_equal
+
+from allura.lib import helpers as h
+from allura.tests import decorators as td
+from alluratest.controller import TestRestApiBase
+
+
+class TestWikiApi(TestRestApiBase):
+
+    def setUp(self):
+        super(TestWikiApi, self).setUp()
+        self.setup_with_tools()
+
+    @td.with_wiki
+    def setup_with_tools(self):
+        h.set_context('test', 'wiki', neighborhood='Projects')
+
+    def test_get_page(self):
+        r = self.app.get('/p/test/wiki/Home/')
+        discussion_url = r.html.findAll('form')[2]['action'][:-4]
+        content = file(__file__).read()
+        self.app.post('/wiki/Home/attach', upload_files=[('file_info', 'test_root.py', content)])
+        r = self.app.get('/rest/p/test/wiki/Home/')
+        r = json.loads(r.body)
+        assert_equal(r['attachments'][0]['url'], 'http://localhost:80/p/test/wiki/Home/attachment/test_root.py')
+        assert_equal(r['discussion_thread_url'], 'http://localhost:80/rest%s' % discussion_url)
+        assert_equal(r['discussion_thread']['_id'], discussion_url.split('/')[-2])
+        self.app.post('/wiki/Home/attach', upload_files=[('file_info', '__init__.py', content),])
+        r = self.app.get('/rest/p/test/wiki/Home/')
+        r = json.loads(r.body)
+        assert_equal(len(r['attachments']), 2)
+
+    def test_post_page(self):
+        data = {
+            'text': 'Embrace the Dark Side',
+            'labels': 'head hunting,dark side'
+        }
+        r = self.api_post('/rest/p/test/wiki/Home/', **data)
+        assert_equal(r.status_int, 200)
+        r = self.api_get('/rest/p/test/wiki/Home/')
+        assert_equal(r.json['text'], data['text'])
+        assert_equal(r.json['labels'], data['labels'].split(','))

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1af5b404/ForgeWiki/forgewiki/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/tests/functional/test_root.py b/ForgeWiki/forgewiki/tests/functional/test_root.py
index 1baa28b..362d8bd 100644
--- a/ForgeWiki/forgewiki/tests/functional/test_root.py
+++ b/ForgeWiki/forgewiki/tests/functional/test_root.py
@@ -621,18 +621,3 @@ class TestRootController(TestController):
     def test_user_browse_page(self):
         r = self.app.get('/wiki/browse_pages/')
         assert '<td>Test Admin (test-admin)</td>' in r
-
-    def test_rest_wiki(self):
-        r = self.app.get('/p/test/wiki/Home/')
-        discussion_url = r.html.findAll('form')[2]['action'][:-4]
-        content = file(__file__).read()
-        self.app.post('/wiki/Home/attach', upload_files=[('file_info', 'test_root.py', content)])
-        r = self.app.get('/rest/p/test/wiki/Home/')
-        r = json.loads(r.body)
-        assert_equal(r['attachments'][0]['url'], 'http://localhost:80/p/test/wiki/Home/attachment/test_root.py')
-        assert_equal(r['discussion_thread_url'], 'http://localhost:80/rest%s' % discussion_url)
-        assert_equal(r['discussion_thread']['_id'], discussion_url.split('/')[-2])
-        self.app.post('/wiki/Home/attach', upload_files=[('file_info', '__init__.py', content),])
-        r = self.app.get('/rest/p/test/wiki/Home/')
-        r = json.loads(r.body)
-        assert_equal(len(r['attachments']), 2)


[2/3] git commit: [#6267] ticket:360 Restore wiki API POST functionality

Posted by br...@apache.org.
[#6267] ticket:360 Restore wiki API POST functionality


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

Branch: refs/heads/master
Commit: a3e7f320c28c641fa60905af08120faac58e5457
Parents: 1af5b40
Author: Igor Bondarenko <je...@gmail.com>
Authored: Fri May 24 13:09:46 2013 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Mon May 27 09:02:18 2013 +0000

----------------------------------------------------------------------
 ForgeWiki/forgewiki/wiki_main.py |   50 ++++++++++++++++-----------------
 1 files changed, 24 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a3e7f320/ForgeWiki/forgewiki/wiki_main.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index 94f98a5..650d271 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -702,42 +702,40 @@ class RootRestController(BaseController):
         return PageRestController(title), remainder
 
 
-    @h.vardec
-    @expose()
-    @require_post()
-    def post(self, title, **post_data):
-        page = WM.Page.query.get(
-            app_config_id=c.app.config._id,
-            title=title,
-            deleted=False)
-        if not page:
-            require_access(c.app, 'create')
-            page = WM.Page.upsert(title)
-            page.viewable_by = ['all']
-        else:
-            require_access(page, 'edit')
-        page.text = post_data['text']
-        if 'labels' in post_data:
-            page.labels = post_data['labels'].split(',')
-        page.commit()
-
 class PageRestController(BaseController):
 
     def __init__(self, title):
-        if title is not None:
-            self.page = WM.Page.query.get(app_config_id=c.app.config._id,
-                                          title=h.really_unicode(unquote(title)),
-                                          deleted=False)
-            if self.page is None:
-                raise exc.HTTPNotFound()
+        self.title = h.really_unicode(unquote(title)) if title else None
+        self.page = WM.Page.query.get(app_config_id=c.app.config._id,
+                                      title=self.title,
+                                      deleted=False)
 
     def _check_security(self):
-        require_access(self.page, 'read')
+        if self.page:
+            require_access(self.page, 'read')
 
+    @h.vardec
     @expose('json:')
     def index(self, **kw):
+        if request.method == 'POST':
+            return self._update_page(self.title, **kw)
+        if self.page is None:
+            raise exc.HTTPNotFound()
         return self.page.__json__()
 
+    def _update_page(self, title, **post_data):
+        if not self.page:
+            require_access(c.app, 'create')
+            self.page = WM.Page.upsert(title)
+            self.page.viewable_by = ['all']
+        else:
+            require_access(self.page, 'edit')
+        self.page.text = post_data['text']
+        if 'labels' in post_data:
+            self.page.labels = post_data['labels'].split(',')
+        self.page.commit()
+        return {}
+
 
 class WikiAdminController(DefaultAdminController):