Use plone.app.testing in test_workflow.
svn path=/plone.app.discussion/trunk/; revision=48902
This commit is contained in:
parent
41f5afa8b9
commit
fc59094cb2
@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""Test plone.app.discussion workflow and permissions.
|
"""Test plone.app.discussion workflow and permissions.
|
||||||
"""
|
"""
|
||||||
import unittest
|
import unittest2 as unittest
|
||||||
|
|
||||||
from zope.component import createObject
|
from zope.component import createObject
|
||||||
|
|
||||||
@ -12,21 +12,24 @@ from AccessControl import Unauthorized
|
|||||||
from Products.CMFCore.utils import _checkPermission as checkPerm
|
from Products.CMFCore.utils import _checkPermission as checkPerm
|
||||||
from Products.CMFCore.permissions import View
|
from Products.CMFCore.permissions import View
|
||||||
|
|
||||||
from Products.PloneTestCase.ptc import PloneTestCase
|
from plone.app.testing import TEST_USER_ID, setRoles
|
||||||
|
from plone.app.testing import logout, login
|
||||||
|
|
||||||
from plone.app.discussion.tests.layer import DiscussionLayer
|
from plone.app.discussion.testing import PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
||||||
from plone.app.discussion.interfaces import IConversation, IDiscussionLayer
|
from plone.app.discussion.interfaces import IConversation, IDiscussionLayer
|
||||||
|
|
||||||
|
|
||||||
class WorkflowSetupTest(PloneTestCase):
|
class WorkflowSetupTest(unittest.TestCase):
|
||||||
"""Make sure the workflows are set up properly.
|
"""Make sure the workflows are set up properly.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
layer = DiscussionLayer
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
||||||
|
|
||||||
def afterSetUp(self):
|
def setUp(self):
|
||||||
"""Create a document and allow discussion.
|
self.portal = self.layer['portal']
|
||||||
"""
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
||||||
|
self.portal.invokeFactory('Folder', 'test-folder')
|
||||||
|
self.folder = self.portal['test-folder']
|
||||||
self.portal.portal_types['Document'].allow_discussion = True
|
self.portal.portal_types['Document'].allow_discussion = True
|
||||||
self.portal_discussion = self.portal.portal_discussion
|
self.portal_discussion = self.portal.portal_discussion
|
||||||
self.folder.invokeFactory('Document', 'doc1')
|
self.folder.invokeFactory('Document', 'doc1')
|
||||||
@ -50,24 +53,25 @@ class WorkflowSetupTest(PloneTestCase):
|
|||||||
def test_review_comments_permission(self):
|
def test_review_comments_permission(self):
|
||||||
#'Review comments' in self.portal.permissionsOfRole('Admin')
|
#'Review comments' in self.portal.permissionsOfRole('Admin')
|
||||||
|
|
||||||
self.setRoles(('Reviewer',))
|
setRoles(self.portal, TEST_USER_ID, ['Reviewer'])
|
||||||
self.assertTrue(self.portal.portal_membership.checkPermission(
|
self.assertTrue(self.portal.portal_membership.checkPermission(
|
||||||
'Review comments', self.folder), self.folder)
|
'Review comments', self.folder), self.folder)
|
||||||
self.setRoles(('Member',))
|
setRoles(self.portal, TEST_USER_ID, ['Member'])
|
||||||
self.assertFalse(self.portal.portal_membership.checkPermission(
|
self.assertFalse(self.portal.portal_membership.checkPermission(
|
||||||
'Review comments', self.folder), self.folder)
|
'Review comments', self.folder), self.folder)
|
||||||
|
|
||||||
def test_reply_to_item_permission(self):
|
def test_reply_to_item_permission(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class PermissionsSetupTest(PloneTestCase):
|
class PermissionsSetupTest(unittest.TestCase):
|
||||||
"""Make sure the permissions are set up properly.
|
"""Make sure the permissions are set up properly.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
layer = DiscussionLayer
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
||||||
|
|
||||||
def afterSetUp(self):
|
def setUp(self):
|
||||||
portal = self.portal
|
self.portal = self.layer['portal']
|
||||||
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
||||||
mtool = self.portal.portal_membership
|
mtool = self.portal.portal_membership
|
||||||
self.checkPermission = mtool.checkPermission
|
self.checkPermission = mtool.checkPermission
|
||||||
|
|
||||||
@ -81,25 +85,27 @@ class PermissionsSetupTest(PloneTestCase):
|
|||||||
# should be allowed as Member
|
# should be allowed as Member
|
||||||
self.assertTrue(self.checkPermission(ReplyToItemPerm, self.portal))
|
self.assertTrue(self.checkPermission(ReplyToItemPerm, self.portal))
|
||||||
# should be allowed as Authenticated
|
# should be allowed as Authenticated
|
||||||
self.setRoles(['Authenticated'])
|
setRoles(self.portal, TEST_USER_ID, ['Authenticated'])
|
||||||
self.assertTrue(self.checkPermission(ReplyToItemPerm, self.portal))
|
self.assertTrue(self.checkPermission(ReplyToItemPerm, self.portal))
|
||||||
# should be allowed as Manager
|
# should be allowed as Manager
|
||||||
self.setRoles(['Manager'])
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
||||||
self.assertTrue(self.checkPermission(ReplyToItemPerm, self.portal))
|
self.assertTrue(self.checkPermission(ReplyToItemPerm, self.portal))
|
||||||
# should not be allowed as anonymous
|
# should not be allowed as anonymous
|
||||||
self.logout()
|
logout()
|
||||||
self.assertFalse(self.checkPermission(ReplyToItemPerm, self.portal))
|
self.assertFalse(self.checkPermission(ReplyToItemPerm, self.portal))
|
||||||
|
|
||||||
|
|
||||||
class CommentOneStateWorkflowTest(PloneTestCase):
|
class CommentOneStateWorkflowTest(unittest.TestCase):
|
||||||
"""Test the one_state_workflow that ships with plone.app.discussion.
|
"""Test the one_state_workflow that ships with plone.app.discussion.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
layer = DiscussionLayer
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
||||||
|
|
||||||
def afterSetUp(self):
|
def setUp(self):
|
||||||
"""Create a document with comments and enable the one.
|
self.portal = self.layer['portal']
|
||||||
"""
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
||||||
|
self.portal.invokeFactory('Folder', 'test-folder')
|
||||||
|
self.folder = self.portal['test-folder']
|
||||||
self.catalog = self.portal.portal_catalog
|
self.catalog = self.portal.portal_catalog
|
||||||
self.workflow = self.portal.portal_workflow
|
self.workflow = self.portal.portal_workflow
|
||||||
self.workflow.setChainForPortalTypes(['Document'],
|
self.workflow.setChainForPortalTypes(['Document'],
|
||||||
@ -135,31 +141,34 @@ class CommentOneStateWorkflowTest(PloneTestCase):
|
|||||||
#self.login(default_user)
|
#self.login(default_user)
|
||||||
#self.assertTrue(checkPerm(View, self.doc))
|
#self.assertTrue(checkPerm(View, self.doc))
|
||||||
# Member is allowed
|
# Member is allowed
|
||||||
self.login('member')
|
login(self.portal, 'member')
|
||||||
self.assertTrue(checkPerm(View, self.comment))
|
self.assertTrue(checkPerm(View, self.comment))
|
||||||
# Reviewer is allowed
|
# Reviewer is allowed
|
||||||
self.login('reviewer')
|
login(self.portal, 'reviewer')
|
||||||
self.assertTrue(checkPerm(View, self.comment))
|
self.assertTrue(checkPerm(View, self.comment))
|
||||||
# Anonymous is allowed
|
# Anonymous is allowed
|
||||||
self.logout()
|
logout()
|
||||||
self.assertTrue(checkPerm(View, self.comment))
|
self.assertTrue(checkPerm(View, self.comment))
|
||||||
# Editor is allowed
|
# Editor is allowed
|
||||||
self.login('editor')
|
login(self.portal, 'editor')
|
||||||
self.assertTrue(checkPerm(View, self.comment))
|
self.assertTrue(checkPerm(View, self.comment))
|
||||||
# Reader is allowed
|
# Reader is allowed
|
||||||
self.login('reader')
|
login(self.portal, 'reader')
|
||||||
self.assertTrue(checkPerm(View, self.comment))
|
self.assertTrue(checkPerm(View, self.comment))
|
||||||
|
|
||||||
|
|
||||||
class CommentReviewWorkflowTest(PloneTestCase):
|
class CommentReviewWorkflowTest(unittest.TestCase):
|
||||||
"""Test the comment_review_workflow that ships with plone.app.discussion.
|
"""Test the comment_review_workflow that ships with plone.app.discussion.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
layer = DiscussionLayer
|
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
||||||
|
|
||||||
def afterSetUp(self):
|
|
||||||
# Allow discussion and
|
def setUp(self):
|
||||||
self.loginAsPortalOwner()
|
self.portal = self.layer['portal']
|
||||||
|
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
||||||
|
self.portal.invokeFactory('Folder', 'test-folder')
|
||||||
|
self.folder = self.portal['test-folder']
|
||||||
|
|
||||||
# Allow discussion on the Document content type
|
# Allow discussion on the Document content type
|
||||||
self.portal.portal_types['Document'].allow_discussion = True
|
self.portal.portal_types['Document'].allow_discussion = True
|
||||||
@ -186,7 +195,7 @@ class CommentReviewWorkflowTest(PloneTestCase):
|
|||||||
self.comment_id = comment_id
|
self.comment_id = comment_id
|
||||||
self.comment = comment
|
self.comment = comment
|
||||||
|
|
||||||
self.setRoles(('Reviewer',))
|
setRoles(self.portal, TEST_USER_ID, ['Reviewer'])
|
||||||
alsoProvides(self.portal.REQUEST, IDiscussionLayer)
|
alsoProvides(self.portal.REQUEST, IDiscussionLayer)
|
||||||
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
@ -197,7 +206,7 @@ class CommentReviewWorkflowTest(PloneTestCase):
|
|||||||
|
|
||||||
def test_delete_as_anonymous(self):
|
def test_delete_as_anonymous(self):
|
||||||
# Make sure that anonymous users can not delete comments
|
# Make sure that anonymous users can not delete comments
|
||||||
self.logout()
|
logout()
|
||||||
self.portal.REQUEST.form['comment_id'] = self.comment_id
|
self.portal.REQUEST.form['comment_id'] = self.comment_id
|
||||||
self.assertRaises(Unauthorized,
|
self.assertRaises(Unauthorized,
|
||||||
self.comment.restrictedTraverse,
|
self.comment.restrictedTraverse,
|
||||||
@ -206,8 +215,8 @@ class CommentReviewWorkflowTest(PloneTestCase):
|
|||||||
|
|
||||||
def test_delete_as_user(self):
|
def test_delete_as_user(self):
|
||||||
# Make sure that members can not delete comments
|
# Make sure that members can not delete comments
|
||||||
self.logout()
|
logout()
|
||||||
self.setRoles(('Member',))
|
setRoles(self.portal, TEST_USER_ID, ['Member'])
|
||||||
self.portal.REQUEST.form['comment_id'] = self.comment_id
|
self.portal.REQUEST.form['comment_id'] = self.comment_id
|
||||||
self.assertRaises(Unauthorized,
|
self.assertRaises(Unauthorized,
|
||||||
self.comment.restrictedTraverse,
|
self.comment.restrictedTraverse,
|
||||||
@ -226,7 +235,7 @@ class CommentReviewWorkflowTest(PloneTestCase):
|
|||||||
getInfoFor(self.comment, 'review_state'))
|
getInfoFor(self.comment, 'review_state'))
|
||||||
|
|
||||||
def test_publish_as_anonymous(self):
|
def test_publish_as_anonymous(self):
|
||||||
self.logout()
|
logout()
|
||||||
self.portal.REQUEST.form['comment_id'] = self.comment_id
|
self.portal.REQUEST.form['comment_id'] = self.comment_id
|
||||||
self.portal.REQUEST.form['workflow_action'] = 'publish'
|
self.portal.REQUEST.form['workflow_action'] = 'publish'
|
||||||
self.assertEqual('pending', self.portal.portal_workflow.\
|
self.assertEqual('pending', self.portal.portal_workflow.\
|
||||||
|
Loading…
Reference in New Issue
Block a user