From ca0e299cdc17b5ae6da7c4fa0f03d908ad78cdd3 Mon Sep 17 00:00:00 2001 From: Martin Aspeli Date: Sun, 24 May 2009 14:19:06 +0000 Subject: [PATCH] Fix dodgy IReplies adapter svn path=/plone.app.discussion/trunk/; revision=27085 --- plone/app/discussion/conversation.py | 12 +++++++---- .../app/discussion/tests/test_conversation.py | 20 +++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/plone/app/discussion/conversation.py b/plone/app/discussion/conversation.py index 04b752f..b0a5d05 100644 --- a/plone/app/discussion/conversation.py +++ b/plone/app/discussion/conversation.py @@ -241,7 +241,7 @@ class ConversationReplies(object): def __init__(self, context): self.conversation = context - self.children = self.conversation._children.get(0, LLSet()) + self.comment_id = 0l def addComment(self, comment): comment.in_reply_to = None @@ -299,7 +299,13 @@ class ConversationReplies(object): def iteritems(self): for key in self.children: yield (key, self.conversation[key],) - + + @property + def children(self): + # we need to look this up every time, because we may not have a + # dict yet when the adapter is first created + return self.conversation._children.get(self.comment_id, LLSet()) + class CommentReplies(ConversationReplies): """An IReplies adapter for comments. @@ -314,7 +320,6 @@ class CommentReplies(ConversationReplies): adapts(Comment) - def __init__(self, context): self.comment = context self.conversation = self.comment.__parent__ @@ -323,7 +328,6 @@ class CommentReplies(ConversationReplies): raise TypeError("This adapter doesn't know what to do with the parent conversation") self.comment_id = self.comment.comment_id - self.children = self.conversation._children.get(self.comment_id, LLSet()) def addComment(self, comment): comment.in_reply_to = self.comment_id diff --git a/plone/app/discussion/tests/test_conversation.py b/plone/app/discussion/tests/test_conversation.py index b978dcc..18eb5b4 100644 --- a/plone/app/discussion/tests/test_conversation.py +++ b/plone/app/discussion/tests/test_conversation.py @@ -74,7 +74,7 @@ class ConversationTest(PloneTestCase): self.assertEquals(conversation.total_comments, 1) # delete the comment we just created - conversation.__delitem__(new_id) + del conversation[new_id] # make sure there is no comment left in the conversation self.assertEquals(len(conversation.getComments()), 0) @@ -344,20 +344,24 @@ class RepliesTest(PloneTestCase): new_id = replies.addComment(comment) - # check that replies is a ConversationReplies object - self.assert_(isinstance(replies, ConversationReplies)) - # check that replies provides the IReplies interface self.assert_(IReplies.providedBy(replies)) - - # TODO: Is this correct? How do I test the ConversationReplies? - # replies.items() is empty! + + # Make sure our comment was added + self.failUnless(new_id in replies) + + # Make sure it is also reflected in the conversation + self.failUnless(new_id in conversation) + + self.assertEquals(conversation[new_id].comment_id, new_id) def test_delete_comment(self): pass def test_dict_api(self): - # ensure all operations use only top-level comments + # ensure all operations use only top-level comments. Add some + # deeper children and ensure that these are not exposed through the + # IReplies dict. pass def test_suite():