Fix dodgy IReplies adapter

svn path=/plone.app.discussion/trunk/; revision=27085
This commit is contained in:
Martin Aspeli 2009-05-24 14:19:06 +00:00
parent 69ab219582
commit ca0e299cdc
2 changed files with 20 additions and 12 deletions

View File

@ -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
@ -300,6 +300,12 @@ class ConversationReplies(object):
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

View File

@ -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():