Make pylint happy.
svn path=/plone.app.discussion/trunk/; revision=39287
This commit is contained in:
parent
0f9c98ec97
commit
435040e0b2
@ -1,3 +1,5 @@
|
||||
"""Test the plone.app.discussion catalog indexes
|
||||
"""
|
||||
import unittest
|
||||
|
||||
from datetime import datetime
|
||||
@ -17,10 +19,14 @@ class CatalogSetupTest(PloneTestCase):
|
||||
layer = DiscussionLayer
|
||||
|
||||
def test_catalog_installed(self):
|
||||
self.failUnless('total_comments' in self.portal.portal_catalog.indexes())
|
||||
self.failUnless('commentators' in self.portal.portal_catalog.indexes())
|
||||
self.failUnless('total_comments' in self.portal.portal_catalog.schema())
|
||||
self.failUnless('in_response_to' in self.portal.portal_catalog.schema())
|
||||
self.failUnless('total_comments' in
|
||||
self.portal.portal_catalog.indexes())
|
||||
self.failUnless('commentators' in
|
||||
self.portal.portal_catalog.indexes())
|
||||
self.failUnless('total_comments' in
|
||||
self.portal.portal_catalog.schema())
|
||||
self.failUnless('in_response_to' in
|
||||
self.portal.portal_catalog.schema())
|
||||
|
||||
def test_collection_criteria_installed(self):
|
||||
try:
|
||||
@ -30,6 +36,7 @@ class CatalogSetupTest(PloneTestCase):
|
||||
except AttributeError:
|
||||
self.fail()
|
||||
|
||||
|
||||
class ConversationCatalogTest(PloneTestCase):
|
||||
|
||||
layer = DiscussionLayer
|
||||
@ -56,7 +63,8 @@ class ConversationCatalogTest(PloneTestCase):
|
||||
self.comment_id = new_comment1_id
|
||||
|
||||
brains = self.catalog.searchResults(
|
||||
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
path = {'query' :
|
||||
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
portal_type = "Document"
|
||||
)
|
||||
self.conversation = conversation
|
||||
@ -75,10 +83,12 @@ class ConversationCatalogTest(PloneTestCase):
|
||||
comment2.creator = 'Emma'
|
||||
new_comment2_id = self.conversation.addComment(comment2)
|
||||
|
||||
comment2 = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_comment2_id)
|
||||
comment2 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_comment2_id)
|
||||
comment2.reindexObject()
|
||||
brains = self.catalog.searchResults(
|
||||
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
path = {'query' :
|
||||
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
portal_type = "Document"
|
||||
)
|
||||
doc1_brain = brains[0]
|
||||
@ -86,7 +96,8 @@ class ConversationCatalogTest(PloneTestCase):
|
||||
|
||||
def test_last_comment_date(self):
|
||||
self.failUnless(self.doc1_brain.has_key('last_comment_date'))
|
||||
self.assertEquals(self.doc1_brain.last_comment_date, datetime(2006, 9, 17, 14, 18, 12))
|
||||
self.assertEquals(self.doc1_brain.last_comment_date,
|
||||
datetime(2006, 9, 17, 14, 18, 12))
|
||||
|
||||
# Add another comment and check if last comment date is updated.
|
||||
comment2 = createObject('plone.Comment')
|
||||
@ -97,30 +108,36 @@ class ConversationCatalogTest(PloneTestCase):
|
||||
comment2.modification_date = datetime(2009, 9, 17, 14, 18, 12)
|
||||
new_comment2_id = self.conversation.addComment(comment2)
|
||||
|
||||
comment2 = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_comment2_id)
|
||||
comment2 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_comment2_id)
|
||||
comment2.reindexObject()
|
||||
brains = self.catalog.searchResults(
|
||||
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
path = {'query' :
|
||||
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
portal_type = "Document"
|
||||
)
|
||||
doc1_brain = brains[0]
|
||||
self.assertEquals(doc1_brain.last_comment_date, datetime(2009, 9, 17, 14, 18, 12))
|
||||
self.assertEquals(doc1_brain.last_comment_date,
|
||||
datetime(2009, 9, 17, 14, 18, 12))
|
||||
|
||||
# Remove the comment again
|
||||
del self.conversation[new_comment2_id]
|
||||
|
||||
brains = self.catalog.searchResults(
|
||||
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
path = {'query' :
|
||||
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
portal_type = "Document"
|
||||
)
|
||||
doc1_brain = brains[0]
|
||||
|
||||
self.assertEquals(doc1_brain.last_comment_date, datetime(2006, 9, 17, 14, 18, 12))
|
||||
self.assertEquals(doc1_brain.last_comment_date,
|
||||
datetime(2006, 9, 17, 14, 18, 12))
|
||||
|
||||
# remove all comments
|
||||
del self.conversation[self.new_comment1_id]
|
||||
brains = self.catalog.searchResults(
|
||||
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
path = {'query' :
|
||||
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
portal_type = "Document"
|
||||
)
|
||||
doc1_brain = brains[0]
|
||||
@ -138,11 +155,13 @@ class ConversationCatalogTest(PloneTestCase):
|
||||
comment2.author_username = 'Emma'
|
||||
new_comment2_id = self.conversation.addComment(comment2)
|
||||
|
||||
comment2 = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_comment2_id)
|
||||
comment2 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_comment2_id)
|
||||
comment2.reindexObject()
|
||||
|
||||
brains = self.catalog.searchResults(
|
||||
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
path = {'query' :
|
||||
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
portal_type = "Document"
|
||||
)
|
||||
doc1_brain = brains[0]
|
||||
@ -152,7 +171,8 @@ class ConversationCatalogTest(PloneTestCase):
|
||||
# remove one comments
|
||||
del self.conversation[new_comment2_id]
|
||||
brains = self.catalog.searchResults(
|
||||
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
path = {'query' :
|
||||
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
portal_type = "Document"
|
||||
)
|
||||
doc1_brain = brains[0]
|
||||
@ -161,7 +181,8 @@ class ConversationCatalogTest(PloneTestCase):
|
||||
# remove all comments
|
||||
del self.conversation[self.new_comment1_id]
|
||||
brains = self.catalog.searchResults(
|
||||
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
path = {'query' :
|
||||
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
portal_type = "Document"
|
||||
)
|
||||
doc1_brain = brains[0]
|
||||
@ -169,7 +190,8 @@ class ConversationCatalogTest(PloneTestCase):
|
||||
|
||||
def test_conversation_indexes_not_in_comments(self):
|
||||
brains = self.catalog.searchResults(
|
||||
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
path = {'query' :
|
||||
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
portal_type = "Discussion Item"
|
||||
)
|
||||
comment1_brain = brains[0]
|
||||
@ -201,10 +223,12 @@ class CommentCatalogTest(PloneTestCase):
|
||||
new_comment1_id = conversation.addComment(comment1)
|
||||
self.comment_id = new_comment1_id
|
||||
|
||||
self.comment = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_comment1_id)
|
||||
self.comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_comment1_id)
|
||||
|
||||
brains = self.catalog.searchResults(
|
||||
path = {'query' : '/'.join(self.comment.getPhysicalPath()) })
|
||||
path = {'query' :
|
||||
'/'.join(self.comment.getPhysicalPath()) })
|
||||
self.comment_brain = brains[0]
|
||||
|
||||
def test_title(self):
|
||||
@ -234,7 +258,8 @@ class CommentCatalogTest(PloneTestCase):
|
||||
# deleted.
|
||||
del self.conversation[self.comment_id]
|
||||
brains = self.catalog.searchResults(
|
||||
path = {'query' : '/'.join(self.comment.getPhysicalPath()) })
|
||||
path = {'query' :
|
||||
'/'.join(self.comment.getPhysicalPath()) })
|
||||
self.assertEquals(len(brains), 0)
|
||||
|
||||
def test_remove_comments_when_content_object_is_removed(self):
|
||||
|
@ -46,7 +46,8 @@ class CommentTest(PloneTestCase):
|
||||
self.assertEquals(comment1.Type(), 'Comment')
|
||||
|
||||
def test_traversal(self):
|
||||
# make sure comments are traversable, have an id, absolute_url and physical path
|
||||
# make sure comments are traversable, have an id, absolute_url and
|
||||
# physical path
|
||||
|
||||
conversation = IConversation(self.portal.doc1)
|
||||
|
||||
@ -56,15 +57,20 @@ class CommentTest(PloneTestCase):
|
||||
|
||||
new_comment1_id = conversation.addComment(comment1)
|
||||
|
||||
comment = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_comment1_id)
|
||||
comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_comment1_id)
|
||||
self.assert_(IComment.providedBy(comment))
|
||||
self.assertEquals('Comment 1', comment.title)
|
||||
|
||||
self.assertEquals(('', 'plone', 'doc1', '++conversation++default', str(new_comment1_id)), comment.getPhysicalPath())
|
||||
self.assertEquals('http://nohost/plone/doc1/++conversation++default/' + str(new_comment1_id), comment.absolute_url())
|
||||
self.assertEquals(('', 'plone', 'doc1', '++conversation++default',
|
||||
str(new_comment1_id)), comment.getPhysicalPath())
|
||||
self.assertEquals('http://nohost/plone/doc1/++conversation++default/' +
|
||||
str(new_comment1_id), comment.absolute_url())
|
||||
|
||||
def test_workflow(self):
|
||||
self.portal.portal_workflow.setChainForPortalTypes(('Discussion Item',), ('simple_publication_workflow,'))
|
||||
self.portal.portal_workflow.setChainForPortalTypes(
|
||||
('Discussion Item',),
|
||||
('simple_publication_workflow,'))
|
||||
|
||||
conversation = IConversation(self.portal.doc1)
|
||||
comment1 = createObject('plone.Comment')
|
||||
@ -76,10 +82,14 @@ class CommentTest(PloneTestCase):
|
||||
self.assertEquals(('simple_publication_workflow',), chain)
|
||||
|
||||
# ensure the initial state was entered and recorded
|
||||
self.assertEquals(1, len(comment.workflow_history['simple_publication_workflow']))
|
||||
self.assertEquals(None, comment.workflow_history['simple_publication_workflow'][0]['action'])
|
||||
self.assertEquals(1,
|
||||
len(comment.workflow_history['simple_publication_workflow']))
|
||||
self.assertEquals(None,
|
||||
comment.workflow_history['simple_publication_workflow'][0]\
|
||||
['action'])
|
||||
|
||||
self.assertEquals('private', self.portal.portal_workflow.getInfoFor(comment, 'review_state'))
|
||||
self.assertEquals('private',
|
||||
self.portal.portal_workflow.getInfoFor(comment, 'review_state'))
|
||||
|
||||
def test_fti(self):
|
||||
# test that we can look up an FTI for Discussion Item
|
||||
@ -92,7 +102,8 @@ class CommentTest(PloneTestCase):
|
||||
self.assertEquals('Discussion Item', fti.getTypeInfo(comment1).getId())
|
||||
|
||||
def test_view(self):
|
||||
# make sure that the comment view is there and redirects to the right URL
|
||||
# make sure that the comment view is there and redirects to the right
|
||||
# URL
|
||||
|
||||
# Create a conversation. In this case we doesn't assign it to an
|
||||
# object, as we just want to check the Conversation object API.
|
||||
@ -106,10 +117,12 @@ class CommentTest(PloneTestCase):
|
||||
# Add comment to the conversation
|
||||
new_comment1_id = conversation.addComment(comment1)
|
||||
|
||||
comment = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_comment1_id)
|
||||
comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_comment1_id)
|
||||
|
||||
# make sure the view is there
|
||||
self.failUnless(getMultiAdapter((comment, self.app.REQUEST), name='view'))
|
||||
self.failUnless(getMultiAdapter((comment, self.app.REQUEST),
|
||||
name='view'))
|
||||
|
||||
# TODO: is this correct? Redirect ist 301
|
||||
self.assertEquals(200, self.app.REQUEST.response.getStatus())
|
||||
@ -140,7 +153,8 @@ class RepliesTest(PloneTestCase):
|
||||
comment.title = 'Comment 1'
|
||||
comment.text = 'Comment text'
|
||||
new_id = replies.addComment(comment)
|
||||
comment = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_id)
|
||||
comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id)
|
||||
|
||||
# Add a reply to the CommentReplies adapter of the first comment
|
||||
re_comment = createObject('plone.Comment')
|
||||
@ -177,7 +191,8 @@ class RepliesTest(PloneTestCase):
|
||||
comment.title = 'Comment 1'
|
||||
comment.text = 'Comment text'
|
||||
new_id = replies.addComment(comment)
|
||||
comment = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_id)
|
||||
comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id)
|
||||
|
||||
# Add a reply to the CommentReplies adapter of the first comment
|
||||
re_comment = createObject('plone.Comment')
|
||||
@ -200,7 +215,8 @@ class RepliesTest(PloneTestCase):
|
||||
def test_traversal(self):
|
||||
# Create a nested structure of comment replies and check the traversal
|
||||
|
||||
# make sure comments are traversable, have an id, absolute_url and physical path
|
||||
# make sure comments are traversable, have an id, absolute_url and
|
||||
# physical path
|
||||
conversation = IConversation(self.portal.doc1)
|
||||
|
||||
comment1 = createObject('plone.Comment')
|
||||
@ -213,7 +229,8 @@ class RepliesTest(PloneTestCase):
|
||||
comment.title = 'Comment 1'
|
||||
comment.text = 'Comment text'
|
||||
new_id = conversation.addComment(comment)
|
||||
comment = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_id)
|
||||
comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id)
|
||||
|
||||
# Add a reply to the CommentReplies adapter of the first comment
|
||||
re_comment = createObject('plone.Comment')
|
||||
@ -221,7 +238,8 @@ class RepliesTest(PloneTestCase):
|
||||
re_comment.text = 'Comment text'
|
||||
replies = IReplies(comment)
|
||||
new_re_id = replies.addComment(re_comment)
|
||||
re_comment = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_re_id)
|
||||
re_comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_re_id)
|
||||
|
||||
# Add a reply to the reply
|
||||
re_re_comment = createObject('plone.Comment')
|
||||
@ -229,7 +247,8 @@ class RepliesTest(PloneTestCase):
|
||||
re_re_comment.text = 'Comment text'
|
||||
replies = IReplies(re_comment)
|
||||
new_re_re_id = replies.addComment(re_re_comment)
|
||||
re_re_comment = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_re_re_id)
|
||||
re_re_comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_re_re_id)
|
||||
|
||||
# Add a reply to the replies reply
|
||||
re_re_re_comment = createObject('plone.Comment')
|
||||
@ -237,16 +256,27 @@ class RepliesTest(PloneTestCase):
|
||||
re_re_re_comment.text = 'Comment text'
|
||||
replies = IReplies(re_re_comment)
|
||||
new_re_re_re_id = replies.addComment(re_re_re_comment)
|
||||
re_re_re_comment = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_re_re_re_id)
|
||||
re_re_re_comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_re_re_re_id)
|
||||
|
||||
self.assertEquals(('', 'plone', 'doc1', '++conversation++default', str(new_id)), comment.getPhysicalPath())
|
||||
self.assertEquals('http://nohost/plone/doc1/++conversation++default/' + str(new_id), comment.absolute_url())
|
||||
self.assertEquals(('', 'plone', 'doc1', '++conversation++default', str(new_re_id)), re_comment.getPhysicalPath())
|
||||
self.assertEquals('http://nohost/plone/doc1/++conversation++default/' + str(new_re_id), re_comment.absolute_url())
|
||||
self.assertEquals(('', 'plone', 'doc1', '++conversation++default', str(new_re_re_id)), re_re_comment.getPhysicalPath())
|
||||
self.assertEquals('http://nohost/plone/doc1/++conversation++default/' + str(new_re_re_id), re_re_comment.absolute_url())
|
||||
self.assertEquals(('', 'plone', 'doc1', '++conversation++default', str(new_re_re_re_id)), re_re_re_comment.getPhysicalPath())
|
||||
self.assertEquals('http://nohost/plone/doc1/++conversation++default/' + str(new_re_re_re_id), re_re_re_comment.absolute_url())
|
||||
self.assertEquals(('', 'plone', 'doc1', '++conversation++default',
|
||||
str(new_id)), comment.getPhysicalPath())
|
||||
self.assertEquals('http://nohost/plone/doc1/++conversation++default/' +
|
||||
str(new_id), comment.absolute_url())
|
||||
self.assertEquals(('', 'plone', 'doc1', '++conversation++default',
|
||||
str(new_re_id)), re_comment.getPhysicalPath())
|
||||
self.assertEquals('http://nohost/plone/doc1/++conversation++default/' +
|
||||
str(new_re_id), re_comment.absolute_url())
|
||||
self.assertEquals(('', 'plone', 'doc1', '++conversation++default',
|
||||
str(new_re_re_id)), re_re_comment.getPhysicalPath())
|
||||
self.assertEquals('http://nohost/plone/doc1/++conversation++default/' +
|
||||
str(new_re_re_id), re_re_comment.absolute_url())
|
||||
self.assertEquals(('', 'plone', 'doc1', '++conversation++default',
|
||||
str(new_re_re_re_id)),
|
||||
re_re_re_comment.getPhysicalPath())
|
||||
self.assertEquals('http://nohost/plone/doc1/++conversation++default/' +
|
||||
str(new_re_re_re_id),
|
||||
re_re_re_comment.absolute_url())
|
||||
|
||||
def test_suite():
|
||||
return unittest.defaultTestLoader.loadTestsFromName(__name__)
|
||||
|
@ -27,7 +27,9 @@ class TestCommentForm(PloneTestCase):
|
||||
self.loginAsPortalOwner()
|
||||
typetool = self.portal.portal_types
|
||||
typetool.constructContent('Document', self.portal, 'doc1')
|
||||
self.portal_discussion = getToolByName(self.portal, 'portal_discussion', None)
|
||||
self.portal_discussion = getToolByName(self.portal,
|
||||
'portal_discussion',
|
||||
None)
|
||||
self.membership_tool = getToolByName(self.folder, 'portal_membership')
|
||||
self.memberdata = self.portal.portal_memberdata
|
||||
request = self.app.REQUEST
|
||||
@ -87,7 +89,8 @@ class TestCommentsViewletIntegration(FunctionalTestCase):
|
||||
# Do not show the old comment viewlet
|
||||
self.failIf('discussion_reply_form' in browser.contents)
|
||||
# Show the new comment viewlet
|
||||
self.failUnless('formfield-form-widgets-in_reply_to' in browser.contents)
|
||||
self.failUnless('formfield-form-widgets-in_reply_to' in
|
||||
browser.contents)
|
||||
self.failUnless('formfield-form-widgets-title' in browser.contents)
|
||||
self.failUnless('formfield-form-widgets-text' in browser.contents)
|
||||
|
||||
@ -100,7 +103,9 @@ class TestCommentsViewlet(PloneTestCase):
|
||||
self.loginAsPortalOwner()
|
||||
typetool = self.portal.portal_types
|
||||
typetool.constructContent('Document', self.portal, 'doc1')
|
||||
self.portal_discussion = getToolByName(self.portal, 'portal_discussion', None)
|
||||
self.portal_discussion = getToolByName(self.portal,
|
||||
'portal_discussion',
|
||||
None)
|
||||
self.membership_tool = getToolByName(self.folder, 'portal_membership')
|
||||
self.memberdata = self.portal.portal_memberdata
|
||||
request = self.app.REQUEST
|
||||
@ -183,9 +188,12 @@ class TestCommentsViewlet(PloneTestCase):
|
||||
comment.text = 'Comment text'
|
||||
conversation = IConversation(self.portal.doc1)
|
||||
c1 = conversation.addComment(comment)
|
||||
self.assertEquals(sum(1 for w in self.viewlet.get_replies(workflow_actions=True)), 1)
|
||||
self.assertEquals(sum(1 for w in
|
||||
self.viewlet.get_replies(workflow_actions=True)),
|
||||
1)
|
||||
# Enable moderation workflow
|
||||
self.portal.portal_workflow.setChainForPortalTypes(('Discussion Item',),
|
||||
self.portal.portal_workflow.setChainForPortalTypes(
|
||||
('Discussion Item',),
|
||||
('simple_publication_workflow,'))
|
||||
# Check if workflow actions are available
|
||||
reply = self.viewlet.get_replies(workflow_actions=True).next()
|
||||
@ -213,9 +221,13 @@ class TestCommentsViewlet(PloneTestCase):
|
||||
|
||||
# Add a user with a member image
|
||||
self.membership_tool.addMember('jim', 'Jim', ['Member'], [])
|
||||
self.memberdata._setPortrait(Image(id='jim', file=dummy.File(), title=''), 'jim')
|
||||
self.assertEqual(self.memberdata._getPortrait('jim').getId(), 'jim')
|
||||
self.assertEqual(self.memberdata._getPortrait('jim').meta_type, 'Image')
|
||||
self.memberdata._setPortrait(Image(id='jim',
|
||||
file=dummy.File(),
|
||||
title=''), 'jim')
|
||||
self.assertEqual(self.memberdata._getPortrait('jim').getId(),
|
||||
'jim')
|
||||
self.assertEqual(self.memberdata._getPortrait('jim').meta_type,
|
||||
'Image')
|
||||
|
||||
# Add a conversation with a comment
|
||||
conversation = IConversation(self.portal.doc1)
|
||||
@ -264,14 +276,16 @@ class TestCommentsViewlet(PloneTestCase):
|
||||
self.failIf(self.viewlet.anonymous_discussion_allowed())
|
||||
# Allow anonymous discussion
|
||||
registry = queryUtility(IRegistry)
|
||||
registry['plone.app.discussion.interfaces.IDiscussionSettings.anonymous_comments'] = True
|
||||
registry['plone.app.discussion.interfaces.IDiscussionSettings.' +
|
||||
'anonymous_comments'] = True
|
||||
# Test if anonymous discussion is allowed for the viewlet
|
||||
self.failUnless(self.viewlet.anonymous_discussion_allowed())
|
||||
|
||||
def test_show_commenter_image(self):
|
||||
self.failUnless(self.viewlet.show_commenter_image())
|
||||
registry = queryUtility(IRegistry)
|
||||
registry['plone.app.discussion.interfaces.IDiscussionSettings.show_commenter_image'] = False
|
||||
registry['plone.app.discussion.interfaces.IDiscussionSettings.' +
|
||||
'show_commenter_image'] = False
|
||||
self.failIf(self.viewlet.show_commenter_image())
|
||||
|
||||
def test_is_anonymous(self):
|
||||
|
@ -38,41 +38,51 @@ class RegistryTest(PloneTestCase):
|
||||
# Check globally_enabled record
|
||||
self.failUnless('globally_enabled' in IDiscussionSettings)
|
||||
self.assertEquals(
|
||||
self.registry['plone.app.discussion.interfaces.IDiscussionSettings.globally_enabled'],
|
||||
self.registry['plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.globally_enabled'],
|
||||
True)
|
||||
|
||||
def test_text_transform(self):
|
||||
self.failUnless('text_transform' in IDiscussionSettings)
|
||||
self.assertEquals(
|
||||
self.registry['plone.app.discussion.interfaces.IDiscussionSettings.text_transform'],
|
||||
self.registry['plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.text_transform'],
|
||||
'text/plain')
|
||||
|
||||
def test_captcha(self):
|
||||
# Check globally_enabled record
|
||||
self.failUnless('captcha' in IDiscussionSettings)
|
||||
self.assertEquals(self.registry['plone.app.discussion.interfaces.IDiscussionSettings.captcha'], 'disabled')
|
||||
self.assertEquals(self.registry['plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.captcha'],
|
||||
'disabled')
|
||||
|
||||
def test_anonymous_comments(self):
|
||||
# Check anonymous_comments record
|
||||
self.failUnless('anonymous_comments' in IDiscussionSettings)
|
||||
self.assertEquals(self.registry['plone.app.discussion.interfaces.IDiscussionSettings.anonymous_comments'], False)
|
||||
self.assertEquals(self.registry['plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.anonymous_comments'], False)
|
||||
|
||||
def test_show_commenter_image(self):
|
||||
# Check show_commenter_image record
|
||||
self.failUnless('show_commenter_image' in IDiscussionSettings)
|
||||
self.assertEquals(self.registry['plone.app.discussion.interfaces.IDiscussionSettings.show_commenter_image'], True)
|
||||
self.assertEquals(self.registry['plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.show_commenter_image'], True)
|
||||
|
||||
def test_moderator_notification_enabled(self):
|
||||
# Check show_commenter_image record
|
||||
self.failUnless('moderator_notification_enabled' in IDiscussionSettings)
|
||||
self.assertEquals(self.registry['plone.app.discussion.interfaces.IDiscussionSettings.moderator_notification_enabled'], False)
|
||||
self.failUnless('moderator_notification_enabled' in
|
||||
IDiscussionSettings)
|
||||
self.assertEquals(self.registry['plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.moderator_notification_enabled'], False)
|
||||
|
||||
#def test_user_notification_enabled(self):
|
||||
# # Check show_commenter_image record
|
||||
# show_commenter_image = self.registry.records['plone.app.discussion.interfaces.IDiscussionSettings.user_notification_enabled']
|
||||
# show_commenter_image = self.registry.records['plone.app.discussion.' +
|
||||
# 'interfaces.IDiscussionSettings.user_notification_enabled']
|
||||
#
|
||||
# self.failUnless('user_notification_enabled' in IDiscussionSettings)
|
||||
# self.assertEquals(self.registry['plone.app.discussion.interfaces.IDiscussionSettings.user_notification_enabled'], False)
|
||||
# self.assertEquals(self.registry['plone.app.discussion.interfaces.' +
|
||||
# 'IDiscussionSettings.user_notification_enabled'], False)
|
||||
|
||||
def test_suite():
|
||||
return unittest.defaultTestLoader.loadTestsFromName(__name__)
|
@ -13,7 +13,11 @@ from Products.CMFCore.utils import getToolByName
|
||||
from Products.PloneTestCase.ptc import PloneTestCase
|
||||
from plone.app.discussion.tests.layer import DiscussionLayer
|
||||
|
||||
from plone.app.discussion.interfaces import IConversation, IComment, IReplies, IDiscussionSettings
|
||||
from plone.app.discussion.interfaces import IConversation
|
||||
from plone.app.discussion.interfaces import IComment
|
||||
from plone.app.discussion.interfaces import IReplies
|
||||
from plone.app.discussion.interfaces import IDiscussionSettings
|
||||
|
||||
|
||||
class ConversationTest(PloneTestCase):
|
||||
|
||||
@ -25,15 +29,17 @@ class ConversationTest(PloneTestCase):
|
||||
typetool = self.portal.portal_types
|
||||
typetool.constructContent('Document', self.portal, 'doc1')
|
||||
self.typetool = typetool
|
||||
self.portal_discussion = getToolByName(self.portal, 'portal_discussion', None)
|
||||
self.portal_discussion = getToolByName(self.portal,
|
||||
'portal_discussion',
|
||||
None)
|
||||
|
||||
def test_add_comment(self):
|
||||
# Create a conversation. In this case we doesn't assign it to an
|
||||
# object, as we just want to check the Conversation object API.
|
||||
conversation = IConversation(self.portal.doc1)
|
||||
|
||||
# Add a comment. Note: in real life, we always create comments via the factory
|
||||
# to allow different factories to be swapped in
|
||||
# Add a comment. Note: in real life, we always create comments via the
|
||||
# factory to allow different factories to be swapped in
|
||||
|
||||
comment = createObject('plone.Comment')
|
||||
comment.title = 'Comment 1'
|
||||
@ -44,20 +50,22 @@ class ConversationTest(PloneTestCase):
|
||||
# Check that the conversation methods return the correct data
|
||||
self.assert_(isinstance(comment.comment_id, long))
|
||||
self.assert_(IComment.providedBy(conversation[new_id]))
|
||||
self.assertEquals(aq_base(conversation[new_id].__parent__), aq_base(conversation))
|
||||
self.assertEquals(aq_base(conversation[new_id].__parent__),
|
||||
aq_base(conversation))
|
||||
self.assertEquals(new_id, comment.comment_id)
|
||||
self.assertEquals(len(list(conversation.getComments())), 1)
|
||||
self.assertEquals(sum(1 for w in conversation.getThreads()), 1)
|
||||
self.assertEquals(conversation.total_comments, 1)
|
||||
self.assert_(conversation.last_comment_date - datetime.now() < timedelta(seconds=1))
|
||||
self.assert_(conversation.last_comment_date - datetime.now() <
|
||||
timedelta(seconds=1))
|
||||
|
||||
def test_delete_comment(self):
|
||||
# Create a conversation. In this case we doesn't assign it to an
|
||||
# object, as we just want to check the Conversation object API.
|
||||
conversation = IConversation(self.portal.doc1)
|
||||
|
||||
# Add a comment. Note: in real life, we always create comments via the factory
|
||||
# to allow different factories to be swapped in
|
||||
# Add a comment. Note: in real life, we always create comments via the
|
||||
# factory to allow different factories to be swapped in
|
||||
|
||||
comment = createObject('plone.Comment')
|
||||
comment.title = 'Comment 1'
|
||||
@ -144,8 +152,8 @@ class ConversationTest(PloneTestCase):
|
||||
], list(conversation.getThreads()))
|
||||
|
||||
def test_delete_comment_when_content_object_is_deleted(self):
|
||||
# Make sure all comments of a content object are deleted when the object
|
||||
# itself is deleted.
|
||||
# Make sure all comments of a content object are deleted when the
|
||||
# object itself is deleted.
|
||||
conversation = IConversation(self.portal.doc1)
|
||||
comment = createObject('plone.Comment')
|
||||
comment.title = 'Comment 1'
|
||||
@ -183,37 +191,48 @@ class ConversationTest(PloneTestCase):
|
||||
# By default, allow_discussion on newly created content objects is
|
||||
# set to False
|
||||
portal_discussion = getToolByName(self.portal, 'portal_discussion')
|
||||
self.assertEquals(portal_discussion.isDiscussionAllowedFor(self.portal.doc1), False)
|
||||
self.assertEquals(self.portal.doc1.getTypeInfo().allowDiscussion(), False)
|
||||
self.assertEquals(portal_discussion.isDiscussionAllowedFor(
|
||||
self.portal.doc1), False)
|
||||
self.assertEquals(self.portal.doc1.getTypeInfo().allowDiscussion(),
|
||||
False)
|
||||
|
||||
# The allow discussion flag is None by default
|
||||
self.failIf(getattr(self.portal.doc1, 'allow_discussion', None))
|
||||
|
||||
# But isDiscussionAllowedFor, also checks if discussion is allowed on the
|
||||
# content type. So we allow discussion on the Document content type and
|
||||
# check if the Document object allows discussion now.
|
||||
# But isDiscussionAllowedFor, also checks if discussion is allowed on
|
||||
# the content type. So we allow discussion on the Document content
|
||||
# type and check if the Document object allows discussion now.
|
||||
document_fti = getattr(portal_types, 'Document')
|
||||
document_fti.manage_changeProperties(allow_discussion = True)
|
||||
self.assertEquals(portal_discussion.isDiscussionAllowedFor(self.portal.doc1), True)
|
||||
self.assertEquals(self.portal.doc1.getTypeInfo().allowDiscussion(), True)
|
||||
self.assertEquals(portal_discussion.isDiscussionAllowedFor(
|
||||
self.portal.doc1), True)
|
||||
self.assertEquals(self.portal.doc1.getTypeInfo().allowDiscussion(),
|
||||
True)
|
||||
|
||||
# We can also override the allow_discussion locally
|
||||
self.portal_discussion.overrideDiscussionFor(self.portal.doc1, False)
|
||||
# Check if the Document discussion is disabled
|
||||
self.assertEquals(portal_discussion.isDiscussionAllowedFor(self.portal.doc1), False)
|
||||
# Check that the local allow_discussion flag is now explicitly set to False
|
||||
self.assertEquals(getattr(self.portal.doc1, 'allow_discussion', None), False)
|
||||
self.assertEquals(portal_discussion.isDiscussionAllowedFor(
|
||||
self.portal.doc1), False)
|
||||
# Check that the local allow_discussion flag is now explicitly set to
|
||||
# False
|
||||
self.assertEquals(getattr(self.portal.doc1, 'allow_discussion', None),
|
||||
False)
|
||||
|
||||
# Disallow discussion on the Document content type again
|
||||
document_fti.manage_changeProperties(allow_discussion = False)
|
||||
self.assertEquals(portal_discussion.isDiscussionAllowedFor(self.portal.doc1), False)
|
||||
self.assertEquals(self.portal.doc1.getTypeInfo().allowDiscussion(), False)
|
||||
self.assertEquals(portal_discussion.isDiscussionAllowedFor(
|
||||
self.portal.doc1), False)
|
||||
self.assertEquals(self.portal.doc1.getTypeInfo().allowDiscussion(),
|
||||
False)
|
||||
|
||||
# Now we override allow_discussion again (True) for the Document
|
||||
# content object
|
||||
self.portal_discussion.overrideDiscussionFor(self.portal.doc1, True)
|
||||
self.assertEquals(portal_discussion.isDiscussionAllowedFor(self.portal.doc1), True)
|
||||
self.assertEquals(getattr(self.portal.doc1, 'allow_discussion', None), True)
|
||||
self.assertEquals(portal_discussion.isDiscussionAllowedFor(
|
||||
self.portal.doc1), True)
|
||||
self.assertEquals(getattr(self.portal.doc1, 'allow_discussion', None),
|
||||
True)
|
||||
|
||||
def test_comments_enabled_on_doc_in_subfolder(self):
|
||||
typetool = self.portal.portal_types
|
||||
@ -395,8 +414,8 @@ class ConversationTest(PloneTestCase):
|
||||
# object, as we just want to check the Conversation object API.
|
||||
conversation = IConversation(self.portal.doc1)
|
||||
|
||||
# Add a comment. Note: in real life, we always create comments via the factory
|
||||
# to allow different factories to be swapped in
|
||||
# Add a comment. Note: in real life, we always create comments via the
|
||||
# factory to allow different factories to be swapped in
|
||||
|
||||
comment1 = createObject('plone.Comment')
|
||||
comment1.title = 'Comment 1'
|
||||
@ -569,24 +588,30 @@ class ConversationTest(PloneTestCase):
|
||||
new_comment3_id = conversation.addComment(comment3)
|
||||
|
||||
# check if the latest comment is exactly one day old
|
||||
self.assert_(conversation.last_comment_date < datetime.now() - timedelta(hours=23, minutes=59, seconds=59))
|
||||
self.assert_(conversation.last_comment_date > datetime.now() - timedelta(days=1, seconds=1))
|
||||
self.assert_(conversation.last_comment_date < datetime.now() -
|
||||
timedelta(hours=23, minutes=59, seconds=59))
|
||||
self.assert_(conversation.last_comment_date >
|
||||
datetime.now() - timedelta(days=1, seconds=1))
|
||||
|
||||
# remove the latest comment
|
||||
del conversation[new_comment3_id]
|
||||
|
||||
# check if the latest comment has been updated
|
||||
# the latest comment should be exactly two days old
|
||||
self.assert_(conversation.last_comment_date < datetime.now() - timedelta(days=1, hours=23, minutes=59, seconds=59))
|
||||
self.assert_(conversation.last_comment_date > datetime.now() - timedelta(days=2, seconds=1))
|
||||
self.assert_(conversation.last_comment_date < datetime.now() -
|
||||
timedelta(days=1, hours=23, minutes=59, seconds=59))
|
||||
self.assert_(conversation.last_comment_date > datetime.now() -
|
||||
timedelta(days=2, seconds=1))
|
||||
|
||||
# remove the latest comment again
|
||||
del conversation[new_comment2_id]
|
||||
|
||||
# check if the latest comment has been updated
|
||||
# the latest comment should be exactly four days old
|
||||
self.assert_(conversation.last_comment_date < datetime.now() - timedelta(days=3, hours=23, minutes=59, seconds=59))
|
||||
self.assert_(conversation.last_comment_date > datetime.now() - timedelta(days=4, seconds=2))
|
||||
self.assert_(conversation.last_comment_date < datetime.now() -
|
||||
timedelta(days=3, hours=23, minutes=59, seconds=59))
|
||||
self.assert_(conversation.last_comment_date > datetime.now() -
|
||||
timedelta(days=4, seconds=2))
|
||||
|
||||
def test_get_comments_full(self):
|
||||
pass
|
||||
@ -672,16 +697,20 @@ class ConversationTest(PloneTestCase):
|
||||
def test_traversal(self):
|
||||
# make sure we can traverse to conversations and get a URL and path
|
||||
|
||||
conversation = self.portal.doc1.restrictedTraverse('++conversation++default')
|
||||
conversation = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default')
|
||||
self.assert_(IConversation.providedBy(conversation))
|
||||
|
||||
self.assertEquals(('', 'plone', 'doc1', '++conversation++default'), conversation.getPhysicalPath())
|
||||
# XXX: conversation.absolute_url() returns different values dependent on
|
||||
# the Plone version used.
|
||||
self.assertEquals(('', 'plone', 'doc1', '++conversation++default'),
|
||||
conversation.getPhysicalPath())
|
||||
# XXX: conversation.absolute_url() returns different values dependent
|
||||
# on the Plone version used.
|
||||
# Plone 3.3:
|
||||
#self.assertEquals('plone/doc1/%2B%2Bconversation%2B%2Bdefault', conversation.absolute_url())
|
||||
#self.assertEquals('plone/doc1/%2B%2Bconversation%2B%2Bdefault',
|
||||
#conversation.absolute_url())
|
||||
# Plone 4:
|
||||
#self.assertEquals('http://nohost/plone/doc1/++conversation++default', conversation.absolute_url())
|
||||
#self.assertEquals('http://nohost/plone/doc1/++conversation++default',
|
||||
#conversation.absolute_url())
|
||||
|
||||
def test_parent(self):
|
||||
# Check that conversation has a content object as parent
|
||||
@ -815,14 +844,17 @@ class RepliesTest(PloneTestCase):
|
||||
|
||||
# Create the nested comment structure
|
||||
new_id_1 = replies.addComment(comment1)
|
||||
comment1 = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_id_1)
|
||||
comment1 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id_1)
|
||||
replies_to_comment1 = IReplies(comment1)
|
||||
new_id_2 = replies.addComment(comment2)
|
||||
comment2 = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_id_2)
|
||||
comment2 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id_2)
|
||||
replies_to_comment2 = IReplies(comment2)
|
||||
|
||||
new_id_1_1 = replies_to_comment1.addComment(comment1_1)
|
||||
comment1_1 = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_id_1_1)
|
||||
comment1_1 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_id_1_1)
|
||||
replies_to_comment1_1 = IReplies(comment1_1)
|
||||
replies_to_comment1_1.addComment(comment1_1_1)
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
"""Test for the plone.app.discussion indexers
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
from datetime import datetime
|
||||
@ -14,8 +17,20 @@ from plone.indexer.delegate import DelegatingIndexerFactory
|
||||
|
||||
from plone.app.discussion import catalog
|
||||
|
||||
LONG_TEXT = """Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
|
||||
diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
|
||||
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
|
||||
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit
|
||||
amet."""
|
||||
|
||||
LONG_TEXT_CUT = """Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
|
||||
diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
|
||||
sed diam voluptua. At [...]"""
|
||||
|
||||
|
||||
class ConversationIndexersTest(PloneTestCase):
|
||||
"""Conversation Indexer Tests
|
||||
"""
|
||||
|
||||
layer = DiscussionLayer
|
||||
|
||||
@ -58,7 +73,8 @@ class ConversationIndexersTest(PloneTestCase):
|
||||
self.conversation = conversation
|
||||
|
||||
def test_conversation_total_comments(self):
|
||||
self.assert_(isinstance(catalog.total_comments, DelegatingIndexerFactory))
|
||||
self.assert_(isinstance(catalog.total_comments,
|
||||
DelegatingIndexerFactory))
|
||||
self.assertEquals(catalog.total_comments(self.portal.doc1)(), 3)
|
||||
del self.conversation[self.new_id1]
|
||||
self.assertEquals(catalog.total_comments(self.portal.doc1)(), 2)
|
||||
@ -67,18 +83,23 @@ class ConversationIndexersTest(PloneTestCase):
|
||||
self.assertEquals(catalog.total_comments(self.portal.doc1)(), 0)
|
||||
|
||||
def test_conversation_last_comment_date(self):
|
||||
self.assert_(isinstance(catalog.last_comment_date, DelegatingIndexerFactory))
|
||||
self.assertEquals(catalog.last_comment_date(self.portal.doc1)(), datetime(2009, 4, 12, 11, 12, 12))
|
||||
self.assert_(isinstance(catalog.last_comment_date,
|
||||
DelegatingIndexerFactory))
|
||||
self.assertEquals(catalog.last_comment_date(self.portal.doc1)(),
|
||||
datetime(2009, 4, 12, 11, 12, 12))
|
||||
del self.conversation[self.new_id3]
|
||||
self.assertEquals(catalog.last_comment_date(self.portal.doc1)(), datetime(2007, 12, 13, 4, 18, 12))
|
||||
self.assertEquals(catalog.last_comment_date(self.portal.doc1)(),
|
||||
datetime(2007, 12, 13, 4, 18, 12))
|
||||
del self.conversation[self.new_id2]
|
||||
del self.conversation[self.new_id1]
|
||||
self.assertEquals(catalog.last_comment_date(self.portal.doc1)(), None)
|
||||
|
||||
def test_conversation_commentators(self):
|
||||
pass
|
||||
#self.assertEquals(catalog.commentators(self.portal.doc1)(), ('Jim', 'Emma', 'Lukas'))
|
||||
#self.assert_(isinstance(catalog.commentators, DelegatingIndexerFactory))
|
||||
#self.assertEquals(catalog.commentators(self.portal.doc1)(),
|
||||
# ('Jim', 'Emma', 'Lukas'))
|
||||
#self.assert_(isinstance(catalog.commentators,
|
||||
# DelegatingIndexerFactory))
|
||||
|
||||
class CommentIndexersTest(PloneTestCase):
|
||||
|
||||
@ -94,8 +115,8 @@ class CommentIndexersTest(PloneTestCase):
|
||||
# object, as we just want to check the Conversation object API.
|
||||
conversation = IConversation(self.portal.doc1)
|
||||
|
||||
# Add a comment. Note: in real life, we always create comments via the factory
|
||||
# to allow different factories to be swapped in
|
||||
# Add a comment. Note: in real life, we always create comments via the
|
||||
# factory to allow different factories to be swapped in
|
||||
|
||||
comment = createObject('plone.Comment')
|
||||
comment.title = 'Comment 1'
|
||||
@ -104,9 +125,7 @@ class CommentIndexersTest(PloneTestCase):
|
||||
comment.creation_date = datetime(2006, 9, 17, 14, 18, 12)
|
||||
comment.modification_date = datetime(2008, 3, 12, 7, 32, 52)
|
||||
|
||||
new_id = conversation.addComment(comment)
|
||||
|
||||
self.comment_id = new_id
|
||||
self.comment_id = conversation.addComment(comment)
|
||||
self.comment = comment.__of__(conversation)
|
||||
self.conversation = conversation
|
||||
|
||||
@ -115,7 +134,8 @@ class CommentIndexersTest(PloneTestCase):
|
||||
self.assert_(isinstance(catalog.title, DelegatingIndexerFactory))
|
||||
|
||||
def test_description(self):
|
||||
self.assertEquals(catalog.description(self.comment)(), 'Lorem ipsum dolor sit amet.')
|
||||
self.assertEquals(catalog.description(self.comment)(),
|
||||
'Lorem ipsum dolor sit amet.')
|
||||
self.assert_(isinstance(catalog.description, DelegatingIndexerFactory))
|
||||
|
||||
def test_description_long(self):
|
||||
@ -123,20 +143,25 @@ class CommentIndexersTest(PloneTestCase):
|
||||
# only the first 25 words
|
||||
comment_long = createObject('plone.Comment')
|
||||
comment_long.title = 'Long Comment'
|
||||
comment_long.text = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.'
|
||||
comment_long.text = LONG_TEXT
|
||||
|
||||
self.conversation.addComment(comment_long)
|
||||
self.assertEquals(catalog.description(comment_long)(), 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At [...]')
|
||||
self.assertEquals(catalog.description(comment_long)(),
|
||||
LONG_TEXT_CUT.replace("\n", ""))
|
||||
|
||||
def test_dates(self):
|
||||
# Test if created, modified, effective etc. are set correctly
|
||||
self.assertEquals(catalog.created(self.comment)(), DateTime(2006, 9, 17, 14, 18, 12))
|
||||
self.assertEquals(catalog.modified(self.comment)(), DateTime(2008, 3, 12, 7, 32, 52))
|
||||
self.assertEquals(catalog.created(self.comment)(),
|
||||
DateTime(2006, 9, 17, 14, 18, 12))
|
||||
self.assertEquals(catalog.modified(self.comment)(),
|
||||
DateTime(2008, 3, 12, 7, 32, 52))
|
||||
|
||||
def test_searchable_text(self):
|
||||
# Test if searchable text is a concatenation of title and comment text
|
||||
self.assertEquals(catalog.searchable_text(self.comment)(), ('Comment 1', 'Lorem ipsum dolor sit amet.'))
|
||||
self.assert_(isinstance(catalog.searchable_text, DelegatingIndexerFactory))
|
||||
self.assertEquals(catalog.searchable_text(self.comment)(),
|
||||
('Comment 1', 'Lorem ipsum dolor sit amet.'))
|
||||
self.assert_(isinstance(catalog.searchable_text,
|
||||
DelegatingIndexerFactory))
|
||||
|
||||
def test_creator(self):
|
||||
self.assertEquals(catalog.creator(self.comment)(), ('Jim'))
|
||||
|
@ -34,7 +34,8 @@ class MigrationTest(PloneTestCase):
|
||||
request.set("test", True)
|
||||
context = getattr(self.portal, 'doc')
|
||||
self.view = View(context, request)
|
||||
self.workflow.setChainForPortalTypes(('Discussion Item',), 'comment_review_workflow')
|
||||
self.workflow.setChainForPortalTypes(('Discussion Item',),
|
||||
'comment_review_workflow')
|
||||
|
||||
self.doc = self.portal.doc
|
||||
|
||||
@ -57,7 +58,8 @@ class MigrationTest(PloneTestCase):
|
||||
self.view()
|
||||
|
||||
# Make sure a conversation has been created
|
||||
self.failUnless('plone.app.discussion:conversation' in IAnnotations(self.doc))
|
||||
self.failUnless('plone.app.discussion:conversation' in
|
||||
IAnnotations(self.doc))
|
||||
conversation = IConversation(self.doc)
|
||||
|
||||
# Check migration
|
||||
@ -68,8 +70,10 @@ class MigrationTest(PloneTestCase):
|
||||
self.assertEquals(comment1.Title(), 'My Title')
|
||||
self.assertEquals(comment1.text, 'My Text')
|
||||
self.assertEquals(comment1.Creator(), 'Jim')
|
||||
self.assertEquals(comment1.creation_date, datetime(2003, 3, 11, 9, 28, 6))
|
||||
self.assertEquals(comment1.modification_date, datetime(2009, 7, 12, 19, 38, 7))
|
||||
self.assertEquals(comment1.creation_date,
|
||||
datetime(2003, 3, 11, 9, 28, 6))
|
||||
self.assertEquals(comment1.modification_date,
|
||||
datetime(2009, 7, 12, 19, 38, 7))
|
||||
self.assertEquals(
|
||||
[{'comment': comment1, 'depth': 0, 'id': long(comment1.id)},]
|
||||
, list(conversation.getThreads()))
|
||||
|
@ -26,14 +26,18 @@ class WorkflowTest(PloneTestCase):
|
||||
|
||||
def test_permission(self):
|
||||
self.setRoles(('Reviewer',))
|
||||
self.failUnless(self.portal.portal_membership.checkPermission('Review comments', self.folder), self.folder)
|
||||
self.failUnless(self.portal.portal_membership.checkPermission(
|
||||
'Review comments', self.folder), self.folder)
|
||||
self.setRoles(('Member',))
|
||||
self.failIf(self.portal.portal_membership.checkPermission('Review comments', self.folder), self.folder)
|
||||
self.failIf(self.portal.portal_membership.checkPermission(
|
||||
'Review comments', self.folder), self.folder)
|
||||
|
||||
def test_workflows_installed(self):
|
||||
self.failUnless('comment_review_workflow' in self.portal.portal_workflow.objectIds())
|
||||
self.failUnless('comment_review_workflow' in
|
||||
self.portal.portal_workflow.objectIds())
|
||||
self.assertEquals(('one_state_workflow',),
|
||||
self.portal.portal_workflow.getChainForPortalType('Discussion Item'))
|
||||
self.portal.portal_workflow.getChainForPortalType(
|
||||
'Discussion Item'))
|
||||
|
||||
class TestCommentOperations(PloneTestCase):
|
||||
|
||||
@ -46,7 +50,8 @@ class TestCommentOperations(PloneTestCase):
|
||||
# Allow discussion on the Document content type
|
||||
self.portal.portal_types['Document'].allow_discussion = True
|
||||
# Set workflow for Discussion item to review workflow
|
||||
self.portal.portal_workflow.setChainForPortalTypes(('Discussion Item',),
|
||||
self.portal.portal_workflow.setChainForPortalTypes(
|
||||
('Discussion Item',),
|
||||
('comment_review_workflow',))
|
||||
|
||||
# Create a Document
|
||||
@ -61,7 +66,8 @@ class TestCommentOperations(PloneTestCase):
|
||||
comment.title = 'Comment 1'
|
||||
comment.text = 'Comment text'
|
||||
comment_id = conversation.addComment(comment)
|
||||
comment = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % comment_id)
|
||||
comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % comment_id)
|
||||
|
||||
self.conversation = conversation
|
||||
self.comment_id = comment_id
|
||||
@ -98,20 +104,25 @@ class TestCommentOperations(PloneTestCase):
|
||||
def test_publish(self):
|
||||
self.portal.REQUEST.form['comment_id'] = self.comment_id
|
||||
self.portal.REQUEST.form['workflow_action'] = 'publish'
|
||||
self.assertEquals('pending', self.portal.portal_workflow.getInfoFor(self.comment, 'review_state'))
|
||||
self.assertEquals('pending',
|
||||
self.portal.portal_workflow.getInfoFor(
|
||||
self.comment, 'review_state'))
|
||||
view = self.comment.restrictedTraverse('@@moderate-publish-comment')
|
||||
view()
|
||||
self.assertEquals('published', self.portal.portal_workflow.getInfoFor(self.comment, 'review_state'))
|
||||
self.assertEquals('published', self.portal.portal_workflow.\
|
||||
getInfoFor(self.comment, 'review_state'))
|
||||
|
||||
def test_publish_as_anonymous(self):
|
||||
self.logout()
|
||||
self.portal.REQUEST.form['comment_id'] = self.comment_id
|
||||
self.portal.REQUEST.form['workflow_action'] = 'publish'
|
||||
self.assertEquals('pending', self.portal.portal_workflow.getInfoFor(self.comment, 'review_state'))
|
||||
self.assertEquals('pending', self.portal.portal_workflow.\
|
||||
getInfoFor(self.comment, 'review_state'))
|
||||
self.assertRaises(Unauthorized,
|
||||
self.comment.restrictedTraverse,
|
||||
'@@moderate-publish-comment')
|
||||
self.assertEquals('pending', self.portal.portal_workflow.getInfoFor(self.comment, 'review_state'))
|
||||
self.assertEquals('pending', self.portal.portal_workflow.\
|
||||
getInfoFor(self.comment, 'review_state'))
|
||||
|
||||
def test_suite():
|
||||
return unittest.defaultTestLoader.loadTestsFromName(__name__)
|
Loading…
Reference in New Issue
Block a user