Make pylint happy.

svn path=/plone.app.discussion/trunk/; revision=39287
This commit is contained in:
Timo Stollenwerk 2010-08-28 17:06:53 +00:00
parent 0f9c98ec97
commit 435040e0b2
9 changed files with 314 additions and 163 deletions

View File

@ -1,3 +1,5 @@
"""Test the plone.app.discussion catalog indexes
"""
import unittest import unittest
from datetime import datetime from datetime import datetime
@ -17,10 +19,14 @@ class CatalogSetupTest(PloneTestCase):
layer = DiscussionLayer layer = DiscussionLayer
def test_catalog_installed(self): def test_catalog_installed(self):
self.failUnless('total_comments' in self.portal.portal_catalog.indexes()) self.failUnless('total_comments' in
self.failUnless('commentators' in self.portal.portal_catalog.indexes()) self.portal.portal_catalog.indexes())
self.failUnless('total_comments' in self.portal.portal_catalog.schema()) self.failUnless('commentators' in
self.failUnless('in_response_to' in self.portal.portal_catalog.schema()) 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): def test_collection_criteria_installed(self):
try: try:
@ -30,6 +36,7 @@ class CatalogSetupTest(PloneTestCase):
except AttributeError: except AttributeError:
self.fail() self.fail()
class ConversationCatalogTest(PloneTestCase): class ConversationCatalogTest(PloneTestCase):
layer = DiscussionLayer layer = DiscussionLayer
@ -56,7 +63,8 @@ class ConversationCatalogTest(PloneTestCase):
self.comment_id = new_comment1_id self.comment_id = new_comment1_id
brains = self.catalog.searchResults( brains = self.catalog.searchResults(
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) }, path = {'query' :
'/'.join(self.portal.doc1.getPhysicalPath()) },
portal_type = "Document" portal_type = "Document"
) )
self.conversation = conversation self.conversation = conversation
@ -75,10 +83,12 @@ class ConversationCatalogTest(PloneTestCase):
comment2.creator = 'Emma' comment2.creator = 'Emma'
new_comment2_id = self.conversation.addComment(comment2) 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() comment2.reindexObject()
brains = self.catalog.searchResults( brains = self.catalog.searchResults(
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) }, path = {'query' :
'/'.join(self.portal.doc1.getPhysicalPath()) },
portal_type = "Document" portal_type = "Document"
) )
doc1_brain = brains[0] doc1_brain = brains[0]
@ -86,7 +96,8 @@ class ConversationCatalogTest(PloneTestCase):
def test_last_comment_date(self): def test_last_comment_date(self):
self.failUnless(self.doc1_brain.has_key('last_comment_date')) 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. # Add another comment and check if last comment date is updated.
comment2 = createObject('plone.Comment') comment2 = createObject('plone.Comment')
@ -97,30 +108,36 @@ class ConversationCatalogTest(PloneTestCase):
comment2.modification_date = datetime(2009, 9, 17, 14, 18, 12) comment2.modification_date = datetime(2009, 9, 17, 14, 18, 12)
new_comment2_id = self.conversation.addComment(comment2) 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() comment2.reindexObject()
brains = self.catalog.searchResults( brains = self.catalog.searchResults(
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) }, path = {'query' :
'/'.join(self.portal.doc1.getPhysicalPath()) },
portal_type = "Document" portal_type = "Document"
) )
doc1_brain = brains[0] 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 # Remove the comment again
del self.conversation[new_comment2_id] del self.conversation[new_comment2_id]
brains = self.catalog.searchResults( brains = self.catalog.searchResults(
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) }, path = {'query' :
'/'.join(self.portal.doc1.getPhysicalPath()) },
portal_type = "Document" portal_type = "Document"
) )
doc1_brain = brains[0] 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 # remove all comments
del self.conversation[self.new_comment1_id] del self.conversation[self.new_comment1_id]
brains = self.catalog.searchResults( brains = self.catalog.searchResults(
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) }, path = {'query' :
'/'.join(self.portal.doc1.getPhysicalPath()) },
portal_type = "Document" portal_type = "Document"
) )
doc1_brain = brains[0] doc1_brain = brains[0]
@ -138,11 +155,13 @@ class ConversationCatalogTest(PloneTestCase):
comment2.author_username = 'Emma' comment2.author_username = 'Emma'
new_comment2_id = self.conversation.addComment(comment2) 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() comment2.reindexObject()
brains = self.catalog.searchResults( brains = self.catalog.searchResults(
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) }, path = {'query' :
'/'.join(self.portal.doc1.getPhysicalPath()) },
portal_type = "Document" portal_type = "Document"
) )
doc1_brain = brains[0] doc1_brain = brains[0]
@ -152,7 +171,8 @@ class ConversationCatalogTest(PloneTestCase):
# remove one comments # remove one comments
del self.conversation[new_comment2_id] del self.conversation[new_comment2_id]
brains = self.catalog.searchResults( brains = self.catalog.searchResults(
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) }, path = {'query' :
'/'.join(self.portal.doc1.getPhysicalPath()) },
portal_type = "Document" portal_type = "Document"
) )
doc1_brain = brains[0] doc1_brain = brains[0]
@ -161,7 +181,8 @@ class ConversationCatalogTest(PloneTestCase):
# remove all comments # remove all comments
del self.conversation[self.new_comment1_id] del self.conversation[self.new_comment1_id]
brains = self.catalog.searchResults( brains = self.catalog.searchResults(
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) }, path = {'query' :
'/'.join(self.portal.doc1.getPhysicalPath()) },
portal_type = "Document" portal_type = "Document"
) )
doc1_brain = brains[0] doc1_brain = brains[0]
@ -169,7 +190,8 @@ class ConversationCatalogTest(PloneTestCase):
def test_conversation_indexes_not_in_comments(self): def test_conversation_indexes_not_in_comments(self):
brains = self.catalog.searchResults( brains = self.catalog.searchResults(
path = {'query' : '/'.join(self.portal.doc1.getPhysicalPath()) }, path = {'query' :
'/'.join(self.portal.doc1.getPhysicalPath()) },
portal_type = "Discussion Item" portal_type = "Discussion Item"
) )
comment1_brain = brains[0] comment1_brain = brains[0]
@ -201,10 +223,12 @@ class CommentCatalogTest(PloneTestCase):
new_comment1_id = conversation.addComment(comment1) new_comment1_id = conversation.addComment(comment1)
self.comment_id = new_comment1_id 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( brains = self.catalog.searchResults(
path = {'query' : '/'.join(self.comment.getPhysicalPath()) }) path = {'query' :
'/'.join(self.comment.getPhysicalPath()) })
self.comment_brain = brains[0] self.comment_brain = brains[0]
def test_title(self): def test_title(self):
@ -234,7 +258,8 @@ class CommentCatalogTest(PloneTestCase):
# deleted. # deleted.
del self.conversation[self.comment_id] del self.conversation[self.comment_id]
brains = self.catalog.searchResults( brains = self.catalog.searchResults(
path = {'query' : '/'.join(self.comment.getPhysicalPath()) }) path = {'query' :
'/'.join(self.comment.getPhysicalPath()) })
self.assertEquals(len(brains), 0) self.assertEquals(len(brains), 0)
def test_remove_comments_when_content_object_is_removed(self): def test_remove_comments_when_content_object_is_removed(self):

