fix conversation.__delitem__ function and add test for deleting comments from a conversation.

svn path=/plone.app.discussion/trunk/; revision=27062
This commit is contained in:
Timo Stollenwerk 2009-05-23 14:18:35 +00:00
parent 2ff696a252
commit 8282307e0a
2 changed files with 99 additions and 76 deletions

View File

@ -176,7 +176,8 @@ class Conversation(Traversable, Persistent, Explicit):
commentator = comment.author_username
notify(ObjectWillBeRemovedEvent(comment, self, key))
self._comments.remove(key)
self._comments.pop(key)
notify(ObjectRemovedEvent(comment, self, key))
if commentator and commentator in self._commentators:

View File

@ -48,7 +48,29 @@ class ConversationTest(PloneTestCase):
self.assert_(conversation.last_comment_date - datetime.now() < timedelta(seconds=1))
def test_delete_comment(self):
pass
# 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)
# 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)
self.assertEquals(len(conversation.getThreads()), 0)
self.assertEquals(conversation.total_comments, 0)
def test_dict_operations(self):
# test dict operations and acquisition wrapping