This is an automated email from the ASF dual-hosted git repository.
gcruz pushed a commit to branch gc/8475
in repository https://gitbox.apache.org/repos/asf/allura.git
The following commit(s) were added to refs/heads/gc/8475 by this push:
new 755878189 [#8475] updated test and conditional to return a 404
755878189 is described below
commit 7558781891ebe20726e64689eea13897cb620a26
Author: Guillermo Cruz <[email protected]>
AuthorDate: Mon Nov 7 09:13:09 2022 -0700
[#8475] updated test and conditional to return a 404
---
Allura/allura/controllers/discuss.py | 2 +-
.../forgediscussion/tests/functional/test_forum.py | 29 +++++++++++-----------
2 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/Allura/allura/controllers/discuss.py
b/Allura/allura/controllers/discuss.py
index 911ae1b40..8d6787aa9 100644
--- a/Allura/allura/controllers/discuss.py
+++ b/Allura/allura/controllers/discuss.py
@@ -208,7 +208,7 @@ class ThreadController(BaseController, FeedController,
metaclass=h.ProxiedAttrMe
M.session.artifact_orm_session._get().skip_mod_date = True
M.session.artifact_orm_session._get().skip_last_updated = True
count = self.thread.query_posts(page=page, limit=int(limit)).count()
- if self.thread.num_replies == 0:
+ if self.thread.num_replies == 0 or not all(p.status == 'ok' for p in
self.thread.posts):
# return status code 404 but still display the page content
request.environ['tg.status_code_redirect'] = True
response.status_int = 404
diff --git a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
b/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
index bc4a0373a..0008302a5 100644
--- a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
+++ b/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
@@ -546,11 +546,12 @@ class TestForum(TestController):
params[f.find('textarea')['name']] = 'Post content'
params[f.find('select')['name']] = 'testforum'
params[f.find('input', {'style': 'width: 90%'})['name']] = 'Test
Thread'
- thread = self.app.post('/discussion/save_new_topic', params=params,
-
extra_environ=dict(username='*anonymous')).follow()
+ thread = self.app.post('/discussion/save_new_topic', params=params,
expect_errors=True,
+ extra_environ=dict(username='*anonymous'))
- # assert post awaiting moderation
- r = self.app.get(thread.request.url,
+ # assert post return 404 but content can still be seen and moderated
+ thread_url = thread.response.headers['Location']
+ r = self.app.get(thread.response.headers['Location'], status=404,
expect_errors=True,
extra_environ=dict(username='*anonymous'))
assert 'Post awaiting moderation' in r
assert 'name="delete"' not in r
@@ -560,7 +561,7 @@ class TestForum(TestController):
assert_equal(spam_checker.check.call_args[0][0], 'Test Thread\nPost
content')
# assert unapproved thread replies do not appear
- f = thread.html.find('div', {'class': 'comment-row
reply_post_form'}).find('form')
+ f = r.html.find('div', {'class': 'comment-row
reply_post_form'}).find('form')
rep_url = f.get('action')
params = dict()
inputs = f.findAll('input')
@@ -568,14 +569,14 @@ class TestForum(TestController):
if field.has_attr('name'):
params[field['name']] = field.get('value') or ''
params[f.find('textarea')['name']] = 'anon reply to anon post content'
- r = self.app.post(str(rep_url), params=params,
extra_environ=dict(username='*anonymous'))
- r = self.app.get(thread.request.url,
+ r = self.app.post(str(rep_url), params=params, expect_errors=True,
extra_environ=dict(username='*anonymous'))
+ r = self.app.get(thread_url, status=404, expect_errors=True,
extra_environ=dict(username='*anonymous'))
assert 'anon reply to anon post' not in r
assert_equal(spam_checker.check.call_args[0][0], 'anon reply to anon
post content')
# assert moderation controls appear for admin
- r = self.app.get(thread.request.url)
+ r = self.app.get(thread_url, expect_errors=True,
extra_environ=dict(username='test-admin'))
assert '<div class="display_post moderate">' in r
assert '<i class="fa fa-reply"></i>' in r
@@ -598,15 +599,13 @@ class TestForum(TestController):
'post-0._id': post._id,
'post-0.checked': 'on',
'approve': 'Approve Marked'})
+
post = FM.ForumPost.query.get(text='Post content')
+ assert 'ok' == post.status
- # assert anon can't edit their original post
- r = self.app.get(thread.request.url,
- extra_environ=dict(username='*anonymous'))
- assert 'Post content' in r
- post_container = r.html.find('div', {'id': post.slug})
- btn_edit = post_container.find('a', {'title': 'Edit'})
- assert not btn_edit
+ # assert spam posts return a 404
+ r = self.app.get(thread_url, expect_errors=True, status=404)
+ assert '404' in r.status
@td.with_tool('test2', 'Discussion', 'discussion')