Use plone.app.testing in test_moderation_view.

svn path=/plone.app.discussion/trunk/; revision=48915
This commit is contained in:
Timo Stollenwerk 2011-04-17 08:50:34 +00:00
parent d66328a26a
commit f3d97b2f20

View File

@ -8,27 +8,36 @@ from zope.component import createObject
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from Products.PloneTestCase.ptc import PloneTestCase from Products.PloneTestCase.ptc import PloneTestCase
from plone.app.testing import TEST_USER_ID, setRoles
from plone.app.discussion.testing import\
PLONE_APP_DISCUSSION_INTEGRATION_TESTING
from plone.app.discussion.browser.moderation import View from plone.app.discussion.browser.moderation import View
from plone.app.discussion.browser.moderation import BulkActionsView from plone.app.discussion.browser.moderation import BulkActionsView
from plone.app.discussion.interfaces import IConversation from plone.app.discussion.interfaces import IConversation
from plone.app.discussion.tests.layer import DiscussionLayer
class ModerationViewTest(PloneTestCase): class ModerationViewTest(unittest.TestCase):
layer = DiscussionLayer layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
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'])
def afterSetUp(self):
self.loginAsPortalOwner()
typetool = self.portal.portal_types typetool = self.portal.portal_types
typetool.constructContent('Document', self.portal, 'doc1') typetool.constructContent('Document', self.portal, 'doc1')
self.portal_discussion = getToolByName(self.portal, self.portal_discussion = getToolByName(self.portal,
'portal_discussion', 'portal_discussion',
None) None)
self.membership_tool = getToolByName(self.folder, self.membership_tool = getToolByName(self.portal,
'portal_membership') 'portal_membership')
self.memberdata = self.portal.portal_memberdata self.memberdata = self.portal.portal_memberdata
request = self.app.REQUEST request = self.app.REQUEST
context = getattr(self.portal, 'doc1') context = getattr(self.portal, 'doc1')
self.view = View(context, request) self.view = View(context, request)
@ -37,34 +46,6 @@ class ModerationViewTest(PloneTestCase):
('Discussion Item',), 'comment_review_workflow') ('Discussion Item',), 'comment_review_workflow')
self.wf_tool = self.portal.portal_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)
def test_moderation_enabled(self): def test_moderation_enabled(self):
"""Make sure that moderation_enabled returns true if the comment """Make sure that moderation_enabled returns true if the comment
workflow implements a 'pending' state. workflow implements a 'pending' state.
@ -79,9 +60,6 @@ class ModerationViewTest(PloneTestCase):
self.assertEqual(self.view.moderation_enabled(), True) self.assertEqual(self.view.moderation_enabled(), True)
def test_old_comments_not_shown_in_moderation_view(self): def test_old_comments_not_shown_in_moderation_view(self):
# Create an old comment and make sure it is not shown
# in the moderation view.
# Create old comment # Create old comment
discussion = getToolByName(self.portal, 'portal_discussion', None) discussion = getToolByName(self.portal, 'portal_discussion', None)
discussion.overrideDiscussionFor(self.portal.doc1, 1) discussion.overrideDiscussionFor(self.portal.doc1, 1)
@ -97,24 +75,26 @@ class ModerationViewTest(PloneTestCase):
self.assertEqual(talkback.replyCount(self.portal.doc1), 1) self.assertEqual(talkback.replyCount(self.portal.doc1), 1)
self.assertEqual(reply.inReplyTo(), self.portal.doc1) self.assertEqual(reply.inReplyTo(), self.portal.doc1)
# Make sure only the two new comments are shown view = self.view()
self.view()
self.assertEqual(len(self.view.comments), 3) self.assertTrue('No comments to moderate' in view)
self.assertEqual(len(self.view.comments), 0)
class ModerationBulkActionsViewTest(PloneTestCase): class ModerationBulkActionsViewTest(unittest.TestCase):
layer = DiscussionLayer layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
def afterSetUp(self): def setUp(self):
self.loginAsPortalOwner() self.app = self.layer['app']
self.portal = self.layer['portal']
self.request = self.layer['request']
setRoles(self.portal, TEST_USER_ID, ['Manager'])
typetool = self.portal.portal_types typetool = self.portal.portal_types
typetool.constructContent('Document', self.portal, 'doc1') typetool.constructContent('Document', self.portal, 'doc1')
self.wf = getToolByName(self.portal, self.wf = getToolByName(self.portal,
'portal_workflow', 'portal_workflow',
None) None)
self.request = self.app.REQUEST
self.context = self.portal self.context = self.portal
self.portal.portal_workflow.setChainForPortalTypes( self.portal.portal_workflow.setChainForPortalTypes(
('Discussion Item',), 'comment_review_workflow') ('Discussion Item',), 'comment_review_workflow')
@ -152,29 +132,23 @@ class ModerationBulkActionsViewTest(PloneTestCase):
def test_default_bulkaction(self): def test_default_bulkaction(self):
# Make sure no error is raised when no bulk actions has been supplied # Make sure no error is raised when no bulk actions has been supplied
self.request = self.app.REQUEST
self.context = self.portal
self.request.set('form.select.BulkAction', '-1') self.request.set('form.select.BulkAction', '-1')
self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())]) self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())])
view = BulkActionsView(self.context, self.request) view = BulkActionsView(self.portal, self.request)
self.assertFalse(view()) self.assertFalse(view())
def test_retract(self): def test_retract(self):
self.request = self.app.REQUEST
self.context = self.portal
self.request.set('form.select.BulkAction', 'retract') self.request.set('form.select.BulkAction', 'retract')
self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())]) self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())])
view = BulkActionsView(self.context, self.request) view = BulkActionsView(self.portal, self.request)
self.assertRaises(NotImplementedError, self.assertRaises(NotImplementedError,
view) view)
def test_publish(self): def test_publish(self):
self.request = self.app.REQUEST
self.context = self.portal
self.request.set('form.select.BulkAction', 'publish') self.request.set('form.select.BulkAction', 'publish')
self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())]) self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())])
view = BulkActionsView(self.context, self.request) view = BulkActionsView(self.portal, self.request)
view() view()
# Count published comments # Count published comments
@ -189,19 +163,15 @@ class ModerationBulkActionsViewTest(PloneTestCase):
self.assertEqual(published_comments, 1) self.assertEqual(published_comments, 1)
def test_mark_as_spam(self): def test_mark_as_spam(self):
self.request = self.app.REQUEST
self.context = self.portal
self.request.set('form.select.BulkAction', 'mark_as_spam') self.request.set('form.select.BulkAction', 'mark_as_spam')
self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())]) self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath())])
view = BulkActionsView(self.context, self.request)
view = BulkActionsView(self.portal, self.request)
self.assertRaises(NotImplementedError, self.assertRaises(NotImplementedError,
view) view)
def test_delete(self): def test_delete(self):
self.request = self.app.REQUEST
self.context = self.app
# Initially we have three comments # Initially we have three comments
self.assertEqual(self.conversation.total_comments, 3) self.assertEqual(self.conversation.total_comments, 3)
@ -209,7 +179,7 @@ class ModerationBulkActionsViewTest(PloneTestCase):
self.request.set('form.select.BulkAction', 'delete') self.request.set('form.select.BulkAction', 'delete')
self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath()), self.request.set('paths', ['/'.join(self.comment1.getPhysicalPath()),
'/'.join(self.comment3.getPhysicalPath())]) '/'.join(self.comment3.getPhysicalPath())])
view = BulkActionsView(self.context, self.request) view = BulkActionsView(self.app, self.request)
view() view()
# Make sure that the two comments have been deleted # Make sure that the two comments have been deleted