View File

@ -46,7 +46,8 @@ class CommentTest(PloneTestCase):
self.assertEquals(comment1.Type(), 'Comment') self.assertEquals(comment1.Type(), 'Comment')
def test_traversal(self): 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) conversation = IConversation(self.portal.doc1)
@ -56,15 +57,20 @@ class CommentTest(PloneTestCase):
new_comment1_id = conversation.addComment(comment1) 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.assert_(IComment.providedBy(comment))
self.assertEquals('Comment 1', comment.title) self.assertEquals('Comment 1', comment.title)
self.assertEquals(('', 'plone', 'doc1', '++conversation++default', str(new_comment1_id)), comment.getPhysicalPath()) self.assertEquals(('', 'plone', 'doc1', '++conversation++default',
self.assertEquals('http://nohost/plone/doc1/++conversation++default/' + str(new_comment1_id), comment.absolute_url()) 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): 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) conversation = IConversation(self.portal.doc1)
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
@ -76,10 +82,14 @@ class CommentTest(PloneTestCase):
self.assertEquals(('simple_publication_workflow',), chain) self.assertEquals(('simple_publication_workflow',), chain)
# ensure the initial state was entered and recorded # ensure the initial state was entered and recorded
self.assertEquals(1, len(comment.workflow_history['simple_publication_workflow'])) self.assertEquals(1,
self.assertEquals(None, comment.workflow_history['simple_publication_workflow'][0]['action']) 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): def test_fti(self):
# test that we can look up an FTI for Discussion Item # 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()) self.assertEquals('Discussion Item', fti.getTypeInfo(comment1).getId())
def test_view(self): 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 # Create a conversation. In this case we doesn't assign it to an
# object, as we just want to check the Conversation object API. # object, as we just want to check the Conversation object API.
@ -106,10 +117,12 @@ class CommentTest(PloneTestCase):
# Add comment to the conversation # Add comment to the conversation
new_comment1_id = conversation.addComment(comment1) 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 # 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 # TODO: is this correct? Redirect ist 301
self.assertEquals(200, self.app.REQUEST.response.getStatus()) self.assertEquals(200, self.app.REQUEST.response.getStatus())
@ -140,7 +153,8 @@ class RepliesTest(PloneTestCase):
comment.title = 'Comment 1' comment.title = 'Comment 1'
comment.text = 'Comment text' comment.text = 'Comment text'
new_id = replies.addComment(comment) 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 # Add a reply to the CommentReplies adapter of the first comment
re_comment = createObject('plone.Comment') re_comment = createObject('plone.Comment')
@ -177,7 +191,8 @@ class RepliesTest(PloneTestCase):
comment.title = 'Comment 1' comment.title = 'Comment 1'
comment.text = 'Comment text' comment.text = 'Comment text'
new_id = replies.addComment(comment) 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 # Add a reply to the CommentReplies adapter of the first comment
re_comment = createObject('plone.Comment') re_comment = createObject('plone.Comment')
@ -200,7 +215,8 @@ class RepliesTest(PloneTestCase):
def test_traversal(self): def test_traversal(self):
# Create a nested structure of comment replies and check the traversal # 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) conversation = IConversation(self.portal.doc1)
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
@ -213,7 +229,8 @@ class RepliesTest(PloneTestCase):
comment.title = 'Comment 1' comment.title = 'Comment 1'
comment.text = 'Comment text' comment.text = 'Comment text'
new_id = conversation.addComment(comment) 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 # Add a reply to the CommentReplies adapter of the first comment
re_comment = createObject('plone.Comment') re_comment = createObject('plone.Comment')
@ -221,7 +238,8 @@ class RepliesTest(PloneTestCase):
re_comment.text = 'Comment text' re_comment.text = 'Comment text'
replies = IReplies(comment) replies = IReplies(comment)
new_re_id = replies.addComment(re_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 # Add a reply to the reply
re_re_comment = createObject('plone.Comment') re_re_comment = createObject('plone.Comment')
@ -229,7 +247,8 @@ class RepliesTest(PloneTestCase):
re_re_comment.text = 'Comment text' re_re_comment.text = 'Comment text'
replies = IReplies(re_comment) replies = IReplies(re_comment)
new_re_re_id = replies.addComment(re_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 # Add a reply to the replies reply
re_re_re_comment = createObject('plone.Comment') re_re_re_comment = createObject('plone.Comment')
@ -237,16 +256,27 @@ class RepliesTest(PloneTestCase):
re_re_re_comment.text = 'Comment text' re_re_re_comment.text = 'Comment text'
replies = IReplies(re_re_comment) replies = IReplies(re_re_comment)
new_re_re_re_id = replies.addComment(re_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(('', 'plone', 'doc1', '++conversation++default',
self.assertEquals('http://nohost/plone/doc1/++conversation++default/' + str(new_id), comment.absolute_url()) str(new_id)), comment.getPhysicalPath())
self.assertEquals(('', 'plone', 'doc1', '++conversation++default', str(new_re_id)), re_comment.getPhysicalPath()) self.assertEquals('http://nohost/plone/doc1/++conversation++default/' +
self.assertEquals('http://nohost/plone/doc1/++conversation++default/' + str(new_re_id), re_comment.absolute_url()) str(new_id), comment.absolute_url())
self.assertEquals(('', 'plone', 'doc1', '++conversation++default', str(new_re_re_id)), re_re_comment.getPhysicalPath()) self.assertEquals(('', 'plone', 'doc1', '++conversation++default',
self.assertEquals('http://nohost/plone/doc1/++conversation++default/' + str(new_re_re_id), re_re_comment.absolute_url()) str(new_re_id)), re_comment.getPhysicalPath())
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/' +
self.assertEquals('http://nohost/plone/doc1/++conversation++default/' + str(new_re_re_re_id), re_re_re_comment.absolute_url()) 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(): def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__) return unittest.defaultTestLoader.loadTestsFromName(__name__)

View File

@ -27,7 +27,9 @@ class TestCommentForm(PloneTestCase):
self.loginAsPortalOwner() 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, 'portal_discussion', None) self.portal_discussion = getToolByName(self.portal,
'portal_discussion',
None)
self.membership_tool = getToolByName(self.folder, 'portal_membership') self.membership_tool = getToolByName(self.folder, 'portal_membership')
self.memberdata = self.portal.portal_memberdata self.memberdata = self.portal.portal_memberdata
request = self.app.REQUEST request = self.app.REQUEST
@ -87,7 +89,8 @@ class TestCommentsViewletIntegration(FunctionalTestCase):
# Do not show the old comment viewlet # Do not show the old comment viewlet
self.failIf('discussion_reply_form' in browser.contents) self.failIf('discussion_reply_form' in browser.contents)
# Show the new comment viewlet # 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-title' in browser.contents)
self.failUnless('formfield-form-widgets-text' in browser.contents) self.failUnless('formfield-form-widgets-text' in browser.contents)
@ -100,7 +103,9 @@ class TestCommentsViewlet(PloneTestCase):
self.loginAsPortalOwner() 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, 'portal_discussion', None) self.portal_discussion = getToolByName(self.portal,
'portal_discussion',
None)
self.membership_tool = getToolByName(self.folder, 'portal_membership') self.membership_tool = getToolByName(self.folder, 'portal_membership')
self.memberdata = self.portal.portal_memberdata self.memberdata = self.portal.portal_memberdata
request = self.app.REQUEST request = self.app.REQUEST
@ -112,7 +117,7 @@ class TestCommentsViewlet(PloneTestCase):
Second paragraph""" Second paragraph"""
self.assertEquals(self.viewlet.cook(text), self.assertEquals(self.viewlet.cook(text),
"<p>First paragraph<br /> <br /> Second paragraph</p>") "<p>First paragraph<br /> <br /> Second paragraph</p>")
def test_cook_no_html(self): def test_cook_no_html(self):
text = """<b>Got HTML?</b>""" text = """<b>Got HTML?</b>"""
@ -122,7 +127,7 @@ class TestCommentsViewlet(PloneTestCase):
def test_cook_with_no_ascii_characters(self): def test_cook_with_no_ascii_characters(self):
text = """Umlaute sind ä, ö und ü.""" text = """Umlaute sind ä, ö und ü."""
self.assertEquals(self.viewlet.cook(text), self.assertEquals(self.viewlet.cook(text),
"<p>Umlaute sind \xc3\xa4, \xc3\xb6 und \xc3\xbc.</p>") "<p>Umlaute sind \xc3\xa4, \xc3\xb6 und \xc3\xbc.</p>")
def test_cook_links(self): def test_cook_links(self):
text = "Go to http://www.plone.org" text = "Go to http://www.plone.org"
@ -183,18 +188,21 @@ class TestCommentsViewlet(PloneTestCase):
comment.text = 'Comment text' comment.text = 'Comment text'
conversation = IConversation(self.portal.doc1) conversation = IConversation(self.portal.doc1)
c1 = conversation.addComment(comment) 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 # Enable moderation workflow
self.portal.portal_workflow.setChainForPortalTypes(('Discussion Item',), self.portal.portal_workflow.setChainForPortalTypes(
('simple_publication_workflow,')) ('Discussion Item',),
('simple_publication_workflow,'))
# Check if workflow actions are available # Check if workflow actions are available
reply = self.viewlet.get_replies(workflow_actions=True).next() reply = self.viewlet.get_replies(workflow_actions=True).next()
self.failUnless(reply.has_key('actions')) self.failUnless(reply.has_key('actions'))
self.assertEquals(reply['actions'][0]['id'], self.assertEquals(reply['actions'][0]['id'],
'publish') 'publish')
self.assertEquals(reply['actions'][0]['url'], self.assertEquals(reply['actions'][0]['url'],
'http://nohost/plone/doc1/++conversation++default/%s' % int(c1) + 'http://nohost/plone/doc1/++conversation++default/%s' % int(c1) +
'/content_status_modify?workflow_action=publish') '/content_status_modify?workflow_action=publish')
def test_get_commenter_home_url(self): def test_get_commenter_home_url(self):
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
@ -213,9 +221,13 @@ class TestCommentsViewlet(PloneTestCase):
# Add a user with a member image # Add a user with a member image
self.membership_tool.addMember('jim', 'Jim', ['Member'], []) self.membership_tool.addMember('jim', 'Jim', ['Member'], [])
self.memberdata._setPortrait(Image(id='jim', file=dummy.File(), title=''), 'jim') self.memberdata._setPortrait(Image(id='jim',
self.assertEqual(self.memberdata._getPortrait('jim').getId(), 'jim') file=dummy.File(),
self.assertEqual(self.memberdata._getPortrait('jim').meta_type, 'Image') 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 # Add a conversation with a comment
conversation = IConversation(self.portal.doc1) conversation = IConversation(self.portal.doc1)
@ -232,7 +244,7 @@ class TestCommentsViewlet(PloneTestCase):
# Check if the correct member image URL is returned # Check if the correct member image URL is returned
self.assertEquals(portrait_url, self.assertEquals(portrait_url,
'http://nohost/plone/portal_memberdata/portraits/jim') 'http://nohost/plone/portal_memberdata/portraits/jim')
def test_get_commenter_portrait_is_none(self): def test_get_commenter_portrait_is_none(self):
self.assertEquals(self.viewlet.get_commenter_portrait(), self.assertEquals(self.viewlet.get_commenter_portrait(),
@ -264,14 +276,16 @@ class TestCommentsViewlet(PloneTestCase):
self.failIf(self.viewlet.anonymous_discussion_allowed()) self.failIf(self.viewlet.anonymous_discussion_allowed())
# Allow anonymous discussion # Allow anonymous discussion
registry = queryUtility(IRegistry) 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 # Test if anonymous discussion is allowed for the viewlet
self.failUnless(self.viewlet.anonymous_discussion_allowed()) self.failUnless(self.viewlet.anonymous_discussion_allowed())
def test_show_commenter_image(self): def test_show_commenter_image(self):
self.failUnless(self.viewlet.show_commenter_image()) self.failUnless(self.viewlet.show_commenter_image())
registry = queryUtility(IRegistry) 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()) self.failIf(self.viewlet.show_commenter_image())
def test_is_anonymous(self): def test_is_anonymous(self):
@ -282,7 +296,7 @@ class TestCommentsViewlet(PloneTestCase):
def test_login_action(self): def test_login_action(self):
self.viewlet.update() self.viewlet.update()
self.assertEquals(self.viewlet.login_action(), self.assertEquals(self.viewlet.login_action(),
'http://nohost/plone/login_form?came_from=http%3A//nohost') 'http://nohost/plone/login_form?came_from=http%3A//nohost')
def test_format_time(self): def test_format_time(self):
python_time = datetime(2009, 02, 01, 23, 32, 03, 57) python_time = datetime(2009, 02, 01, 23, 32, 03, 57)
@ -290,4 +304,4 @@ class TestCommentsViewlet(PloneTestCase):
self.assertEquals(localized_time, "Feb 01, 2009 11:32 PM") self.assertEquals(localized_time, "Feb 01, 2009 11:32 PM")
def test_suite(): def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__) return unittest.defaultTestLoader.loadTestsFromName(__name__)

View File

@ -38,41 +38,51 @@ class RegistryTest(PloneTestCase):
# Check globally_enabled record # Check globally_enabled record
self.failUnless('globally_enabled' in IDiscussionSettings) self.failUnless('globally_enabled' in IDiscussionSettings)
self.assertEquals( self.assertEquals(
self.registry['plone.app.discussion.interfaces.IDiscussionSettings.globally_enabled'], self.registry['plone.app.discussion.interfaces.' +
'IDiscussionSettings.globally_enabled'],
True) True)
def test_text_transform(self): def test_text_transform(self):
self.failUnless('text_transform' in IDiscussionSettings) self.failUnless('text_transform' in IDiscussionSettings)
self.assertEquals( self.assertEquals(
self.registry['plone.app.discussion.interfaces.IDiscussionSettings.text_transform'], self.registry['plone.app.discussion.interfaces.' +
'IDiscussionSettings.text_transform'],
'text/plain') 'text/plain')
def test_captcha(self): def test_captcha(self):
# Check globally_enabled record # Check globally_enabled record
self.failUnless('captcha' in IDiscussionSettings) 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): def test_anonymous_comments(self):
# Check anonymous_comments record # Check anonymous_comments record
self.failUnless('anonymous_comments' in IDiscussionSettings) 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): def test_show_commenter_image(self):
# Check show_commenter_image record # Check show_commenter_image record
self.failUnless('show_commenter_image' in IDiscussionSettings) 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): def test_moderator_notification_enabled(self):
# Check show_commenter_image record # Check show_commenter_image record
self.failUnless('moderator_notification_enabled' in IDiscussionSettings) self.failUnless('moderator_notification_enabled' in
self.assertEquals(self.registry['plone.app.discussion.interfaces.IDiscussionSettings.moderator_notification_enabled'], False) IDiscussionSettings)
self.assertEquals(self.registry['plone.app.discussion.interfaces.' +
'IDiscussionSettings.moderator_notification_enabled'], False)
#def test_user_notification_enabled(self): #def test_user_notification_enabled(self):
# # Check show_commenter_image record # # 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.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(): def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__) return unittest.defaultTestLoader.loadTestsFromName(__name__)

