rename all indexes from comment_XXX to XXX. clean up indexes test.

svn path=/plone.app.discussion/trunk/; revision=27259
This commit is contained in:
Timo Stollenwerk 2009-06-01 23:45:49 +00:00
parent dc948da00b
commit a6a64bd3d6
3 changed files with 32 additions and 101 deletions

View File

@ -15,20 +15,20 @@ from plone.app.discussion.interfaces import IComment
MAX_DESCRIPTION=25
@indexer(IComment)
def comment_title(object):
def title(object):
return object.title
@indexer(IComment)
def comment_creator(object):
def creator(object):
return object.creator
@indexer(IComment)
def comment_description(object):
def description(object):
# Return the first 25 words of the comment text and append '...'
return '%s...' % join(object.text.split()[:MAX_DESCRIPTION])
@indexer(IComment)
def comment_searchable_text(object):
def searchable_text(object):
return object.title, object.text
@indexer(IComment)

View File

@ -58,10 +58,10 @@
/>
<!-- adapters for indexes -->
<adapter name="Title" factory=".catalog.comment_title" />
<adapter name="Creator" factory=".catalog.comment_creator" />
<adapter name="Description" factory=".catalog.comment_description" />
<adapter name="SearchableText" factory=".catalog.comment_searchable_text" />
<adapter name="Title" factory=".catalog.title" />
<adapter name="Creator" factory=".catalog.creator" />
<adapter name="Description" factory=".catalog.description" />
<adapter name="SearchableText" factory=".catalog.searchable_text" />
<adapter name="effective" factory=".catalog.effective" />
<adapter name="created" factory=".catalog.created" />
<adapter name="modified" factory=".catalog.modified" />

View File

@ -26,32 +26,6 @@ class IndexersTest(PloneTestCase):
self.loginAsPortalOwner()
typetool = self.portal.portal_types
typetool.constructContent('Document', self.portal, 'doc1')
provideAdapter(catalog.comment_title, name='title')
def test_comment_title(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)
self.assertEquals(catalog.comment_title(comment)(), 'Comment 1')
self.assert_(isinstance(catalog.comment_title, DelegatingIndexerFactory))
def test_comment_description(self):
# Create a 50 word comment and make sure the description returns
# only the first 25 words
# Create a conversation. In this case we doesn't assign it to an
# object, as we just want to check the Conversation object API.
@ -66,80 +40,37 @@ class IndexersTest(PloneTestCase):
comment = createObject('plone.Comment')
comment.title = 'Comment 1'
comment.text = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.'
new_id = conversation.addComment(comment)
self.assertEquals(catalog.comment_description(comment)(), 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At...')
self.assert_(isinstance(catalog.comment_description, DelegatingIndexerFactory))
def test_dates(self):
# Test if created, modified, effective etc. are set correctly
# 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'
comment.creator = "Jim"
comment.creation_date = datetime(2006, 9, 17, 14, 18, 12)
comment.modification_date = datetime(2008, 3, 12, 7, 32, 52)
new_id = conversation.addComment(comment)
# Check the indexes
self.assertEquals(catalog.created(comment)(), DateTime(2006, 9, 17, 14, 18, 12))
self.assertEquals(catalog.modified(comment)(), DateTime(2008, 3, 12, 7, 32, 52))
def test_searchable_text(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)
self.assertEquals(catalog.comment_searchable_text(comment)(), ('Comment 1', 'Comment text'))
self.assert_(isinstance(catalog.comment_searchable_text, DelegatingIndexerFactory))
def test_creator(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'
comment.creator = "Jim"
new_id = conversation.addComment(comment)
self.assertEquals(catalog.comment_creator(comment)(), ('Jim'))
self.comment_id = new_id
self.comment = comment
def test_title(self):
pass
self.assertEquals(catalog.title(self.comment)(), 'Comment 1')
self.assert_(isinstance(catalog.title, DelegatingIndexerFactory))
def test_description(self):
# Create a 50 word comment and make sure the description returns
# only the first 25 words
self.assertEquals(catalog.description(self.comment)(), 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At...')
self.assert_(isinstance(catalog.description, DelegatingIndexerFactory))
def test_dates(self):
# Test if created, modified, effective etc. are set correctly
self.assertEquals(catalog.created(self.comment)(), DateTime(2006, 9, 17, 14, 18, 12))
self.assertEquals(catalog.modified(self.comment)(), DateTime(2008, 3, 12, 7, 32, 52))
def test_searchable_text(self):
# Test if searchable text is a concatenation of title and comment text
self.assertEquals(catalog.searchable_text(self.comment)(), ('Comment 1', 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.'))
self.assert_(isinstance(catalog.searchable_text, DelegatingIndexerFactory))
def test_creator(self):
self.assertEquals(catalog.creator(self.comment)(), ('Jim'))
def test_in_reply_to(self):
pass