Refactor tests and add a lot of skeleton tests we really ought to have

svn path=/plone.app.discussion/trunk/; revision=27012
This commit is contained in:
Martin Aspeli
2009-05-18 15:15:36 +00:00
parent f5a781501b
commit 250b556428
8 changed files with 252 additions and 69 deletions
-45
View File
@@ -1,45 +0,0 @@
import unittest
from datetime import datetime, timedelta
from Products.PloneTestCase.ptc import PloneTestCase
from plone.app.discussion.tests.layer import DiscussionLayer
from plone.app.discussion.conversation import Conversation
from plone.app.discussion.comment import Comment
from plone.app.discussion.interfaces import ICommentingTool, IConversation
class ConversationTest(PloneTestCase):
layer = DiscussionLayer
def afterSetUp(self):
# XXX If we make this a layer, it only get run once...
# First we need to create some content.
self.loginAsPortalOwner()
typetool = self.portal.portal_types
typetool.constructContent('Document', self.portal, 'doc1')
def test_add_comment(self):
# 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.
# XXX implement traversal to commenting and change this:
conversation = conversation.__of__(self.portal.doc1)
# Add a comment. reply_to=0 means it's not a reply
comment = Comment(conversation=conversation, reply_to=0)
comment.title = 'Comment 1'
comment.text = 'Comment text'
conversation.addComment(comment)
# Check that the conversation methods return the correct data
self.assert_(isinstance(comment.comment_id, long))
self.assertEquals(len(conversation.getComments()), 1)
self.assertEquals(len(conversation.getThreads()), 1)
self.assertEquals(conversation.total_comments, 1)
self.assert_(conversation.last_comment_date - datetime.now() < timedelta(seconds=1))
def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__)
@@ -0,0 +1,71 @@
import unittest
from zope.component import createObject
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):
layer = DiscussionLayer
def afterSetUp(self):
# First we need to create some content.
self.loginAsPortalOwner()
typetool = self.portal.portal_types
typetool.constructContent('Document', self.portal, 'doc1')
def test_factory(self):
# test with createObject()
pass
def test_id(self):
# relationship between id, getId(), __name__
pass
def test_title(self):
pass
def test_creator(self):
pass
def test_traversal(self):
# make sure comments are traversable, have an id, absolute_url and physical path
pass
def test_workflow(self):
# ensure that we can assign a workflow to the comment type and perform
# workflow operations
pass
def test_fti(self):
# test that we can look up an FTI for Discussion Item
pass
class RepliesTest(PloneTestCase):
# test the IReplies adapter on a comment
layer = DiscussionLayer
def afterSetUp(self):
# First we need to create some content.
self.loginAsPortalOwner()
typetool = self.portal.portal_types
typetool.constructContent('Document', self.portal, 'doc1')
def test_add_comment(self):
pass
def test_delete_comment(self):
pass
def test_dict_api(self):
# ensure all operations use only top-level comments
pass
def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__)
@@ -0,0 +1,103 @@
import unittest
from datetime import datetime, timedelta
from zope.component import createObject
from Acquisition import aq_base
from Products.PloneTestCase.ptc import PloneTestCase
from plone.app.discussion.tests.layer import DiscussionLayer
from plone.app.discussion.interfaces import IConversation, IComment
class ConversationTest(PloneTestCase):
layer = DiscussionLayer
def afterSetUp(self):
# First we need to create some content.
self.loginAsPortalOwner()
typetool = self.portal.portal_types
typetool.constructContent('Document', self.portal, 'doc1')
def test_add_comment(self):
# 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)
# Check that the conversation methods return the correct data
self.assert_(isinstance(comment.comment_id, long))
self.assert_(IComment.providedBy(conversation[new_id]))
self.assertEquals(aq_base(conversation[new_id].__parent__), aq_base(conversation))
self.assertEquals(new_id, comment.comment_id)
self.assertEquals(len(conversation.getComments()), 1)
self.assertEquals(len(conversation.getThreads()), 1)
self.assertEquals(conversation.total_comments, 1)
self.assert_(conversation.last_comment_date - datetime.now() < timedelta(seconds=1))
def test_delete(self):
pass
def test_dict_operations(self):
# test dict operations and acquisition wrapping
pass
def test_total_comments(self):
pass
def test_commentators(self):
# add and remove a few comments to make sure the commenetators
# property returns a true set
pass
def test_last_comment_date(self):
pass
def test_get_comments_flat(self):
pass
def test_get_comments_batched(self):
pass
def test_get_threads(self):
pass
def test_get_threads_batched(self):
pass
class RepliesTest(PloneTestCase):
# test the IReplies adapter on a conversation
layer = DiscussionLayer
def afterSetUp(self):
# First we need to create some content.
self.loginAsPortalOwner()
typetool = self.portal.portal_types
typetool.constructContent('Document', self.portal, 'doc1')
def test_add_comment(self):
pass
def test_delete_comment(self):
pass
def test_dict_api(self):
# ensure all operations use only top-level comments
pass
def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__)
@@ -0,0 +1,42 @@
import unittest
from Products.PloneTestCase.ptc import PloneTestCase
from plone.app.discussion.tests.layer import DiscussionLayer
class TestIndexers(PloneTestCase):
layer = DiscussionLayer
def test_title(self):
pass
def test_description(self):
pass
def test_dates(self):
# created, modified, effective etc
pass
def test_searchable_text(self):
pass
def test_creator(self):
pass
def test_title(self):
pass
def test_in_reply_to(self):
pass
def test_path(self):
pass
def test_review_state(self):
pass
def test_object_provides(self):
pass
def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__)
+10 -4
View File
@@ -1,11 +1,10 @@
import unittest
from zope.component import getUtility
from zope.component import getUtility, createObject
from Products.PloneTestCase.ptc import PloneTestCase
from plone.app.discussion.tests.layer import DiscussionLayer
from plone.app.discussion.comment import Comment
from plone.app.discussion.interfaces import ICommentingTool, IConversation
class ToolTest(PloneTestCase):
@@ -27,8 +26,8 @@ class ToolTest(PloneTestCase):
# XXX implement traversal to commenting and change this:
conversation = conversation.__of__(self.portal.doc1)
# Add a comment. reply_to=0 means it's not a reply
comment = Comment(conversation=conversation, reply_to=0)
# Add a comment.
comment = createObject('plone.Comment')
comment.title = 'Comment 1'
comment.text = 'Comment text'
@@ -41,5 +40,12 @@ class ToolTest(PloneTestCase):
" %s results in the search" % len(comment))
self.assertEquals(comment[0].Title, 'Comment 1')
def test_unindexing(self):
pass
def test_search(self):
# search returns only comments
pass
def test_suite():
return unittest.defaultTestLoader.loadTestsFromName(__name__)