View File

@ -13,7 +13,11 @@ from Products.CMFCore.utils import getToolByName
from Products.PloneTestCase.ptc import PloneTestCase from Products.PloneTestCase.ptc import PloneTestCase
from plone.app.discussion.tests.layer import DiscussionLayer 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): class ConversationTest(PloneTestCase):
@ -25,15 +29,17 @@ class ConversationTest(PloneTestCase):
typetool = self.portal.portal_types typetool = self.portal.portal_types
typetool.constructContent('Document', self.portal, 'doc1') typetool.constructContent('Document', self.portal, 'doc1')
self.typetool = typetool 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): def test_add_comment(self):
# Create a conversation. In this case we doesn't assign it to an # Create a conversation. In this case we doesn't assign it to an
# object, as we just want to check the Conversation object API. # object, as we just want to check the Conversation object API.
conversation = IConversation(self.portal.doc1) conversation = IConversation(self.portal.doc1)
# Add a comment. Note: in real life, we always create comments via the factory # Add a comment. Note: in real life, we always create comments via the
# to allow different factories to be swapped in # factory to allow different factories to be swapped in
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.title = 'Comment 1' comment.title = 'Comment 1'
@ -44,20 +50,22 @@ class ConversationTest(PloneTestCase):
# Check that the conversation methods return the correct data # Check that the conversation methods return the correct data
self.assert_(isinstance(comment.comment_id, long)) self.assert_(isinstance(comment.comment_id, long))
self.assert_(IComment.providedBy(conversation[new_id])) 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(new_id, comment.comment_id)
self.assertEquals(len(list(conversation.getComments())), 1) self.assertEquals(len(list(conversation.getComments())), 1)
self.assertEquals(sum(1 for w in conversation.getThreads()), 1) self.assertEquals(sum(1 for w in conversation.getThreads()), 1)
self.assertEquals(conversation.total_comments, 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): def test_delete_comment(self):
# Create a conversation. In this case we doesn't assign it to an # Create a conversation. In this case we doesn't assign it to an
# object, as we just want to check the Conversation object API. # object, as we just want to check the Conversation object API.
conversation = IConversation(self.portal.doc1) conversation = IConversation(self.portal.doc1)
# Add a comment. Note: in real life, we always create comments via the factory # Add a comment. Note: in real life, we always create comments via the
# to allow different factories to be swapped in # factory to allow different factories to be swapped in
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.title = 'Comment 1' comment.title = 'Comment 1'
@ -144,8 +152,8 @@ class ConversationTest(PloneTestCase):
], list(conversation.getThreads())) ], list(conversation.getThreads()))
def test_delete_comment_when_content_object_is_deleted(self): def test_delete_comment_when_content_object_is_deleted(self):
# Make sure all comments of a content object are deleted when the object # Make sure all comments of a content object are deleted when the
# itself is deleted. # object itself is deleted.
conversation = IConversation(self.portal.doc1) conversation = IConversation(self.portal.doc1)
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.title = 'Comment 1' comment.title = 'Comment 1'
@ -183,37 +191,48 @@ class ConversationTest(PloneTestCase):
# By default, allow_discussion on newly created content objects is # By default, allow_discussion on newly created content objects is
# set to False # set to False
portal_discussion = getToolByName(self.portal, 'portal_discussion') portal_discussion = getToolByName(self.portal, 'portal_discussion')
self.assertEquals(portal_discussion.isDiscussionAllowedFor(self.portal.doc1), False) self.assertEquals(portal_discussion.isDiscussionAllowedFor(
self.assertEquals(self.portal.doc1.getTypeInfo().allowDiscussion(), False) self.portal.doc1), False)
self.assertEquals(self.portal.doc1.getTypeInfo().allowDiscussion(),
False)
# The allow discussion flag is None by default # The allow discussion flag is None by default
self.failIf(getattr(self.portal.doc1, 'allow_discussion', None)) self.failIf(getattr(self.portal.doc1, 'allow_discussion', None))
# But isDiscussionAllowedFor, also checks if discussion is allowed on the # But isDiscussionAllowedFor, also checks if discussion is allowed on
# content type. So we allow discussion on the Document content type and # the content type. So we allow discussion on the Document content
# check if the Document object allows discussion now. # type and check if the Document object allows discussion now.
document_fti = getattr(portal_types, 'Document') document_fti = getattr(portal_types, 'Document')
document_fti.manage_changeProperties(allow_discussion = True) document_fti.manage_changeProperties(allow_discussion = True)
self.assertEquals(portal_discussion.isDiscussionAllowedFor(self.portal.doc1), True) self.assertEquals(portal_discussion.isDiscussionAllowedFor(
self.assertEquals(self.portal.doc1.getTypeInfo().allowDiscussion(), True) self.portal.doc1), True)
self.assertEquals(self.portal.doc1.getTypeInfo().allowDiscussion(),
True)
# We can also override the allow_discussion locally # We can also override the allow_discussion locally
self.portal_discussion.overrideDiscussionFor(self.portal.doc1, False) self.portal_discussion.overrideDiscussionFor(self.portal.doc1, False)
# Check if the Document discussion is disabled # Check if the Document discussion is disabled
self.assertEquals(portal_discussion.isDiscussionAllowedFor(self.portal.doc1), False) self.assertEquals(portal_discussion.isDiscussionAllowedFor(
# Check that the local allow_discussion flag is now explicitly set to False self.portal.doc1), False)
self.assertEquals(getattr(self.portal.doc1, 'allow_discussion', None), 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 # Disallow discussion on the Document content type again
document_fti.manage_changeProperties(allow_discussion = False) document_fti.manage_changeProperties(allow_discussion = False)
self.assertEquals(portal_discussion.isDiscussionAllowedFor(self.portal.doc1), False) self.assertEquals(portal_discussion.isDiscussionAllowedFor(
self.assertEquals(self.portal.doc1.getTypeInfo().allowDiscussion(), False) self.portal.doc1), False)
self.assertEquals(self.portal.doc1.getTypeInfo().allowDiscussion(),
False)
# Now we override allow_discussion again (True) for the Document # Now we override allow_discussion again (True) for the Document
# content object # content object
self.portal_discussion.overrideDiscussionFor(self.portal.doc1, True) self.portal_discussion.overrideDiscussionFor(self.portal.doc1, True)
self.assertEquals(portal_discussion.isDiscussionAllowedFor(self.portal.doc1), True) self.assertEquals(portal_discussion.isDiscussionAllowedFor(
self.assertEquals(getattr(self.portal.doc1, 'allow_discussion', None), True) self.portal.doc1), True)
self.assertEquals(getattr(self.portal.doc1, 'allow_discussion', None),
True)
def test_comments_enabled_on_doc_in_subfolder(self): def test_comments_enabled_on_doc_in_subfolder(self):
typetool = self.portal.portal_types typetool = self.portal.portal_types
@ -395,8 +414,8 @@ class ConversationTest(PloneTestCase):
# object, as we just want to check the Conversation object API. # object, as we just want to check the Conversation object API.
conversation = IConversation(self.portal.doc1) conversation = IConversation(self.portal.doc1)
# Add a comment. Note: in real life, we always create comments via the factory # Add a comment. Note: in real life, we always create comments via the
# to allow different factories to be swapped in # factory to allow different factories to be swapped in
comment1 = createObject('plone.Comment') comment1 = createObject('plone.Comment')
comment1.title = 'Comment 1' comment1.title = 'Comment 1'
@ -569,24 +588,30 @@ class ConversationTest(PloneTestCase):
new_comment3_id = conversation.addComment(comment3) new_comment3_id = conversation.addComment(comment3)
# check if the latest comment is exactly one day old # 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() -
self.assert_(conversation.last_comment_date > datetime.now() - timedelta(days=1, seconds=1)) timedelta(hours=23, minutes=59, seconds=59))
self.assert_(conversation.last_comment_date >
datetime.now() - timedelta(days=1, seconds=1))
# remove the latest comment # remove the latest comment
del conversation[new_comment3_id] del conversation[new_comment3_id]
# check if the latest comment has been updated # check if the latest comment has been updated
# the latest comment should be exactly two days old # 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() -
self.assert_(conversation.last_comment_date > datetime.now() - timedelta(days=2, seconds=1)) 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 # remove the latest comment again
del conversation[new_comment2_id] del conversation[new_comment2_id]
# check if the latest comment has been updated # check if the latest comment has been updated
# the latest comment should be exactly four days old # 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() -
self.assert_(conversation.last_comment_date > datetime.now() - timedelta(days=4, seconds=2)) 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): def test_get_comments_full(self):
pass pass
@ -672,16 +697,20 @@ class ConversationTest(PloneTestCase):
def test_traversal(self): def test_traversal(self):
# make sure we can traverse to conversations and get a URL and path # 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.assert_(IConversation.providedBy(conversation))
self.assertEquals(('', 'plone', 'doc1', '++conversation++default'), conversation.getPhysicalPath()) self.assertEquals(('', 'plone', 'doc1', '++conversation++default'),
# XXX: conversation.absolute_url() returns different values dependent on conversation.getPhysicalPath())
# the Plone version used. # XXX: conversation.absolute_url() returns different values dependent
# on the Plone version used.
# Plone 3.3: # 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: # 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): def test_parent(self):
# Check that conversation has a content object as parent # Check that conversation has a content object as parent
@ -815,14 +844,17 @@ class RepliesTest(PloneTestCase):
# Create the nested comment structure # Create the nested comment structure
new_id_1 = replies.addComment(comment1) 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) replies_to_comment1 = IReplies(comment1)
new_id_2 = replies.addComment(comment2) 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) replies_to_comment2 = IReplies(comment2)
new_id_1_1 = replies_to_comment1.addComment(comment1_1) 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 = IReplies(comment1_1)
replies_to_comment1_1.addComment(comment1_1_1) replies_to_comment1_1.addComment(comment1_1_1)

