Tests for moderate comments bulk actions added.

svn path=/plone.app.discussion/trunk/; revision=39942
This commit is contained in:
Timo Stollenwerk 2010-09-16 14:58:11 +00:00
parent 087efab54a
commit 8d866a0ff6
2 changed files with 101 additions and 2 deletions

View File

@ -22,7 +22,7 @@ from plone.app.discussion.interfaces import IComment
# Bug report: https://bugs.launchpad.net/zope2/+bug/176566
#
def _getContext(self):
def _getContext(self): # pragma: no cover
self = self.aq_parent
while getattr(self, '_is_wrapperish', None):
self = self.aq_parent

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import unittest
from DateTime import DateTime
@ -8,6 +9,7 @@ from Products.CMFCore.utils import getToolByName
from Products.PloneTestCase.ptc import PloneTestCase
from plone.app.discussion.browser.moderation import View
from plone.app.discussion.browser.moderation import BulkActionsView
from plone.app.discussion.interfaces import IConversation
from plone.app.discussion.tests.layer import DiscussionLayer
@ -92,5 +94,102 @@ class ModerationViewTest(PloneTestCase):
self.view()
self.assertEquals(len(self.view.comments), 3)
class ModerationBulkActionsViewTest(PloneTestCase):
layer = DiscussionLayer
def afterSetUp(self):
self.loginAsPortalOwner()
typetool = self.portal.portal_types
typetool.constructContent('Document', self.portal, 'doc1')
self.portal_discussion = getToolByName(self.portal,
'portal_discussion',
None)
self.membership_tool = getToolByName(self.folder,
'portal_membership')
self.memberdata = self.portal.portal_memberdata
self.request = self.app.REQUEST
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
def test_retract(self):
self.request = self.app.REQUEST
self.context = self.portal
self.request.set('form.select.BulkAction', 'retract')
view = BulkActionsView(self.context, self.request)
self.assertRaises(NotImplementedError,
view.retract)
def test_publish(self):
self.request = self.app.REQUEST
self.context = self.portal
self.request.set('form.select.BulkAction', 'publish')
self.request.set('paths', [])
view = BulkActionsView(self.context, self.request)
def test_mark_as_spam(self):
self.request = self.app.REQUEST
self.context = self.portal
self.request.set('form.select.BulkAction', 'mark_as_spam')
view = BulkActionsView(self.context, self.request)
self.assertRaises(NotImplementedError,
view.mark_as_spam)
def test_delete(self):
self.request = self.app.REQUEST
self.context = self.app
# Initially we have three comments
self.assertEquals(self.conversation.total_comments, 3)
# Delete two comments with bulk actions
self.request.set('form.select.BulkAction', 'delete')
self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath()),
'/'.join(self.comment3.getPhysicalPath())])
view = BulkActionsView(self.context, self.request)
view()
# Make sure that the two comments have been deleted
self.assertEquals(self.conversation.total_comments, 1)
comment = self.conversation.getComments().next()
self.failUnless(comment)
self.assertEquals(comment.title, 'Comment 2')
def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__)