From a6a64bd3d62225ed50407896474144d83c264990 Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Mon, 1 Jun 2009 23:45:49 +0000 Subject: [PATCH] rename all indexes from comment_XXX to XXX. clean up indexes test. svn path=/plone.app.discussion/trunk/; revision=27259 --- plone/app/discussion/catalog.py | 8 +- plone/app/discussion/configure.zcml | 8 +- plone/app/discussion/tests/test_indexers.py | 117 ++++---------------- 3 files changed, 32 insertions(+), 101 deletions(-) diff --git a/plone/app/discussion/catalog.py b/plone/app/discussion/catalog.py index e052ca9..f78af84 100644 --- a/plone/app/discussion/catalog.py +++ b/plone/app/discussion/catalog.py @@ -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) diff --git a/plone/app/discussion/configure.zcml b/plone/app/discussion/configure.zcml index 21865d9..89fc5c5 100644 --- a/plone/app/discussion/configure.zcml +++ b/plone/app/discussion/configure.zcml @@ -58,10 +58,10 @@ /> - - - - + + + + diff --git a/plone/app/discussion/tests/test_indexers.py b/plone/app/discussion/tests/test_indexers.py index 1172bc6..7141346 100644 --- a/plone/app/discussion/tests/test_indexers.py +++ b/plone/app/discussion/tests/test_indexers.py @@ -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