Use plone.app.testing in test_catalog.
svn path=/plone.app.discussion/trunk/; revision=48897
This commit is contained in:
parent
4110b41ae6
commit
e5d45dbd78
@ -1,6 +1,6 @@
|
||||
"""Test the plone.app.discussion catalog indexes
|
||||
"""
|
||||
import unittest
|
||||
import unittest2 as unittest
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
@ -9,17 +9,20 @@ from zope.annotation.interfaces import IAnnotations
|
||||
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
|
||||
from Products.PloneTestCase.ptc import PloneTestCase
|
||||
from plone.app.testing import TEST_USER_ID, setRoles
|
||||
|
||||
from plone.app.discussion.tests.layer import DiscussionLayer
|
||||
from plone.app.discussion.testing import PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
||||
|
||||
from plone.app.discussion.interfaces import IConversation
|
||||
|
||||
|
||||
class CatalogSetupTest(PloneTestCase):
|
||||
class CatalogSetupTest(unittest.TestCase):
|
||||
|
||||
layer = DiscussionLayer
|
||||
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
||||
|
||||
def setUp(self):
|
||||
self.portal = self.layer['portal']
|
||||
|
||||
def test_catalog_installed(self):
|
||||
self.assertTrue('total_comments' in
|
||||
self.portal.portal_catalog.indexes())
|
||||
@ -29,7 +32,7 @@ class CatalogSetupTest(PloneTestCase):
|
||||
self.portal.portal_catalog.schema())
|
||||
self.assertTrue('in_response_to' in
|
||||
self.portal.portal_catalog.schema())
|
||||
|
||||
|
||||
def test_collection_criteria_installed(self):
|
||||
try:
|
||||
self.portal.portal_atct.getIndex('commentators')
|
||||
@ -39,21 +42,19 @@ class CatalogSetupTest(PloneTestCase):
|
||||
self.fail()
|
||||
|
||||
|
||||
class ConversationCatalogTest(PloneTestCase):
|
||||
class ConversationCatalogTest(unittest.TestCase):
|
||||
|
||||
layer = DiscussionLayer
|
||||
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
||||
|
||||
def afterSetUp(self):
|
||||
# First we need to create some content.
|
||||
self.loginAsPortalOwner()
|
||||
def setUp(self):
|
||||
self.portal = self.layer['portal']
|
||||
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
||||
self.portal.invokeFactory(id='doc1',
|
||||
Title='Document 1',
|
||||
type_name='Document')
|
||||
|
||||
|
||||
self.catalog = getToolByName(self.portal, 'portal_catalog')
|
||||
|
||||
conversation = IConversation(self.portal.doc1)
|
||||
|
||||
comment1 = createObject('plone.Comment')
|
||||
comment1.title = 'Comment 1'
|
||||
comment1.text = 'Comment text'
|
||||
@ -75,17 +76,17 @@ class ConversationCatalogTest(PloneTestCase):
|
||||
self.doc1_brain = brains[0]
|
||||
self.comment1 = comment1
|
||||
self.new_comment1_id = new_comment1_id
|
||||
|
||||
|
||||
def test_total_comments(self):
|
||||
self.assertTrue('total_comments' in self.doc1_brain)
|
||||
self.assertEqual(self.doc1_brain.total_comments, 1)
|
||||
|
||||
|
||||
comment2 = createObject('plone.Comment')
|
||||
comment2.title = 'Comment 2'
|
||||
comment2.text = 'Comment text'
|
||||
comment2.creator = 'Emma'
|
||||
new_comment2_id = self.conversation.addComment(comment2)
|
||||
|
||||
|
||||
comment2 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_comment2_id)
|
||||
comment2.reindexObject()
|
||||
@ -96,12 +97,12 @@ class ConversationCatalogTest(PloneTestCase):
|
||||
))
|
||||
doc1_brain = brains[0]
|
||||
self.assertEqual(doc1_brain.total_comments, 2)
|
||||
|
||||
|
||||
def test_last_comment_date(self):
|
||||
self.assertTrue('last_comment_date' in self.doc1_brain)
|
||||
self.assertEqual(self.doc1_brain.last_comment_date,
|
||||
datetime(2006, 9, 17, 14, 18, 12))
|
||||
|
||||
|
||||
# Add another comment and check if last comment date is updated.
|
||||
comment2 = createObject('plone.Comment')
|
||||
comment2.title = 'Comment 2'
|
||||
@ -110,7 +111,7 @@ class ConversationCatalogTest(PloneTestCase):
|
||||
comment2.creation_date = datetime(2009, 9, 17, 14, 18, 12)
|
||||
comment2.modification_date = datetime(2009, 9, 17, 14, 18, 12)
|
||||
new_comment2_id = self.conversation.addComment(comment2)
|
||||
|
||||
|
||||
comment2 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_comment2_id)
|
||||
comment2.reindexObject()
|
||||
@ -122,20 +123,19 @@ class ConversationCatalogTest(PloneTestCase):
|
||||
doc1_brain = brains[0]
|
||||
self.assertEqual(doc1_brain.last_comment_date,
|
||||
datetime(2009, 9, 17, 14, 18, 12))
|
||||
|
||||
|
||||
# Remove the comment again
|
||||
del self.conversation[new_comment2_id]
|
||||
|
||||
|
||||
brains = self.catalog.searchResults(dict(
|
||||
path={'query':
|
||||
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
portal_type="Document"
|
||||
))
|
||||
doc1_brain = brains[0]
|
||||
|
||||
self.assertEqual(doc1_brain.last_comment_date,
|
||||
datetime(2006, 9, 17, 14, 18, 12))
|
||||
|
||||
|
||||
# remove all comments
|
||||
del self.conversation[self.new_comment1_id]
|
||||
brains = self.catalog.searchResults(dict(
|
||||
@ -145,11 +145,11 @@ class ConversationCatalogTest(PloneTestCase):
|
||||
))
|
||||
doc1_brain = brains[0]
|
||||
self.assertEqual(doc1_brain.last_comment_date, None)
|
||||
|
||||
|
||||
def test_commentators(self):
|
||||
self.assertTrue('commentators' in self.doc1_brain)
|
||||
self.assertEqual(self.doc1_brain.commentators, ('Jim',))
|
||||
|
||||
|
||||
# add another comment with another author
|
||||
comment2 = createObject('plone.Comment')
|
||||
comment2.title = 'Comment 2'
|
||||
@ -157,20 +157,20 @@ class ConversationCatalogTest(PloneTestCase):
|
||||
comment2.creator = 'Emma'
|
||||
comment2.author_username = 'Emma'
|
||||
new_comment2_id = self.conversation.addComment(comment2)
|
||||
|
||||
|
||||
comment2 = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_comment2_id)
|
||||
comment2.reindexObject()
|
||||
|
||||
|
||||
brains = self.catalog.searchResults(dict(
|
||||
path={'query':
|
||||
'/'.join(self.portal.doc1.getPhysicalPath()) },
|
||||
portal_type="Document"
|
||||
))
|
||||
doc1_brain = brains[0]
|
||||
|
||||
|
||||
self.assertEqual(doc1_brain.commentators, ('Emma', 'Jim'))
|
||||
|
||||
|
||||
# remove one comments
|
||||
del self.conversation[new_comment2_id]
|
||||
brains = self.catalog.searchResults(dict(
|
||||
@ -180,7 +180,7 @@ class ConversationCatalogTest(PloneTestCase):
|
||||
))
|
||||
doc1_brain = brains[0]
|
||||
self.assertEqual(doc1_brain.commentators, ('Jim',))
|
||||
|
||||
|
||||
# remove all comments
|
||||
del self.conversation[self.new_comment1_id]
|
||||
brains = self.catalog.searchResults(dict(
|
||||
@ -190,7 +190,7 @@ class ConversationCatalogTest(PloneTestCase):
|
||||
))
|
||||
doc1_brain = brains[0]
|
||||
self.assertEqual(doc1_brain.commentators, ())
|
||||
|
||||
|
||||
def test_conversation_indexes_not_in_comments(self):
|
||||
brains = self.catalog.searchResults(dict(
|
||||
path={'query':
|
||||
@ -203,28 +203,27 @@ class ConversationCatalogTest(PloneTestCase):
|
||||
self.assertEqual(comment1_brain.total_comments, None)
|
||||
|
||||
|
||||
class CommentCatalogTest(PloneTestCase):
|
||||
|
||||
layer = DiscussionLayer
|
||||
|
||||
def afterSetUp(self):
|
||||
"""Create a document with a comment.
|
||||
"""
|
||||
self.loginAsPortalOwner()
|
||||
class CommentCatalogTest(unittest.TestCase):
|
||||
|
||||
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
||||
|
||||
def setUp(self):
|
||||
self.portal = self.layer['portal']
|
||||
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
||||
self.portal.invokeFactory(id='doc1',
|
||||
title='Document 1',
|
||||
type_name='Document')
|
||||
self.catalog = getToolByName(self.portal, 'portal_catalog')
|
||||
|
||||
|
||||
conversation = IConversation(self.portal.doc1)
|
||||
self.conversation = conversation
|
||||
|
||||
|
||||
comment1 = createObject('plone.Comment')
|
||||
comment1.text = 'Comment text'
|
||||
comment1.creator = 'Jim'
|
||||
new_comment1_id = conversation.addComment(comment1)
|
||||
self.comment_id = new_comment1_id
|
||||
|
||||
|
||||
# Comment brain
|
||||
self.comment = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/%s' % new_comment1_id)
|
||||
@ -368,13 +367,13 @@ class CommentCatalogTest(PloneTestCase):
|
||||
self.assertEqual(len(topic.queryCatalog()), 1)
|
||||
|
||||
|
||||
class NoConversationCatalogTest(PloneTestCase):
|
||||
class NoConversationCatalogTest(unittest.TestCase):
|
||||
|
||||
layer = DiscussionLayer
|
||||
layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
||||
|
||||
def afterSetUp(self):
|
||||
# First we need to create some content.
|
||||
self.loginAsPortalOwner()
|
||||
def setUp(self):
|
||||
self.portal = self.layer['portal']
|
||||
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
||||
self.portal.invokeFactory(id='doc1',
|
||||
Title='Document 1',
|
||||
type_name='Document')
|
||||
|
Loading…
Reference in New Issue
Block a user