2009-05-18 17:15:36 +02:00
|
|
|
import unittest
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
|
|
from zope.component import createObject
|
|
|
|
|
|
|
|
from Acquisition import aq_base
|
|
|
|
|
|
|
|
from Products.PloneTestCase.ptc import PloneTestCase
|
|
|
|
from plone.app.discussion.tests.layer import DiscussionLayer
|
|
|
|
|
|
|
|
from plone.app.discussion.interfaces import IConversation, IComment
|
|
|
|
|
|
|
|
class ConversationTest(PloneTestCase):
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
layer = DiscussionLayer
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def afterSetUp(self):
|
|
|
|
# First we need to create some content.
|
|
|
|
self.loginAsPortalOwner()
|
|
|
|
typetool = self.portal.portal_types
|
|
|
|
typetool.constructContent('Document', self.portal, 'doc1')
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
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)
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
# Pretend that we have traversed to the comment by aq wrapping it.
|
|
|
|
conversation = conversation.__of__(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
|
|
|
|
|
|
|
|
comment = createObject('plone.Comment')
|
|
|
|
comment.title = 'Comment 1'
|
|
|
|
comment.text = 'Comment text'
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
new_id = conversation.addComment(comment)
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
# 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(new_id, comment.comment_id)
|
|
|
|
self.assertEquals(len(conversation.getComments()), 1)
|
2009-05-23 18:28:10 +02:00
|
|
|
# XXX: not yet implemented
|
2009-05-23 18:12:13 +02:00
|
|
|
# self.assertEquals(len(conversation.getThreads()), 1)
|
2009-05-18 17:15:36 +02:00
|
|
|
self.assertEquals(conversation.total_comments, 1)
|
|
|
|
self.assert_(conversation.last_comment_date - datetime.now() < timedelta(seconds=1))
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-23 13:52:57 +02:00
|
|
|
def test_delete_comment(self):
|
2009-05-23 16:18:35 +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)
|
|
|
|
|
|
|
|
# Pretend that we have traversed to the comment by aq wrapping it.
|
|
|
|
conversation = conversation.__of__(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
|
|
|
|
|
|
|
|
comment = createObject('plone.Comment')
|
|
|
|
comment.title = 'Comment 1'
|
|
|
|
comment.text = 'Comment text'
|
|
|
|
|
|
|
|
new_id = conversation.addComment(comment)
|
|
|
|
|
2009-05-23 16:24:24 +02:00
|
|
|
# make sure the comment has been added
|
|
|
|
self.assertEquals(len(conversation.getComments()), 1)
|
2009-05-23 18:12:13 +02:00
|
|
|
# XXX: not yet implemented
|
|
|
|
# self.assertEquals(len(conversation.getThreads()), 1)
|
2009-05-23 16:24:24 +02:00
|
|
|
self.assertEquals(conversation.total_comments, 1)
|
|
|
|
|
2009-05-23 16:18:35 +02:00
|
|
|
# delete the comment we just created
|
|
|
|
conversation.__delitem__(new_id)
|
|
|
|
|
|
|
|
# make sure there is no comment left in the conversation
|
|
|
|
self.assertEquals(len(conversation.getComments()), 0)
|
2009-05-23 18:28:10 +02:00
|
|
|
|
2009-05-23 18:12:13 +02:00
|
|
|
# XXX: not yet implemented
|
|
|
|
# self.assertEquals(len(conversation.getThreads()), 0)
|
2009-05-23 16:18:35 +02:00
|
|
|
self.assertEquals(conversation.total_comments, 0)
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_dict_operations(self):
|
2009-05-20 17:39:45 +02:00
|
|
|
# test dict operations and acquisition wrapping
|
2009-05-18 17:15:36 +02:00
|
|
|
pass
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_total_comments(self):
|
2009-05-20 17:39:45 +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)
|
|
|
|
|
|
|
|
# Pretend that we have traversed to the comment by aq wrapping it.
|
|
|
|
conversation = conversation.__of__(self.portal.doc1)
|
|
|
|
|
2009-05-20 18:07:29 +02:00
|
|
|
# Add a three comments. Note: in real life, we always create
|
|
|
|
# comments via the factory to allow different factories to be
|
|
|
|
# swapped in
|
2009-05-20 17:39:45 +02:00
|
|
|
|
|
|
|
comment1 = createObject('plone.Comment')
|
|
|
|
comment1.title = 'Comment 1'
|
|
|
|
comment1.text = 'Comment text'
|
|
|
|
|
|
|
|
comment2 = createObject('plone.Comment')
|
|
|
|
comment2.title = 'Comment 2'
|
|
|
|
comment2.text = 'Comment text'
|
|
|
|
|
|
|
|
comment3 = createObject('plone.Comment')
|
|
|
|
comment3.title = 'Comment 3'
|
|
|
|
comment3.text = 'Comment text'
|
|
|
|
|
|
|
|
new_comment1_id = conversation.addComment(comment1)
|
|
|
|
new_comment2_id = conversation.addComment(comment2)
|
|
|
|
new_comment3_id = conversation.addComment(comment3)
|
|
|
|
|
2009-05-20 18:07:29 +02:00
|
|
|
self.assertEquals(conversation.total_comments, 3)
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_commentators(self):
|
2009-05-20 17:39:45 +02:00
|
|
|
# add and remove a few comments to make sure the commentators
|
2009-05-18 17:15:36 +02:00
|
|
|
# property returns a true set
|
2009-05-23 18:28:10 +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)
|
|
|
|
|
|
|
|
# Pretend that we have traversed to the comment by aq wrapping it.
|
|
|
|
conversation = conversation.__of__(self.portal.doc1)
|
|
|
|
|
2009-05-23 19:17:06 +02:00
|
|
|
# Add a four comments from three different users
|
2009-05-23 18:28:10 +02:00
|
|
|
# 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'
|
|
|
|
comment1.text = 'Comment text'
|
|
|
|
comment1.author_username = "Jim"
|
|
|
|
new_comment1_id = conversation.addComment(comment1)
|
|
|
|
|
|
|
|
comment2 = createObject('plone.Comment')
|
|
|
|
comment2.title = 'Comment 2'
|
|
|
|
comment2.text = 'Comment text'
|
|
|
|
comment2.author_username = "Joe"
|
|
|
|
new_comment2_id = conversation.addComment(comment2)
|
|
|
|
|
|
|
|
comment3 = createObject('plone.Comment')
|
|
|
|
comment3.title = 'Comment 3'
|
|
|
|
comment3.text = 'Comment text'
|
|
|
|
comment3.author_username = "Jack"
|
|
|
|
new_comment3_id = conversation.addComment(comment3)
|
|
|
|
|
2009-05-23 19:17:06 +02:00
|
|
|
comment4 = createObject('plone.Comment')
|
|
|
|
comment4.title = 'Comment 3'
|
|
|
|
comment4.text = 'Comment text'
|
|
|
|
comment4.author_username = "Jack"
|
|
|
|
new_comment4_id = conversation.addComment(comment4)
|
|
|
|
|
2009-05-23 18:28:10 +02:00
|
|
|
# check if all commentators are in the commentators list
|
2009-05-23 19:17:06 +02:00
|
|
|
self.assertEquals(conversation.total_comments, 4)
|
|
|
|
self.failUnless('Jim' in conversation.commentators)
|
|
|
|
self.failUnless('Joe' in conversation.commentators)
|
|
|
|
self.failUnless('Jack' in conversation.commentators)
|
|
|
|
|
|
|
|
# remove the comment from Jack
|
|
|
|
del conversation[new_comment3_id]
|
|
|
|
|
|
|
|
# check if Jack is still in the commentators list (since
|
|
|
|
# he had added two comments)
|
|
|
|
self.failUnless('Jim' in conversation.commentators)
|
|
|
|
self.failUnless('Joe' in conversation.commentators)
|
|
|
|
self.failUnless('Jack' in conversation.commentators)
|
2009-05-23 18:28:10 +02:00
|
|
|
self.assertEquals(conversation.total_comments, 3)
|
|
|
|
|
2009-05-23 19:17:06 +02:00
|
|
|
# remove the second comment from Jack
|
|
|
|
del conversation[new_comment4_id]
|
2009-05-23 18:28:10 +02:00
|
|
|
|
2009-05-23 19:17:06 +02:00
|
|
|
# check if Jack has been removed from the commentators list
|
|
|
|
self.failUnless('Jim' in conversation.commentators)
|
|
|
|
self.failUnless('Joe' in conversation.commentators)
|
|
|
|
self.failIf('Jack' in conversation.commentators)
|
2009-05-23 18:28:10 +02:00
|
|
|
self.assertEquals(conversation.total_comments, 2)
|
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_last_comment_date(self):
|
2009-05-20 17:39:45 +02:00
|
|
|
pass
|
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_get_comments_flat(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_get_comments_batched(self):
|
2009-05-23 06:55:06 +02:00
|
|
|
pass
|
2009-05-18 17:15:36 +02:00
|
|
|
|
|
|
|
def test_get_threads(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_get_threads_batched(self):
|
|
|
|
pass
|
2009-05-23 16:18:35 +02:00
|
|
|
|
2009-05-23 13:52:57 +02:00
|
|
|
def test_traversal(self):
|
|
|
|
# make sure we can traverse to conversations and get a URL and path
|
2009-05-23 16:18:35 +02:00
|
|
|
|
|
|
|
conversation = self.portal.doc1.restrictedTraverse('++conversation++default')
|
2009-05-23 13:52:57 +02:00
|
|
|
self.assert_(IConversation.providedBy(conversation))
|
2009-05-23 16:18:35 +02:00
|
|
|
|
2009-05-23 13:52:57 +02:00
|
|
|
self.assertEquals(('', 'plone', 'doc1', '++conversation++default'), conversation.getPhysicalPath())
|
|
|
|
self.assertEquals('plone/doc1/%2B%2Bconversation%2B%2Bdefault', conversation.absolute_url())
|
2009-05-18 17:15:36 +02:00
|
|
|
|
|
|
|
class RepliesTest(PloneTestCase):
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
# test the IReplies adapter on a conversation
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
layer = DiscussionLayer
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def afterSetUp(self):
|
|
|
|
# First we need to create some content.
|
|
|
|
self.loginAsPortalOwner()
|
|
|
|
typetool = self.portal.portal_types
|
|
|
|
typetool.constructContent('Document', self.portal, 'doc1')
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_add_comment(self):
|
|
|
|
pass
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_delete_comment(self):
|
|
|
|
pass
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_dict_api(self):
|
|
|
|
# ensure all operations use only top-level comments
|
|
|
|
pass
|
2009-05-20 17:39:45 +02:00
|
|
|
|
2009-05-18 17:15:36 +02:00
|
|
|
def test_suite():
|
|
|
|
return unittest.defaultTestLoader.loadTestsFromName(__name__)
|