View File

@ -1,3 +1,6 @@
"""Test for the plone.app.discussion indexers
"""
import unittest import unittest
from datetime import datetime from datetime import datetime
@ -14,8 +17,20 @@ from plone.indexer.delegate import DelegatingIndexerFactory
from plone.app.discussion import catalog 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): class ConversationIndexersTest(PloneTestCase):
"""Conversation Indexer Tests
"""
layer = DiscussionLayer layer = DiscussionLayer
@ -58,7 +73,8 @@ class ConversationIndexersTest(PloneTestCase):
self.conversation = conversation self.conversation = conversation
def test_conversation_total_comments(self): 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) self.assertEquals(catalog.total_comments(self.portal.doc1)(), 3)
del self.conversation[self.new_id1] del self.conversation[self.new_id1]
self.assertEquals(catalog.total_comments(self.portal.doc1)(), 2) 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) self.assertEquals(catalog.total_comments(self.portal.doc1)(), 0)
def test_conversation_last_comment_date(self): def test_conversation_last_comment_date(self):
self.assert_(isinstance(catalog.last_comment_date, DelegatingIndexerFactory)) self.assert_(isinstance(catalog.last_comment_date,
self.assertEquals(catalog.last_comment_date(self.portal.doc1)(), datetime(2009, 4, 12, 11, 12, 12)) DelegatingIndexerFactory))
self.assertEquals(catalog.last_comment_date(self.portal.doc1)(),
datetime(2009, 4, 12, 11, 12, 12))
del self.conversation[self.new_id3] 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_id2]
del self.conversation[self.new_id1] del self.conversation[self.new_id1]
self.assertEquals(catalog.last_comment_date(self.portal.doc1)(), None) self.assertEquals(catalog.last_comment_date(self.portal.doc1)(), None)
def test_conversation_commentators(self): def test_conversation_commentators(self):
pass pass
#self.assertEquals(catalog.commentators(self.portal.doc1)(), ('Jim', 'Emma', 'Lukas')) #self.assertEquals(catalog.commentators(self.portal.doc1)(),
#self.assert_(isinstance(catalog.commentators, DelegatingIndexerFactory)) # ('Jim', 'Emma', 'Lukas'))
#self.assert_(isinstance(catalog.commentators,
# DelegatingIndexerFactory))
class CommentIndexersTest(PloneTestCase): class CommentIndexersTest(PloneTestCase):
@ -94,8 +115,8 @@ class CommentIndexersTest(PloneTestCase):
# object, as we just want to check the Conversation object API. # object, as we just want to check the Conversation object API.
conversation = IConversation(self.portal.doc1) conversation = IConversation(self.portal.doc1)
# Add a comment. Note: in real life, we always create comments via the factory # Add a comment. Note: in real life, we always create comments via the
# to allow different factories to be swapped in # factory to allow different factories to be swapped in
comment = createObject('plone.Comment') comment = createObject('plone.Comment')
comment.title = 'Comment 1' comment.title = 'Comment 1'
@ -104,9 +125,7 @@ class CommentIndexersTest(PloneTestCase):
comment.creation_date = datetime(2006, 9, 17, 14, 18, 12) comment.creation_date = datetime(2006, 9, 17, 14, 18, 12)
comment.modification_date = datetime(2008, 3, 12, 7, 32, 52) comment.modification_date = datetime(2008, 3, 12, 7, 32, 52)
new_id = conversation.addComment(comment) self.comment_id = conversation.addComment(comment)
self.comment_id = new_id
self.comment = comment.__of__(conversation) self.comment = comment.__of__(conversation)
self.conversation = conversation self.conversation = conversation
@ -115,7 +134,8 @@ class CommentIndexersTest(PloneTestCase):
self.assert_(isinstance(catalog.title, DelegatingIndexerFactory)) self.assert_(isinstance(catalog.title, DelegatingIndexerFactory))
def test_description(self): 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)) self.assert_(isinstance(catalog.description, DelegatingIndexerFactory))
def test_description_long(self): def test_description_long(self):
@ -123,20 +143,25 @@ class CommentIndexersTest(PloneTestCase):
# only the first 25 words # only the first 25 words
comment_long = createObject('plone.Comment') comment_long = createObject('plone.Comment')
comment_long.title = 'Long 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.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): def test_dates(self):
# Test if created, modified, effective etc. are set correctly # 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.created(self.comment)(),
self.assertEquals(catalog.modified(self.comment)(), DateTime(2008, 3, 12, 7, 32, 52)) 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): def test_searchable_text(self):
# Test if searchable text is a concatenation of title and comment text # 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.assertEquals(catalog.searchable_text(self.comment)(),
self.assert_(isinstance(catalog.searchable_text, DelegatingIndexerFactory)) ('Comment 1', 'Lorem ipsum dolor sit amet.'))
self.assert_(isinstance(catalog.searchable_text,
DelegatingIndexerFactory))
def test_creator(self): def test_creator(self):
self.assertEquals(catalog.creator(self.comment)(), ('Jim')) self.assertEquals(catalog.creator(self.comment)(), ('Jim'))
@ -149,4 +174,4 @@ class CommentIndexersTest(PloneTestCase):
self.assertEquals(catalog.in_response_to(self.comment)(), 'Document 1') self.assertEquals(catalog.in_response_to(self.comment)(), 'Document 1')
def test_suite(): def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__) return unittest.defaultTestLoader.loadTestsFromName(__name__)

