You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2015/10/01 18:24:53 UTC
[1/2] allura git commit: [#7943] ticket:842 Remove /_discuss/ endpoint
Repository: allura
Updated Branches:
refs/heads/ib/7943 [created] 2caa81d02
[#7943] ticket:842 Remove /_discuss/ endpoint
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/e88bf8c8
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/e88bf8c8
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/e88bf8c8
Branch: refs/heads/ib/7943
Commit: e88bf8c8f0dd8319bc802ebfb959378be066a834
Parents: 79b2b98
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Oct 1 14:21:54 2015 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Thu Oct 1 14:21:54 2015 +0000
----------------------------------------------------------------------
Allura/allura/controllers/discuss.py | 16 +++-------------
.../forgediscussion/controllers/forum.py | 11 +++++++----
2 files changed, 10 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/e88bf8c8/Allura/allura/controllers/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/discuss.py b/Allura/allura/controllers/discuss.py
index df8076d..36a9b97 100644
--- a/Allura/allura/controllers/discuss.py
+++ b/Allura/allura/controllers/discuss.py
@@ -89,18 +89,12 @@ class DiscussionController(BaseController, FeedController):
if not hasattr(self, 'moderate'):
self.moderate = ModerationController(self)
- @with_trailing_slash
- @expose('jinja:allura:templates/discussion/index.html')
- def index(self, threads=None, limit=None, page=0, count=0, **kw):
- c.discussion = self.W.discussion
- c.discussion_header = self.W.discussion_header
- if threads is None:
- threads = self.discussion.threads
- return dict(discussion=self.discussion, limit=limit, page=page, count=count, threads=threads)
+ def error_handler(self, *args, **kwargs):
+ redirect(request.referer)
@h.vardec
@expose()
- @validate(pass_validator, error_handler=index)
+ @validate(pass_validator, error_handler=error_handler)
def subscribe(self, **kw):
threads = kw.pop('threads', [])
for t in threads:
@@ -528,7 +522,3 @@ class ThreadRestController(ThreadController):
class AppDiscussionRestController(AppDiscussionController):
ThreadController = ThreadRestController
PostController = PostRestController
-
- @expose('json:')
- def index(self, **kw):
- return dict(discussion=self.discussion)
http://git-wip-us.apache.org/repos/asf/allura/blob/e88bf8c8/ForgeDiscussion/forgediscussion/controllers/forum.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/controllers/forum.py b/ForgeDiscussion/forgediscussion/controllers/forum.py
index 8d0117d..8229151 100644
--- a/ForgeDiscussion/forgediscussion/controllers/forum.py
+++ b/ForgeDiscussion/forgediscussion/controllers/forum.py
@@ -107,12 +107,15 @@ class ForumController(DiscussionController):
c.subscribed = M.Mailbox.subscribed(artifact=self.discussion)
threads = DM.ForumThread.query.find(dict(discussion_id=self.discussion._id, num_replies={'$gt': 0})) \
.sort([('flags', pymongo.DESCENDING), ('last_post_date', pymongo.DESCENDING)])
- response = super(
- ForumController, self).index(threads=threads.skip(start).limit(int(limit)).all(),
- limit=limit, page=page, count=threads.count(), **kw)
+ c.discussion = self.W.discussion
c.discussion_header = self.W.discussion_header
c.whole_forum_subscription_form = self.W.subscribe_form
- return response
+ return dict(
+ discussion=self.discussion,
+ count=threads.count(),
+ threads=threads.skip(start).limit(int(limit)).all(),
+ limit=limit,
+ page=page)
@expose()
def icon(self):
[2/2] allura git commit: [#7943] ticket:842 Rewrite tests
Posted by je...@apache.org.
[#7943] ticket:842 Rewrite tests
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/2caa81d0
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/2caa81d0
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/2caa81d0
Branch: refs/heads/ib/7943
Commit: 2caa81d02ceccb576cdfcb90a5ada2998df37f33
Parents: e88bf8c
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Oct 1 16:04:01 2015 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Thu Oct 1 16:04:01 2015 +0000
----------------------------------------------------------------------
Allura/allura/tests/functional/test_discuss.py | 85 +++++++++-----------
.../forgetracker/tests/functional/test_rest.py | 20 ++---
2 files changed, 44 insertions(+), 61 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/2caa81d0/Allura/allura/tests/functional/test_discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_discuss.py b/Allura/allura/tests/functional/test_discuss.py
index 0063cb8..21b5d3b 100644
--- a/Allura/allura/tests/functional/test_discuss.py
+++ b/Allura/allura/tests/functional/test_discuss.py
@@ -17,48 +17,51 @@
import os
from mock import patch
-from nose.tools import assert_in, assert_not_in, assert_equal
+from nose.tools import assert_in, assert_not_in, assert_equal, assert_false, assert_true
from ming.odm import session
from allura.tests import TestController
from allura import model as M
+class TestDiscussBase(TestController):
-class TestDiscuss(TestController):
+ def _thread_link(self):
+ home = self.app.get('/wiki/Home/')
+ new_post = home.html.find('div', {'id': 'new_post_holder'})
+ thread_link = new_post.find('form', {'id': 'edit_post'}).get('action')
+ return thread_link.rstrip('post')
+
+ def _thread_id(self):
+ home = self.app.get('/wiki/Home/')
+ new_post = home.html.find('div', {'id': 'new_post_holder'})
+ thread_link = new_post.find('form', {'id': 'edit_post'}).get('action')
+ return thread_link.split('/')[-2]
+
+
+class TestDiscuss(TestDiscussBase):
+
+ def _is_subscribed(self, username, thread_id):
+ user_id = str(M.User.by_username(username)._id)
+ thread = M.Thread.query.get(_id=thread_id)
+ return thread.subscriptions.get(user_id)
def test_subscribe_unsubscribe(self):
- home = self.app.get('/wiki/_discuss/')
- subscribed = [i for i in home.html.findAll('input')
- if i.get('type') == 'checkbox'][0]
- assert 'checked' not in subscribed.attrMap
- link = [a for a in home.html.findAll('a')
- if 'thread' in a['href']][0]
+ user = 'test-admin'
+ thread_id = self._thread_id()
+ assert_false(self._is_subscribed(user, thread_id))
+ link = self._thread_link()
params = {
- 'threads-0._id': link['href'][len('/p/test/wiki/_discuss/thread/'):-1],
+ 'threads-0._id': thread_id,
'threads-0.subscription': 'on'}
- r = self.app.post('/wiki/_discuss/subscribe',
- params=params,
- headers={'Referer': '/wiki/_discuss/'})
- r = r.follow()
- subscribed = [i for i in r.html.findAll('input')
- if i.get('type') == 'checkbox'][0]
- assert 'checked' in subscribed.attrMap
- params = {
- 'threads-0._id': link['href'][len('/p/test/wiki/_discuss/thread/'):-1]
- }
- r = self.app.post('/wiki/_discuss/subscribe',
- params=params,
- headers={'Referer': '/wiki/_discuss/'})
- r = r.follow()
- subscribed = [i for i in r.html.findAll('input')
- if i.get('type') == 'checkbox'][0]
- assert 'checked' not in subscribed.attrMap
+ r = self.app.post('/wiki/_discuss/subscribe', params=params)
+ assert_true(self._is_subscribed(user, thread_id))
+ params = {'threads-0._id': thread_id}
+ r = self.app.post('/wiki/_discuss/subscribe', params=params)
+ assert_false(self._is_subscribed(user, thread_id))
def _make_post(self, text):
- home = self.app.get('/wiki/_discuss/')
- thread_link = [a for a in home.html.findAll('a')
- if 'thread' in a['href']][0]['href']
+ thread_link = self._thread_link()
thread = self.app.get(thread_link)
for f in thread.html.findAll('form'):
if f.get('action', '').endswith('/post'):
@@ -78,9 +81,7 @@ class TestDiscuss(TestController):
@patch('allura.controllers.discuss.g.spam_checker.submit_spam')
def test_post(self, submit_spam):
- home = self.app.get('/wiki/_discuss/')
- thread_link = [a for a in home.html.findAll('a')
- if 'thread' in a['href']][0]['href']
+ thread_link = self._thread_link()
r = self._make_post('This is a post')
assert 'This is a post' in r, r
post_link = str(
@@ -124,9 +125,7 @@ class TestDiscuss(TestController):
'This is a new post',), submit_spam.call_args[0]
def test_permissions(self):
- home = self.app.get('/wiki/_discuss/')
- thread_url = [a for a in home.html.findAll('a')
- if 'thread' in a['href']][0]['href']
+ thread_url = self._thread_link()
thread_id = thread_url.rstrip('/').split('/')[-1]
thread = M.Thread.query.get(_id=thread_id)
@@ -154,8 +153,7 @@ class TestDiscuss(TestController):
def test_spam_link(self):
r = self._make_post('Test post')
assert '<span>Spam</span>' in r
- r = self.app.get('/wiki/_discuss/',
- extra_environ={'username': 'test-user-1'})
+ r = self.app.get('/wiki/Home/', extra_environ={'username': 'test-user-1'})
assert '<span>Spam</span>' not in r, 'User without moderate perm must not see Spam link'
@patch('allura.controllers.discuss.g.spam_checker.submit_spam')
@@ -195,9 +193,7 @@ class TestDiscuss(TestController):
assert_in('Post needs moderation!', r)
def test_post_paging(self):
- home = self.app.get('/wiki/_discuss/')
- thread_link = [a for a in home.html.findAll('a')
- if 'thread' in a['href']][0]['href']
+ thread_link = self._thread_link()
# just make sure it doesn't 500
self.app.get('%s?limit=50&page=0' % thread_link)
@@ -243,14 +239,11 @@ class TestDiscuss(TestController):
r = self.app.get(post_link, status=404)
-class TestAttachment(TestController):
+class TestAttachment(TestDiscussBase):
def setUp(self):
super(TestAttachment, self).setUp()
- home = self.app.get('/wiki/_discuss/')
- self.thread_link = [a['href'].encode("utf-8")
- for a in home.html.findAll('a')
- if 'thread' in a['href']][0]
+ self.thread_link = self._thread_link()
thread = self.app.get(self.thread_link)
for f in thread.html.findAll('form'):
if f.get('action', '').endswith('/post'):
@@ -264,7 +257,7 @@ class TestAttachment(TestController):
'value') and field['value'] or ''
params[f.find('textarea')['name']] = 'Test Post'
r = self.app.post(f['action'].encode('utf-8'), params=params,
- headers={'Referer': self.thread_link})
+ headers={'Referer': self.thread_link.encode('utf-8')})
r = r.follow()
self.post_link = str(
r.html.find('div', {'class': 'edit_post_form reply'}).find('form')['action'])
http://git-wip-us.apache.org/repos/asf/allura/blob/2caa81d0/ForgeTracker/forgetracker/tests/functional/test_rest.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/functional/test_rest.py b/ForgeTracker/forgetracker/tests/functional/test_rest.py
index 7d8d91a..d2f42bf 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_rest.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_rest.py
@@ -179,22 +179,13 @@ class TestRestDiscussion(TestTrackerApiBase):
ticket_view = self.create_ticket()
self.ticket_args = ticket_view.json['ticket']
- def test_index(self):
- r = self.api_get('/rest/p/test/bugs/_discuss/')
- assert len(r.json['discussion']['threads']) == 1, r.json
- for t in r.json['discussion']['threads']:
- r = self.api_get('/rest/p/test/bugs/_discuss/thread/%s/' %
- t['_id'])
- assert len(r.json['thread']['posts']) == 0, r.json
-
def test_post(self):
- discussion = self.api_get(
- '/rest/p/test/bugs/_discuss/').json['discussion']
+ r = self.api_get('/rest/p/test/bugs/1/')
+ thread_id = r.json['ticket']['discussion_thread']['_id']
post = self.api_post(
- '/rest/p/test/bugs/_discuss/thread/%s/new' % discussion['threads'][0]['_id'],
+ '/rest/p/test/bugs/_discuss/thread/%s/new' % thread_id,
text='This is a comment', wrap_args=None)
- thread = self.api_get('/rest/p/test/bugs/_discuss/thread/%s/' %
- discussion['threads'][0]['_id'])
+ thread = self.api_get('/rest/p/test/bugs/_discuss/thread/%s/' % thread_id)
assert len(thread.json['thread']['posts']) == 1, thread.json
assert post.json['post']['text'] == 'This is a comment', post.json
reply = self.api_post(
@@ -202,8 +193,7 @@ class TestRestDiscussion(TestTrackerApiBase):
['_id'], post.json['post']['slug']),
text='This is a reply', wrap_args=None)
assert reply.json['post']['text'] == 'This is a reply', reply.json
- thread = self.api_get('/rest/p/test/bugs/_discuss/thread/%s/' %
- discussion['threads'][0]['_id'])
+ thread = self.api_get('/rest/p/test/bugs/_discuss/thread/%s/' % thread_id)
assert len(thread.json['thread']['posts']) == 2, thread.json