2010-09-16 16:58:11 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2009-06-18 22:57:47 +02:00
|
|
|
import unittest
|
2009-12-19 16:03:12 +01:00
|
|
|
|
|
|
|
from DateTime import DateTime
|
2009-06-18 22:57:47 +02:00
|
|
|
|
|
|
|
from zope.component import createObject
|
|
|
|
|
|
|
|
from Products.CMFCore.utils import getToolByName
|
|
|
|
from Products.PloneTestCase.ptc import PloneTestCase
|
|
|
|
|
2011-04-17 10:50:34 +02:00
|
|
|
from plone.app.testing import TEST_USER_ID, setRoles
|
|
|
|
|
|
|
|
from plone.app.discussion.testing import\
|
|
|
|
PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
|
|
|
|
2009-06-18 22:57:47 +02:00
|
|
|
from plone.app.discussion.browser.moderation import View
|
2010-09-16 16:58:11 +02:00
|
|
|
from plone.app.discussion.browser.moderation import BulkActionsView
|
2010-07-13 12:45:53 +02:00
|
|
|
from plone.app.discussion.interfaces import IConversation
|
2009-06-18 22:57:47 +02:00
|
|
|
|
|
|
|
|
2011-04-17 10:50:34 +02:00
|
|
|
class ModerationViewTest(unittest.TestCase):
|
2011-04-22 19:04:35 +02:00
|
|
|
|
2011-04-17 10:50:34 +02:00
|
|
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
2011-04-22 19:04:35 +02:00
|
|
|
|
2011-04-17 10:50:34 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.app = self.layer['app']
|
|
|
|
self.portal = self.layer['portal']
|
|
|
|
self.request = self.layer['request']
|
|
|
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
2009-06-18 22:57:47 +02:00
|
|
|
typetool = self.portal.portal_types
|
|
|
|
typetool.constructContent('Document', self.portal, 'doc1')
|
2009-10-18 15:12:52 +02:00
|
|
|
self.portal_discussion = getToolByName(self.portal,
|
|
|
|
'portal_discussion',
|
|
|
|
None)
|
2011-04-17 10:50:34 +02:00
|
|
|
self.membership_tool = getToolByName(self.portal,
|
2009-10-18 15:12:52 +02:00
|
|
|
'portal_membership')
|
2009-06-18 22:57:47 +02:00
|
|
|
self.memberdata = self.portal.portal_memberdata
|
|
|
|
request = self.app.REQUEST
|
|
|
|
context = getattr(self.portal, 'doc1')
|
|
|
|
self.view = View(context, request)
|
2010-01-22 17:28:00 +01:00
|
|
|
self.view.__of__(context)
|
2009-10-18 15:12:52 +02:00
|
|
|
self.portal.portal_workflow.setChainForPortalTypes(
|
|
|
|
('Discussion Item',), 'comment_review_workflow')
|
2009-06-27 11:35:52 +02:00
|
|
|
self.wf_tool = self.portal.portal_workflow
|
2011-04-17 10:50:34 +02:00
|
|
|
|
2009-10-18 15:12:52 +02:00
|
|
|
def test_moderation_enabled(self):
|
2010-12-16 00:52:56 +01:00
|
|
|
"""Make sure that moderation_enabled returns true if the comment
|
2010-10-08 12:22:40 +02:00
|
|
|
workflow implements a 'pending' state.
|
|
|
|
"""
|
|
|
|
# The one_state_workflow does not have a 'pending' state
|
2009-10-18 15:12:52 +02:00
|
|
|
self.wf_tool.setChainForPortalTypes(('Discussion Item',),
|
2010-10-08 12:22:40 +02:00
|
|
|
('one_state_workflow,'))
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(self.view.moderation_enabled(), False)
|
2010-10-08 12:22:40 +02:00
|
|
|
# The comment_review_workflow does have a 'pending' state
|
|
|
|
self.wf_tool.setChainForPortalTypes(('Discussion Item',),
|
|
|
|
('comment_review_workflow,'))
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(self.view.moderation_enabled(), True)
|
2011-04-17 10:50:34 +02:00
|
|
|
|
2009-12-19 16:03:12 +01:00
|
|
|
def test_old_comments_not_shown_in_moderation_view(self):
|
|
|
|
# Create old comment
|
|
|
|
discussion = getToolByName(self.portal, 'portal_discussion', None)
|
2010-12-16 00:52:56 +01:00
|
|
|
discussion.overrideDiscussionFor(self.portal.doc1, 1)
|
2009-12-19 16:03:12 +01:00
|
|
|
talkback = discussion.getDiscussionFor(self.portal.doc1)
|
|
|
|
self.portal.doc1.talkback.createReply('My Title', 'My Text', Creator='Jim')
|
|
|
|
reply = talkback.getReplies()[0]
|
|
|
|
reply.setReplyTo(self.portal.doc1)
|
|
|
|
reply.creation_date = DateTime(2003, 3, 11, 9, 28, 6)
|
|
|
|
reply.modification_date = DateTime(2009, 7, 12, 19, 38, 7)
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(reply.Title(), 'My Title')
|
|
|
|
self.assertEqual(reply.EditableBody(), 'My Text')
|
|
|
|
self.assertTrue('Jim' in reply.listCreators())
|
|
|
|
self.assertEqual(talkback.replyCount(self.portal.doc1), 1)
|
|
|
|
self.assertEqual(reply.inReplyTo(), self.portal.doc1)
|
2011-04-17 10:50:34 +02:00
|
|
|
|
|
|
|
view = self.view()
|
|
|
|
|
|
|
|
self.assertTrue('No comments to moderate' in view)
|
|
|
|
self.assertEqual(len(self.view.comments), 0)
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2009-06-18 22:57:47 +02:00
|
|
|
|
2011-04-17 10:50:34 +02:00
|
|
|
class ModerationBulkActionsViewTest(unittest.TestCase):
|
2010-09-16 16:58:11 +02:00
|
|
|
|
2011-04-17 10:50:34 +02:00
|
|
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
2010-09-16 16:58:11 +02:00
|
|
|
|
2011-04-17 10:50:34 +02:00
|
|
|
def setUp(self):
|
|
|
|
self.app = self.layer['app']
|
|
|
|
self.portal = self.layer['portal']
|
|
|
|
self.request = self.layer['request']
|
|
|
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
2010-09-16 16:58:11 +02:00
|
|
|
typetool = self.portal.portal_types
|
|
|
|
typetool.constructContent('Document', self.portal, 'doc1')
|
2010-12-16 00:52:56 +01:00
|
|
|
self.wf = getToolByName(self.portal,
|
2010-09-16 17:12:59 +02:00
|
|
|
'portal_workflow',
|
|
|
|
None)
|
2010-09-16 16:58:11 +02:00
|
|
|
self.context = self.portal
|
|
|
|
self.portal.portal_workflow.setChainForPortalTypes(
|
|
|
|
('Discussion Item',), 'comment_review_workflow')
|
|
|
|
self.wf_tool = self.portal.portal_workflow
|
|
|
|
# Add a conversation with three comments
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
comment1.title = 'Comment 1'
|
|
|
|
comment1.text = 'Comment text'
|
|
|
|
comment1.Creator = 'Jim'
|
|
|
|
new_id_1 = conversation.addComment(comment1)
|
|
|
|
self.comment1 = self.portal.doc1.restrictedTraverse(\
|
|
|
|
'++conversation++default/%s' % new_id_1)
|
|
|
|
comment2 = createObject('plone.Comment')
|
|
|
|
comment2.title = 'Comment 2'
|
|
|
|
comment2.text = 'Comment text'
|
|
|
|
comment2.Creator = 'Joe'
|
|
|
|
new_id_2 = conversation.addComment(comment2)
|
|
|
|
self.comment2 = self.portal.doc1.restrictedTraverse(\
|
|
|
|
'++conversation++default/%s' % new_id_2)
|
|
|
|
comment3 = createObject('plone.Comment')
|
|
|
|
comment3.title = 'Comment 3'
|
|
|
|
comment3.text = 'Comment text'
|
|
|
|
comment3.Creator = 'Emma'
|
|
|
|
new_id_3 = conversation.addComment(comment3)
|
|
|
|
self.comment3 = self.portal.doc1.restrictedTraverse(\
|
|
|
|
'++conversation++default/%s' % new_id_3)
|
|
|
|
self.conversation = conversation
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2010-09-16 17:42:27 +02:00
|
|
|
def test_default_bulkaction(self):
|
2010-09-16 17:44:07 +02:00
|
|
|
# Make sure no error is raised when no bulk actions has been supplied
|
2010-09-16 17:42:27 +02:00
|
|
|
self.request.set('form.select.BulkAction', '-1')
|
2010-09-18 19:02:37 +02:00
|
|
|
self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())])
|
2011-04-22 19:04:35 +02:00
|
|
|
|
2011-04-17 10:50:34 +02:00
|
|
|
view = BulkActionsView(self.portal, self.request)
|
2011-04-22 19:04:35 +02:00
|
|
|
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertFalse(view())
|
2011-04-22 19:04:35 +02:00
|
|
|
|
2010-09-16 16:58:11 +02:00
|
|
|
def test_retract(self):
|
|
|
|
self.request.set('form.select.BulkAction', 'retract')
|
2010-09-18 19:02:37 +02:00
|
|
|
self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())])
|
2011-04-22 19:04:35 +02:00
|
|
|
|
2011-04-17 10:50:34 +02:00
|
|
|
view = BulkActionsView(self.portal, self.request)
|
2011-04-22 19:04:35 +02:00
|
|
|
|
2010-09-16 16:58:11 +02:00
|
|
|
self.assertRaises(NotImplementedError,
|
2010-09-18 19:02:37 +02:00
|
|
|
view)
|
2010-09-16 16:58:11 +02:00
|
|
|
|
|
|
|
def test_publish(self):
|
|
|
|
self.request.set('form.select.BulkAction', 'publish')
|
2010-12-16 00:52:56 +01:00
|
|
|
self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())])
|
2011-04-17 10:50:34 +02:00
|
|
|
view = BulkActionsView(self.portal, self.request)
|
2011-04-22 19:04:35 +02:00
|
|
|
|
2010-09-16 17:12:59 +02:00
|
|
|
view()
|
2011-04-22 19:04:35 +02:00
|
|
|
|
2010-09-16 17:12:59 +02:00
|
|
|
# Count published comments
|
|
|
|
published_comments = 0
|
|
|
|
for r in self.conversation.getThreads():
|
|
|
|
comment_obj = r['comment']
|
|
|
|
workflow_status = self.wf.getInfoFor(comment_obj, 'review_state')
|
|
|
|
if workflow_status == 'published':
|
|
|
|
published_comments += 1
|
2010-09-16 17:42:27 +02:00
|
|
|
# Make sure the comment has been published
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(published_comments, 1)
|
2011-04-22 19:04:35 +02:00
|
|
|
|
2010-09-16 16:58:11 +02:00
|
|
|
def test_mark_as_spam(self):
|
|
|
|
self.request.set('form.select.BulkAction', 'mark_as_spam')
|
2010-09-18 19:02:37 +02:00
|
|
|
self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())])
|
2011-04-17 10:50:34 +02:00
|
|
|
|
|
|
|
view = BulkActionsView(self.portal, self.request)
|
2011-04-22 19:04:35 +02:00
|
|
|
|
2010-09-16 16:58:11 +02:00
|
|
|
self.assertRaises(NotImplementedError,
|
2010-09-18 19:02:37 +02:00
|
|
|
view)
|
2011-04-22 19:04:35 +02:00
|
|
|
|
2010-09-16 16:58:11 +02:00
|
|
|
def test_delete(self):
|
|
|
|
# Initially we have three comments
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(self.conversation.total_comments, 3)
|
2010-09-16 16:58:11 +02:00
|
|
|
# Delete two comments with bulk actions
|
|
|
|
self.request.set('form.select.BulkAction', 'delete')
|
|
|
|
self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath()),
|
2010-12-16 00:52:56 +01:00
|
|
|
'/'.join(self.comment3.getPhysicalPath())])
|
2011-04-17 10:50:34 +02:00
|
|
|
view = BulkActionsView(self.app, self.request)
|
2011-04-22 19:04:35 +02:00
|
|
|
|
2010-09-16 16:58:11 +02:00
|
|
|
view()
|
2011-04-22 19:04:35 +02:00
|
|
|
|
2010-09-16 16:58:11 +02:00
|
|
|
# Make sure that the two comments have been deleted
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertEqual(self.conversation.total_comments, 1)
|
2010-09-16 16:58:11 +02:00
|
|
|
comment = self.conversation.getComments().next()
|
2011-04-15 18:23:38 +02:00
|
|
|
self.assertTrue(comment)
|
|
|
|
self.assertEqual(comment, self.comment2)
|
2010-09-16 16:58:11 +02:00
|
|
|
|
2009-06-18 22:57:47 +02:00
|
|
|
def test_suite():
|
2010-09-16 16:58:11 +02:00
|
|
|
return unittest.defaultTestLoader.loadTestsFromName(__name__)
|