Fix dodgy IReplies adapter
svn path=/plone.app.discussion/trunk/; revision=27085
This commit is contained in:
parent
69ab219582
commit
ca0e299cdc
@ -241,7 +241,7 @@ class ConversationReplies(object):
|
|||||||
|
|
||||||
def __init__(self, context):
|
def __init__(self, context):
|
||||||
self.conversation = context
|
self.conversation = context
|
||||||
self.children = self.conversation._children.get(0, LLSet())
|
self.comment_id = 0l
|
||||||
|
|
||||||
def addComment(self, comment):
|
def addComment(self, comment):
|
||||||
comment.in_reply_to = None
|
comment.in_reply_to = None
|
||||||
@ -300,6 +300,12 @@ class ConversationReplies(object):
|
|||||||
for key in self.children:
|
for key in self.children:
|
||||||
yield (key, self.conversation[key],)
|
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):
|
class CommentReplies(ConversationReplies):
|
||||||
"""An IReplies adapter for comments.
|
"""An IReplies adapter for comments.
|
||||||
|
|
||||||
@ -314,7 +320,6 @@ class CommentReplies(ConversationReplies):
|
|||||||
|
|
||||||
adapts(Comment)
|
adapts(Comment)
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, context):
|
def __init__(self, context):
|
||||||
self.comment = context
|
self.comment = context
|
||||||
self.conversation = self.comment.__parent__
|
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")
|
raise TypeError("This adapter doesn't know what to do with the parent conversation")
|
||||||
|
|
||||||
self.comment_id = self.comment.comment_id
|
self.comment_id = self.comment.comment_id
|
||||||
self.children = self.conversation._children.get(self.comment_id, LLSet())
|
|
||||||
|
|
||||||
def addComment(self, comment):
|
def addComment(self, comment):
|
||||||
comment.in_reply_to = self.comment_id
|
comment.in_reply_to = self.comment_id
|
||||||
|
@ -74,7 +74,7 @@ class ConversationTest(PloneTestCase):
|
|||||||
self.assertEquals(conversation.total_comments, 1)
|
self.assertEquals(conversation.total_comments, 1)
|
||||||
|
|
||||||
# delete the comment we just created
|
# delete the comment we just created
|
||||||
conversation.__delitem__(new_id)
|
del conversation[new_id]
|
||||||
|
|
||||||
# make sure there is no comment left in the conversation
|
# make sure there is no comment left in the conversation
|
||||||
self.assertEquals(len(conversation.getComments()), 0)
|
self.assertEquals(len(conversation.getComments()), 0)
|
||||||
@ -344,20 +344,24 @@ class RepliesTest(PloneTestCase):
|
|||||||
|
|
||||||
new_id = replies.addComment(comment)
|
new_id = replies.addComment(comment)
|
||||||
|
|
||||||
# check that replies is a ConversationReplies object
|
|
||||||
self.assert_(isinstance(replies, ConversationReplies))
|
|
||||||
|
|
||||||
# check that replies provides the IReplies interface
|
# check that replies provides the IReplies interface
|
||||||
self.assert_(IReplies.providedBy(replies))
|
self.assert_(IReplies.providedBy(replies))
|
||||||
|
|
||||||
# TODO: Is this correct? How do I test the ConversationReplies?
|
# Make sure our comment was added
|
||||||
# replies.items() is empty!
|
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):
|
def test_delete_comment(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_dict_api(self):
|
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
|
pass
|
||||||
|
|
||||||
def test_suite():
|
def test_suite():
|
||||||
|
Loading…
Reference in New Issue
Block a user