View File

@ -34,7 +34,8 @@ class MigrationTest(PloneTestCase):
request.set("test", True) request.set("test", True)
context = getattr(self.portal, 'doc') context = getattr(self.portal, 'doc')
self.view = View(context, request) 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 self.doc = self.portal.doc
@ -57,7 +58,8 @@ class MigrationTest(PloneTestCase):
self.view() self.view()
# Make sure a conversation has been created # 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) conversation = IConversation(self.doc)
# Check migration # Check migration
@ -68,8 +70,10 @@ class MigrationTest(PloneTestCase):
self.assertEquals(comment1.Title(), 'My Title') self.assertEquals(comment1.Title(), 'My Title')
self.assertEquals(comment1.text, 'My Text') self.assertEquals(comment1.text, 'My Text')
self.assertEquals(comment1.Creator(), 'Jim') self.assertEquals(comment1.Creator(), 'Jim')
self.assertEquals(comment1.creation_date, datetime(2003, 3, 11, 9, 28, 6)) self.assertEquals(comment1.creation_date,
self.assertEquals(comment1.modification_date, datetime(2009, 7, 12, 19, 38, 7)) datetime(2003, 3, 11, 9, 28, 6))
self.assertEquals(comment1.modification_date,
datetime(2009, 7, 12, 19, 38, 7))
self.assertEquals( self.assertEquals(
[{'comment': comment1, 'depth': 0, 'id': long(comment1.id)},] [{'comment': comment1, 'depth': 0, 'id': long(comment1.id)},]
, list(conversation.getThreads())) , list(conversation.getThreads()))
@ -149,19 +153,19 @@ class MigrationTest(PloneTestCase):
comment2 = conversation.values()[7] comment2 = conversation.values()[7]
self.assertEquals( self.assertEquals(
[{'comment': comment1, 'depth': 0, 'id': long(comment1.id)}, [{'comment': comment1, 'depth': 0, 'id': long(comment1.id)},
{'comment': comment1_1, 'depth': 1, 'id': long(comment1_1.id)}, {'comment': comment1_1, 'depth': 1, 'id': long(comment1_1.id)},
{'comment': comment1_1_1, 'depth': 2, 'id': long(comment1_1_1.id)}, {'comment': comment1_1_1, 'depth': 2, 'id': long(comment1_1_1.id)},
{'comment': comment1_1_1_1, 'depth': 3, 'id': long(comment1_1_1_1.id)}, {'comment': comment1_1_1_1, 'depth': 3, 'id': long(comment1_1_1_1.id)},
{'comment': comment1_2, 'depth': 1, 'id': long(comment1_2.id)}, {'comment': comment1_2, 'depth': 1, 'id': long(comment1_2.id)},
{'comment': comment1_3, 'depth': 1, 'id': long(comment1_3.id)}, {'comment': comment1_3, 'depth': 1, 'id': long(comment1_3.id)},
{'comment': comment1_4, 'depth': 1, 'id': long(comment1_4.id)}, {'comment': comment1_4, 'depth': 1, 'id': long(comment1_4.id)},
{'comment': comment2, 'depth': 0, 'id': long(comment2.id)}, {'comment': comment2, 'depth': 0, 'id': long(comment2.id)},
], list(conversation.getThreads())) ], list(conversation.getThreads()))
talkback = self.discussion.getDiscussionFor(self.doc) talkback = self.discussion.getDiscussionFor(self.doc)
self.assertEquals(len(talkback.getReplies()), 0) self.assertEquals(len(talkback.getReplies()), 0)
def test_suite(): def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__) return unittest.defaultTestLoader.loadTestsFromName(__name__)

