From 4d330f2daa1efcf9e11b83c79e2779656fdaef5a Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Sat, 31 Mar 2012 18:40:58 +0200 Subject: [PATCH] Make comment collection tests work with plone.app.collection. --- plone/app/discussion/testing.py | 6 ++++ plone/app/discussion/tests/test_catalog.py | 32 ++++++++++++++++------ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/plone/app/discussion/testing.py b/plone/app/discussion/testing.py index b7a8841..39e5221 100644 --- a/plone/app/discussion/testing.py +++ b/plone/app/discussion/testing.py @@ -8,6 +8,12 @@ from plone.app.testing import FunctionalTesting from zope.configuration import xmlconfig +try: + import plone.app.collection + COLLECTION_TYPE = "Collection" +except: + COLLECTION_TYPE = "Topic" + class PloneAppDiscussion(PloneSandboxLayer): diff --git a/plone/app/discussion/tests/test_catalog.py b/plone/app/discussion/tests/test_catalog.py index 6479aa4..9e3f113 100644 --- a/plone/app/discussion/tests/test_catalog.py +++ b/plone/app/discussion/tests/test_catalog.py @@ -18,6 +18,8 @@ from plone.app.discussion.testing import \ from plone.app.discussion.interfaces import IConversation +from plone.app.discussion.testing import COLLECTION_TYPE + class CatalogSetupTest(unittest.TestCase): @@ -413,16 +415,28 @@ class CommentCatalogTest(unittest.TestCase): self.assertEqual(len(brains), 6) def test_collection(self): - self.portal.invokeFactory(id='topic', type_name='Topic') - topic = self.portal.topic - crit = topic.addCriterion('Type', 'ATSimpleStringCriterion') - crit.setValue('Comment') - query = topic.buildQuery() + if COLLECTION_TYPE == "Topic": + self.portal.invokeFactory('Topic', id='topic') + topic = self.portal.topic + crit = topic.addCriterion('Type', 'ATSimpleStringCriterion') + crit.setValue('Comment') + query = topic.buildQuery() - # Make sure the comment we just added is returned by the collection - self.assertEqual(len(query), 1) - self.assertEqual(query['Type'], 'Comment') - self.assertEqual(len(topic.queryCatalog()), 1) + self.assertEqual(len(query), 1) + self.assertEqual(query['Type'], 'Comment') + self.assertEqual(len(topic.queryCatalog()), 1) + else: + self.portal.invokeFactory('Collection', id='collection') + collection = self.portal.collection + collection.query = [{ + 'i': 'Type', + 'o': 'plone.app.querystring.operation.string.is', + 'v': 'Comment', + }] + + self.assertEqual(len(collection.results()), 1) + self.assertEqual(collection.results()[0].text, 'Comment text') + self.assertEqual(collection.results()[0].creator, 'Jim') class NoConversationCatalogTest(unittest.TestCase):