2010-10-02 20:16:49 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2010-09-07 14:02:55 +02:00
|
|
|
import datetime
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from zope.component import createObject
|
|
|
|
|
2009-05-27 19:05:12 +02:00
|
|
|
from zope.component import getMultiAdapter
|
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
from Products.PloneTestCase.ptc import PloneTestCase
|
2009-06-22 19:06:37 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
from plone.app.discussion.tests.layer import DiscussionLayer
|
|
|
|
|
2009-05-25 09:02:11 +02:00
|
|
|
from plone.app.discussion.interfaces import IComment, IConversation, IReplies
|
2009-05-18 17:15:36 +02:00
|
|
|
|
2010-09-03 23:23:44 +02:00
|
|
|
from plone.app.discussion.browser.comment import View
|
|
|
|
|
2010-09-02 22:00:43 +02:00
|
|
|
|
2010-09-07 14:02:55 +02:00
|
|
|
logger = logging.getLogger('plone.app.discussion.tests')
|
|
|
|
logger.addHandler(logging.StreamHandler())
|
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
class CommentTest(PloneTestCase):
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
layer = DiscussionLayer
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def afterSetUp(self):
|
2010-09-29 09:56:36 +02:00
|
|
|
"""Create a document.
|
|
|
|
"""
|
2009-05-18 17:15:36 +02:00
|
|
|
self.loginAsPortalOwner()
|
2010-09-29 09:56:36 +02:00
|
|
|
self.portal.invokeFactory(id='doc1',
|
|
|
|
title='Document 1',
|
|
|
|
type_name='Document')
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_factory(self):
|
2009-05-23 13:52:57 +02:00
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
self.assert_(IComment.providedBy(comment1))
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2010-09-07 14:02:55 +02:00
|
|
|
def test_UTCDates(self):
|
|
|
|
utc_to_local_diff = datetime.datetime.now() - datetime.datetime.utcnow()
|
|
|
|
utc_to_local_diff = abs(utc_to_local_diff.seconds)
|
|
|
|
if utc_to_local_diff < 60:
|
|
|
|
logger.warning("Your computer is living in a timezone where local "
|
|
|
|
"time equals utc time. Some potential errors can "
|
|
|
|
"get hidden by that")
|
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
local_utc = datetime.datetime.utcnow()
|
|
|
|
for date in (comment1.creation_date, comment1.modification_date):
|
|
|
|
difference = abs(date - local_utc)
|
|
|
|
difference = difference.seconds
|
|
|
|
# We hope that between comment1 and local_utc happen less than
|
|
|
|
# 10 seconds
|
|
|
|
self.assertFalse(difference / 10)
|
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_id(self):
|
2009-05-23 13:52:57 +02:00
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
comment1.comment_id = 123
|
|
|
|
self.assertEquals('123', comment1.id)
|
|
|
|
self.assertEquals('123', comment1.getId())
|
|
|
|
self.assertEquals(u'123', comment1.__name__)
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_title(self):
|
2010-09-29 09:56:36 +02:00
|
|
|
conversation = IConversation(self.portal.doc1)
|
2009-05-23 13:52:57 +02:00
|
|
|
comment1 = createObject('plone.Comment')
|
2010-09-29 09:56:36 +02:00
|
|
|
comment1.creator = "Jim Fulton"
|
|
|
|
conversation.addComment(comment1)
|
|
|
|
self.assertEquals("Jim Fulton on Document 1", comment1.Title())
|
2010-09-29 12:52:11 +02:00
|
|
|
|
|
|
|
def test_no_name_title(self):
|
|
|
|
conversation = IConversation(self.portal.doc1)
|
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
conversation.addComment(comment1)
|
|
|
|
self.assertEquals("Anonymous on Document 1", comment1.Title())
|
|
|
|
|
2010-10-02 20:16:49 +02:00
|
|
|
def test_title_special_characters(self):
|
|
|
|
self.portal.invokeFactory(id='doc_sp_chars',
|
2010-10-04 15:48:27 +02:00
|
|
|
title=u'Document äüö',
|
2010-10-02 20:16:49 +02:00
|
|
|
type_name='Document')
|
|
|
|
conversation = IConversation(self.portal.doc_sp_chars)
|
|
|
|
comment1 = createObject('plone.Comment')
|
2010-10-04 15:48:27 +02:00
|
|
|
comment1.creator = u"Tarek Ziadé"
|
2010-10-02 20:16:49 +02:00
|
|
|
conversation.addComment(comment1)
|
|
|
|
self.assertEquals(u"Tarek Ziadé on Document äüö", comment1.Title())
|
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_creator(self):
|
2009-05-23 13:52:57 +02:00
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
comment1.creator = "Jim"
|
|
|
|
self.assertEquals("Jim", comment1.Creator())
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-06-22 14:23:19 +02:00
|
|
|
def test_type(self):
|
|
|
|
comment1 = createObject('plone.Comment')
|
2010-03-18 15:42:52 +01:00
|
|
|
self.assertEquals(comment1.Type(), 'Comment')
|
2009-06-22 14:23:19 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_traversal(self):
|
2010-08-28 19:06:53 +02:00
|
|
|
# make sure comments are traversable, have an id, absolute_url and
|
|
|
|
# physical path
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-06-18 22:57:47 +02:00
|
|
|
conversation = IConversation(self.portal.doc1)
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-05-23 13:52:57 +02:00
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
comment1.title = 'Comment 1'
|
|
|
|
comment1.text = 'Comment text'
|
|
|
|
|
|
|
|
new_comment1_id = conversation.addComment(comment1)
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2010-08-28 19:06:53 +02:00
|
|
|
comment = self.portal.doc1.restrictedTraverse(
|
|
|
|
'++conversation++default/%s' % new_comment1_id)
|
2009-05-23 13:52:57 +02:00
|
|
|
self.assert_(IComment.providedBy(comment))
|
|
|
|
self.assertEquals('Comment 1', comment.title)
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2010-08-28 19:06:53 +02:00
|
|
|
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())
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_workflow(self):
|
2010-08-28 19:06:53 +02:00
|
|
|
self.portal.portal_workflow.setChainForPortalTypes(
|
|
|
|
('Discussion Item',),
|
|
|
|
('simple_publication_workflow,'))
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-06-18 22:57:47 +02:00
|
|
|
conversation = IConversation(self.portal.doc1)
|
2009-05-23 18:37:10 +02:00
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
new_comment1_id = conversation.addComment(comment1)
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-05-23 18:37:10 +02:00
|
|
|
comment = conversation[new_comment1_id]
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-05-23 18:37:10 +02:00
|
|
|
chain = self.portal.portal_workflow.getChainFor(comment)
|
|
|
|
self.assertEquals(('simple_publication_workflow',), chain)
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-05-23 18:37:10 +02:00
|
|
|
# ensure the initial state was entered and recorded
|
2010-08-28 19:06:53 +02:00
|
|
|
self.assertEquals(1,
|
|
|
|
len(comment.workflow_history['simple_publication_workflow']))
|
|
|
|
self.assertEquals(None,
|
|
|
|
comment.workflow_history['simple_publication_workflow'][0]\
|
|
|
|
['action'])
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2010-08-28 19:06:53 +02:00
|
|
|
self.assertEquals('private',
|
|
|
|
self.portal.portal_workflow.getInfoFor(comment, 'review_state'))
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_fti(self):
|
|
|
|
# test that we can look up an FTI for Discussion Item
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-05-23 18:12:45 +02:00
|
|
|
self.assert_("Discussion Item" in self.portal.portal_types.objectIds())
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-05-23 18:12:45 +02:00
|
|
|
comment1 = createObject('plone.Comment')
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-05-23 18:12:45 +02:00
|
|
|
fti = self.portal.portal_types.getTypeInfo(comment1)
|
|
|
|
self.assertEquals('Discussion Item', fti.getTypeInfo(comment1).getId())
|
2009-05-18 17:15:36 +02:00
|
|
|
|
2009-05-27 19:05:12 +02:00
|
|
|
def test_view(self):
|
2010-08-28 19:06:53 +02:00
|
|
|
# make sure that the comment view is there and redirects to the right
|
|
|
|
# URL
|
2009-05-27 19:05:12 +02:00
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
# Create a comment
|
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
comment1.title = 'Comment 1'
|
|
|
|
comment1.text = 'Comment text'
|
|
|
|
|
|
|
|
# Add comment to the conversation
|
|
|
|
new_comment1_id = conversation.addComment(comment1)
|
|
|
|
|
2010-08-28 19:06:53 +02:00
|
|
|
comment = self.portal.doc1.restrictedTraverse(
|
|
|
|
'++conversation++default/%s' % new_comment1_id)
|
2009-05-27 19:05:12 +02:00
|
|
|
|
|
|
|
# make sure the view is there
|
2010-08-28 19:06:53 +02:00
|
|
|
self.failUnless(getMultiAdapter((comment, self.app.REQUEST),
|
|
|
|
name='view'))
|
2009-05-27 19:05:12 +02:00
|
|
|
|
2010-09-03 23:23:44 +02:00
|
|
|
# make sure the HTTP redirect (status code 302) works when a comment
|
|
|
|
# is called directly
|
|
|
|
view = View(comment, self.app.REQUEST)
|
|
|
|
View.__call__(view)
|
|
|
|
self.assertEquals(self.app.REQUEST.response.status, 302)
|
2009-05-27 19:05:12 +02:00
|
|
|
|
2010-09-02 22:00:43 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
class RepliesTest(PloneTestCase):
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
# test the IReplies adapter on a comment
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
layer = DiscussionLayer
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def afterSetUp(self):
|
|
|
|
# First we need to create some content.
|
|
|
|
self.loginAsPortalOwner()
|
2010-09-29 09:56:36 +02:00
|
|
|
self.portal.invokeFactory(id='doc1',
|
|
|
|
title='Document 1',
|
|
|
|
type_name='Document')
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_add_comment(self):
|
2009-05-25 09:02:11 +02:00
|
|
|
# Add comments to a CommentReplies adapter
|
|
|
|
|
|
|
|
# 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 to the conversation
|
|
|
|
replies = IReplies(conversation)
|
|
|
|
|
|
|
|
comment = createObject('plone.Comment')
|
|
|
|
comment.title = 'Comment 1'
|
|
|
|
comment.text = 'Comment text'
|
|
|
|
new_id = replies.addComment(comment)
|
2010-08-28 19:06:53 +02:00
|
|
|
comment = self.portal.doc1.restrictedTraverse(
|
|
|
|
'++conversation++default/%s' % new_id)
|
2009-05-25 09:02:11 +02:00
|
|
|
|
|
|
|
# Add a reply to the CommentReplies adapter of the first comment
|
|
|
|
re_comment = createObject('plone.Comment')
|
|
|
|
re_comment.title = 'Re: Comment 1'
|
|
|
|
re_comment.text = 'Comment text'
|
|
|
|
|
|
|
|
replies = IReplies(comment)
|
|
|
|
|
|
|
|
new_re_id = replies.addComment(re_comment)
|
|
|
|
|
|
|
|
# check that replies provides the IReplies interface
|
|
|
|
self.assert_(IReplies.providedBy(replies))
|
|
|
|
|
|
|
|
# Make sure our comment was added
|
|
|
|
self.failUnless(new_re_id in replies)
|
|
|
|
|
|
|
|
# Make sure it is also reflected in the conversation
|
|
|
|
self.failUnless(new_re_id in conversation)
|
|
|
|
|
|
|
|
# Make sure the conversation has the correct comment id
|
|
|
|
self.assertEquals(conversation[new_re_id].comment_id, new_re_id)
|
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_delete_comment(self):
|
2009-05-25 09:08:26 +02:00
|
|
|
# Add and remove a comment to a CommentReplies adapter
|
|
|
|
|
|
|
|
# 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 to the conversation
|
|
|
|
replies = IReplies(conversation)
|
|
|
|
|
|
|
|
comment = createObject('plone.Comment')
|
|
|
|
comment.title = 'Comment 1'
|
|
|
|
comment.text = 'Comment text'
|
|
|
|
new_id = replies.addComment(comment)
|
2010-08-28 19:06:53 +02:00
|
|
|
comment = self.portal.doc1.restrictedTraverse(
|
|
|
|
'++conversation++default/%s' % new_id)
|
2009-05-25 09:08:26 +02:00
|
|
|
|
|
|
|
# Add a reply to the CommentReplies adapter of the first comment
|
|
|
|
re_comment = createObject('plone.Comment')
|
|
|
|
re_comment.title = 'Re: Comment 1'
|
|
|
|
re_comment.text = 'Comment text'
|
|
|
|
|
|
|
|
replies = IReplies(comment)
|
|
|
|
|
|
|
|
new_re_id = replies.addComment(re_comment)
|
|
|
|
|
|
|
|
# Remove the reply to the CommentReplies adapter
|
|
|
|
del replies[new_re_id]
|
|
|
|
|
|
|
|
# Make sure there is no comment left in CommentReplies
|
|
|
|
self.assertEquals(len(replies), 0)
|
|
|
|
|
|
|
|
# Make sure the first comment is still in the conversation
|
|
|
|
self.assertEquals(conversation.total_comments, 1)
|
2009-05-25 09:02:11 +02:00
|
|
|
|
2009-06-15 11:06:47 +02:00
|
|
|
def test_traversal(self):
|
|
|
|
# Create a nested structure of comment replies and check the traversal
|
|
|
|
|
2010-08-28 19:06:53 +02:00
|
|
|
# make sure comments are traversable, have an id, absolute_url and
|
|
|
|
# physical path
|
2009-06-18 22:57:47 +02:00
|
|
|
conversation = IConversation(self.portal.doc1)
|
2009-06-15 11:06:47 +02:00
|
|
|
|
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
comment1.title = 'Comment 1'
|
|
|
|
comment1.text = 'Comment text'
|
|
|
|
|
2010-07-13 12:45:53 +02:00
|
|
|
conversation.addComment(comment1)
|
2009-06-15 11:06:47 +02:00
|
|
|
|
|
|
|
comment = createObject('plone.Comment')
|
|
|
|
comment.title = 'Comment 1'
|
|
|
|
comment.text = 'Comment text'
|
|
|
|
new_id = conversation.addComment(comment)
|
2010-08-28 19:06:53 +02:00
|
|
|
comment = self.portal.doc1.restrictedTraverse(
|
|
|
|
'++conversation++default/%s' % new_id)
|
2009-06-15 11:06:47 +02:00
|
|
|
|
|
|
|
# Add a reply to the CommentReplies adapter of the first comment
|
|
|
|
re_comment = createObject('plone.Comment')
|
|
|
|
re_comment.title = 'Re: Comment 1'
|
|
|
|
re_comment.text = 'Comment text'
|
|
|
|
replies = IReplies(comment)
|
|
|
|
new_re_id = replies.addComment(re_comment)
|
2010-08-28 19:06:53 +02:00
|
|
|
re_comment = self.portal.doc1.restrictedTraverse(
|
|
|
|
'++conversation++default/%s' % new_re_id)
|
2009-06-15 11:06:47 +02:00
|
|
|
|
|
|
|
# Add a reply to the reply
|
|
|
|
re_re_comment = createObject('plone.Comment')
|
|
|
|
re_re_comment.title = 'Re: Re: Comment 1'
|
|
|
|
re_re_comment.text = 'Comment text'
|
|
|
|
replies = IReplies(re_comment)
|
|
|
|
new_re_re_id = replies.addComment(re_re_comment)
|
2010-08-28 19:06:53 +02:00
|
|
|
re_re_comment = self.portal.doc1.restrictedTraverse(
|
|
|
|
'++conversation++default/%s' % new_re_re_id)
|
2009-06-15 11:06:47 +02:00
|
|
|
|
|
|
|
# Add a reply to the replies reply
|
|
|
|
re_re_re_comment = createObject('plone.Comment')
|
|
|
|
re_re_re_comment.title = 'Re: Re: Comment 1'
|
|
|
|
re_re_re_comment.text = 'Comment text'
|
|
|
|
replies = IReplies(re_re_comment)
|
|
|
|
new_re_re_re_id = replies.addComment(re_re_re_comment)
|
2010-08-28 19:06:53 +02:00
|
|
|
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())
|
2009-06-15 11:06:47 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_suite():
|
2010-03-18 15:42:52 +01:00
|
|
|
return unittest.defaultTestLoader.loadTestsFromName(__name__)
|