View File

@ -45,4 +45,4 @@ class ToolTest(PloneTestCase):
pass pass
def test_suite(): def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__) return unittest.defaultTestLoader.loadTestsFromName(__name__)

View File

@ -26,14 +26,18 @@ class WorkflowTest(PloneTestCase):
def test_permission(self): def test_permission(self):
self.setRoles(('Reviewer',)) 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.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): 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.assertEquals(('one_state_workflow',),
self.portal.portal_workflow.getChainForPortalType('Discussion Item')) self.portal.portal_workflow.getChainForPortalType(
'Discussion Item'))
class TestCommentOperations(PloneTestCase): class TestCommentOperations(PloneTestCase):
@ -46,8 +50,9 @@ class TestCommentOperations(PloneTestCase):
# 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
# Set workflow for Discussion item to review workflow # Set workflow for Discussion item to review workflow
self.portal.portal_workflow.setChainForPortalTypes(('Discussion Item',), self.portal.portal_workflow.setChainForPortalTypes(
('comment_review_workflow',)) ('Discussion Item',),
('comment_review_workflow',))
# Create a Document # Create a Document
self.portal.invokeFactory('Document', 'doc1') self.portal.invokeFactory('Document', 'doc1')
@ -61,7 +66,8 @@ class TestCommentOperations(PloneTestCase):
comment.title = 'Comment 1' comment.title = 'Comment 1'
comment.text = 'Comment text' comment.text = 'Comment text'
comment_id = conversation.addComment(comment) 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.conversation = conversation
self.comment_id = comment_id self.comment_id = comment_id
@ -98,20 +104,25 @@ class TestCommentOperations(PloneTestCase):
def test_publish(self): def test_publish(self):
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.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.comment.restrictedTraverse('@@moderate-publish-comment')
view() 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): def test_publish_as_anonymous(self):
self.logout() self.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.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.assertRaises(Unauthorized,
self.comment.restrictedTraverse, self.comment.restrictedTraverse,
'@@moderate-publish-comment') '@@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(): def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__) return unittest.defaultTestLoader.loadTestsFromName(__name__)