diff --git a/plone/app/discussion/browser/configure.zcml b/plone/app/discussion/browser/configure.zcml index 56a10e2..7666c73 100644 --- a/plone/app/discussion/browser/configure.zcml +++ b/plone/app/discussion/browser/configure.zcml @@ -4,7 +4,7 @@ i18n_domain="plone.app.discussion"> - + count of comments; key is removed when count reaches 0 @@ -71,7 +73,8 @@ class Conversation(Traversable, Persistent, Explicit): self._children = LOBTree() def getId(self): - """Get the id of + """Get the id of the conversation. This is used to construct a + URL. """ return self.id @@ -216,7 +219,8 @@ class Conversation(Traversable, Persistent, Explicit): @implementer(IConversation) @adapter(IAnnotatable) def conversationAdapterFactory(content): - """Adapter factory to fetch a conversation from annotations + """Adapter factory to fetch the default conversation from annotations. + Will create the conversation if it does not exist. """ annotions = IAnnotations(content) if not ANNOTATION_KEY in annotions: diff --git a/plone/app/discussion/tests/test_comment.py b/plone/app/discussion/tests/test_comment.py index bd5e905..2374c93 100644 --- a/plone/app/discussion/tests/test_comment.py +++ b/plone/app/discussion/tests/test_comment.py @@ -6,7 +6,6 @@ from Products.PloneTestCase.ptc import PloneTestCase from plone.app.discussion.tests.layer import DiscussionLayer from plone.app.discussion.interfaces import IComment, IConversation -from plone.app.discussion.comment import Comment class CommentTest(PloneTestCase): @@ -19,30 +18,44 @@ class CommentTest(PloneTestCase): typetool.constructContent('Document', self.portal, 'doc1') def test_factory(self): - # test with createObject() - pass + comment1 = createObject('plone.Comment') + self.assert_(IComment.providedBy(comment1)) def test_id(self): - # relationship between id, getId(), __name__ - pass + comment1 = createObject('plone.Comment') + comment1.comment_id = 123 + self.assertEquals('123', comment1.id) + self.assertEquals('123', comment1.getId()) + self.assertEquals(u'123', comment1.__name__) def test_title(self): - pass + comment1 = createObject('plone.Comment') + comment1.title = "New title" + self.assertEquals("New title", comment1.Title()) def test_creator(self): - pass + comment1 = createObject('plone.Comment') + comment1.creator = "Jim" + self.assertEquals("Jim", comment1.Creator()) def test_traversal(self): # make sure comments are traversable, have an id, absolute_url and physical path - # XXX - traversal doesn't work without a name? - conversation = self.portal.doc1.restrictedTraverse('++comment++1') - self.assert_(IConversation.providedBy(conversation)) + conversation = IConversation(self.portal.doc1).__of__(self.portal.doc1) - # TODO: Test adding comments, traversing to them + comment1 = createObject('plone.Comment') + comment1.title = 'Comment 1' + comment1.text = 'Comment text' + + new_comment1_id = conversation.addComment(comment1) + + comment = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_comment1_id) + self.assert_(IComment.providedBy(comment)) + self.assertEquals('Comment 1', comment.title) + + self.assertEquals(('', 'plone', 'doc1', '++conversation++default', str(new_comment1_id)), comment.getPhysicalPath()) + self.assertEquals('plone/doc1/%2B%2Bconversation%2B%2Bdefault/' + str(new_comment1_id), comment.absolute_url()) - pass - def test_workflow(self): # ensure that we can assign a workflow to the comment type and perform # workflow operations diff --git a/plone/app/discussion/tests/test_conversation.py b/plone/app/discussion/tests/test_conversation.py index a3ba04f..575aa19 100644 --- a/plone/app/discussion/tests/test_conversation.py +++ b/plone/app/discussion/tests/test_conversation.py @@ -47,7 +47,7 @@ class ConversationTest(PloneTestCase): self.assertEquals(conversation.total_comments, 1) self.assert_(conversation.last_comment_date - datetime.now() < timedelta(seconds=1)) - def test_delete(self): + def test_delete_comment(self): pass def test_dict_operations(self): @@ -103,6 +103,15 @@ class ConversationTest(PloneTestCase): def test_get_threads_batched(self): pass + + def test_traversal(self): + # make sure we can traverse to conversations and get a URL and path + + conversation = self.portal.doc1.restrictedTraverse('++conversation++default') + self.assert_(IConversation.providedBy(conversation)) + + self.assertEquals(('', 'plone', 'doc1', '++conversation++default'), conversation.getPhysicalPath()) + self.assertEquals('plone/doc1/%2B%2Bconversation%2B%2Bdefault', conversation.absolute_url()) class RepliesTest(PloneTestCase):