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
+73 -41
View File
@@ -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)