From a54a15a90fcc65956095f8e9a2daff9e9750529a Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Tue, 13 Jul 2010 10:45:53 +0000 Subject: [PATCH] Remove unnecessary imports and variables from test code. svn path=/plone.app.discussion/trunk/; revision=37768 --- plone/app/discussion/tests/test_catalog.py | 12 +++--- plone/app/discussion/tests/test_comment.py | 4 +- .../discussion/tests/test_comments_viewlet.py | 26 ++++-------- .../app/discussion/tests/test_controlpanel.py | 10 ----- .../app/discussion/tests/test_conversation.py | 36 +++++++--------- plone/app/discussion/tests/test_indexers.py | 7 +--- plone/app/discussion/tests/test_migration.py | 42 +++++++------------ .../discussion/tests/test_moderation_view.py | 14 +------ .../discussion/tests/test_notifications.py | 11 +---- 9 files changed, 50 insertions(+), 112 deletions(-) diff --git a/plone/app/discussion/tests/test_catalog.py b/plone/app/discussion/tests/test_catalog.py index b57e9b9..34f2e20 100644 --- a/plone/app/discussion/tests/test_catalog.py +++ b/plone/app/discussion/tests/test_catalog.py @@ -4,15 +4,13 @@ from datetime import datetime from zope.component import createObject -from zope.component import getMultiAdapter - from Products.CMFCore.utils import getToolByName from Products.PloneTestCase.ptc import PloneTestCase from plone.app.discussion.tests.layer import DiscussionLayer -from plone.app.discussion.interfaces import IComment, IConversation, IReplies +from plone.app.discussion.interfaces import IConversation class CatalogSetupTest(PloneTestCase): @@ -218,7 +216,7 @@ class CommentCatalogTest(PloneTestCase): self.assertEquals(self.comment_brain.Type, 'Comment') def test_review_state(self): - self.assertEquals(self.comment_brain.review_state, 'published') + self.assertEquals(self.comment_brain.review_state, 'published') def test_creator(self): self.assertEquals(self.comment_brain.Creator, 'Jim') @@ -294,13 +292,13 @@ class CommentCatalogTest(PloneTestCase): new_id_1_1 = self.conversation.addComment(comment1_1) comment1_1_1.in_reply_to = new_id_1_1 - new_id_1_1_1 = self.conversation.addComment(comment1_1_1) + self.conversation.addComment(comment1_1_1) comment1_2.in_reply_to = new_id_1 - new_id_1_2 = self.conversation.addComment(comment1_2) + self.conversation.addComment(comment1_2) comment2_1.in_reply_to = new_id_2 - new_id_2_1 = self.conversation.addComment(comment2_1) + self.conversation.addComment(comment2_1) # Clear and rebuild catalog self.catalog.clearFindAndRebuild() diff --git a/plone/app/discussion/tests/test_comment.py b/plone/app/discussion/tests/test_comment.py index e096cc6..673a866 100644 --- a/plone/app/discussion/tests/test_comment.py +++ b/plone/app/discussion/tests/test_comment.py @@ -4,8 +4,6 @@ from zope.component import createObject from zope.component import getMultiAdapter -from Products.CMFCore.utils import getToolByName - from Products.PloneTestCase.ptc import PloneTestCase from plone.app.discussion.tests.layer import DiscussionLayer @@ -209,7 +207,7 @@ class RepliesTest(PloneTestCase): comment1.title = 'Comment 1' comment1.text = 'Comment text' - new_comment1_id = conversation.addComment(comment1) + conversation.addComment(comment1) comment = createObject('plone.Comment') comment.title = 'Comment 1' diff --git a/plone/app/discussion/tests/test_comments_viewlet.py b/plone/app/discussion/tests/test_comments_viewlet.py index 98c5369..de9a948 100644 --- a/plone/app/discussion/tests/test_comments_viewlet.py +++ b/plone/app/discussion/tests/test_comments_viewlet.py @@ -1,28 +1,20 @@ import unittest -from datetime import datetime, timedelta - -from plone.registry import Registry +from datetime import datetime from zope.component import createObject, queryUtility -from Acquisition import aq_base, aq_parent, aq_inner - from OFS.Image import Image -from plone.app.vocabularies.types import BAD_TYPES - from plone.registry.interfaces import IRegistry -from Products.CMFCore.FSImage import FSImage from Products.CMFCore.utils import getToolByName from Products.CMFPlone.tests import dummy from Products.Five.testbrowser import Browser from Products.PloneTestCase.ptc import PloneTestCase from Products.PloneTestCase.ptc import FunctionalTestCase -from plone.app.discussion.browser.comments import CommentForm, CommentsViewlet -from plone.app.discussion.interfaces import IConversation, IComment -from plone.app.discussion.interfaces import IReplies, IDiscussionSettings +from plone.app.discussion.browser.comments import CommentsViewlet +from plone.app.discussion.interfaces import IConversation from plone.app.discussion.tests.layer import DiscussionLayer @@ -42,7 +34,7 @@ class TestCommentForm(PloneTestCase): self.viewlet = CommentsViewlet(context, request, None, None) def test_add_comment(self): - form = CommentForm(self.viewlet, self.app.REQUEST) + #form = CommentForm(self.viewlet, self.app.REQUEST) #self.viewlet.form.render(form) #self.viewlet.form.handleComment() #from z3c.form.testing import TestRequest @@ -64,7 +56,7 @@ class TestCommentForm(PloneTestCase): # Always check form errors after update() #errors = view.errors #self.assertEqual(len(errors), 0, "Got errors:" + str(errors)) - + pass class TestCommentsViewletIntegration(FunctionalTestCase): @@ -185,7 +177,7 @@ class TestCommentsViewlet(PloneTestCase): comment = createObject('plone.Comment') comment.title = 'Comment 1' comment.text = 'Comment text' - conversation = IConversation(self.portal.doc1) + IConversation(self.portal.doc1) portal_membership = getToolByName(self.portal, 'portal_membership') m = portal_membership.getAuthenticatedMember() self.assertEquals(self.viewlet.get_commenter_home_url(m.getUserName()), @@ -209,7 +201,7 @@ class TestCommentsViewlet(PloneTestCase): comment.text = 'Comment text' comment.Creator = 'Jim' comment.author_username = 'jim' - new_id = conversation.addComment(comment) + conversation.addComment(comment) # Call get_commenter_portrait method of the viewlet self.viewlet.update() @@ -235,7 +227,7 @@ class TestCommentsViewlet(PloneTestCase): comment.text = 'Comment text' comment.Creator = 'Jim' comment.author_username = 'jim' - new_id = conversation.addComment(comment) + conversation.addComment(comment) # Call get_commenter_portrait method of the viewlet self.viewlet.update() @@ -249,7 +241,6 @@ class TestCommentsViewlet(PloneTestCase): self.failIf(self.viewlet.anonymous_discussion_allowed()) # Allow anonymous discussion registry = queryUtility(IRegistry) - settings = registry.forInterface(IDiscussionSettings) registry['plone.app.discussion.interfaces.IDiscussionSettings.anonymous_comments'] = True # Test if anonymous discussion is allowed for the viewlet self.failUnless(self.viewlet.anonymous_discussion_allowed()) @@ -257,7 +248,6 @@ class TestCommentsViewlet(PloneTestCase): def test_show_commenter_image(self): self.failUnless(self.viewlet.show_commenter_image()) registry = queryUtility(IRegistry) - settings = registry.forInterface(IDiscussionSettings) registry['plone.app.discussion.interfaces.IDiscussionSettings.show_commenter_image'] = False self.failIf(self.viewlet.show_commenter_image()) diff --git a/plone/app/discussion/tests/test_controlpanel.py b/plone/app/discussion/tests/test_controlpanel.py index 4a147f3..f47d3bd 100644 --- a/plone/app/discussion/tests/test_controlpanel.py +++ b/plone/app/discussion/tests/test_controlpanel.py @@ -35,36 +35,26 @@ class RegistryTest(PloneTestCase): def test_globally_enabled(self): # Check globally_enabled record - globally_enabled_record = self.registry.records['plone.app.discussion.interfaces.IDiscussionSettings.globally_enabled'] - self.failUnless('globally_enabled' in IDiscussionSettings) self.assertEquals(self.registry['plone.app.discussion.interfaces.IDiscussionSettings.globally_enabled'], True) def test_captcha(self): # Check globally_enabled record - globally_enabled_record = self.registry.records['plone.app.discussion.interfaces.IDiscussionSettings.captcha'] - self.failUnless('captcha' in IDiscussionSettings) self.assertEquals(self.registry['plone.app.discussion.interfaces.IDiscussionSettings.captcha'], 'disabled') def test_anonymous_comments(self): # Check anonymous_comments record - anonymous_comments_record = self.registry.records['plone.app.discussion.interfaces.IDiscussionSettings.anonymous_comments'] - self.failUnless('anonymous_comments' in IDiscussionSettings) self.assertEquals(self.registry['plone.app.discussion.interfaces.IDiscussionSettings.anonymous_comments'], False) def test_show_commenter_image(self): # Check show_commenter_image record - show_commenter_image = self.registry.records['plone.app.discussion.interfaces.IDiscussionSettings.show_commenter_image'] - self.failUnless('show_commenter_image' in IDiscussionSettings) self.assertEquals(self.registry['plone.app.discussion.interfaces.IDiscussionSettings.show_commenter_image'], True) def test_moderator_notification_enabled(self): # Check show_commenter_image record - show_commenter_image = self.registry.records['plone.app.discussion.interfaces.IDiscussionSettings.moderator_notification_enabled'] - self.failUnless('moderator_notification_enabled' in IDiscussionSettings) self.assertEquals(self.registry['plone.app.discussion.interfaces.IDiscussionSettings.moderator_notification_enabled'], False) diff --git a/plone/app/discussion/tests/test_conversation.py b/plone/app/discussion/tests/test_conversation.py index df4dd72..05cc507 100644 --- a/plone/app/discussion/tests/test_conversation.py +++ b/plone/app/discussion/tests/test_conversation.py @@ -3,7 +3,7 @@ from datetime import datetime, timedelta from zope.component import createObject, queryUtility -from Acquisition import aq_base, aq_parent, aq_inner +from Acquisition import aq_base, aq_parent from plone.app.vocabularies.types import BAD_TYPES @@ -83,7 +83,7 @@ class ConversationTest(PloneTestCase): # object, as we just want to check the Conversation object API. conversation = IConversation(self.portal.doc1) - replies = IReplies(conversation) + IReplies(conversation) # Create a nested comment structure: # @@ -128,10 +128,10 @@ class ConversationTest(PloneTestCase): new_id_1_1 = conversation.addComment(comment1_1) comment1_1_1.in_reply_to = new_id_1_1 - new_id_1_1_1 = conversation.addComment(comment1_1_1) + conversation.addComment(comment1_1_1) comment1_2.in_reply_to = new_id_1 - new_id_1_2 = conversation.addComment(comment1_2) + conversation.addComment(comment1_2) comment2_1.in_reply_to = new_id_2 new_id_2_1 = conversation.addComment(comment2_1) @@ -150,7 +150,7 @@ class ConversationTest(PloneTestCase): comment = createObject('plone.Comment') comment.title = 'Comment 1' comment.text = 'Comment text' - new_id = conversation.addComment(comment) + conversation.addComment(comment) # Delete the content object self.portal.manage_delObjects(['doc1']) @@ -170,11 +170,10 @@ class ConversationTest(PloneTestCase): # Create a conversation. - conversation = IConversation(self.portal.doc1) + IConversation(self.portal.doc1) # By default, discussion is disabled for all content types portal_types = getToolByName(self.portal, 'portal_types') - from plone.app.vocabularies.types import BAD_TYPES for type in list(portal_types): type_fti = getattr(portal_types, type) if type not in BAD_TYPES: @@ -349,9 +348,6 @@ class ConversationTest(PloneTestCase): def test_is_discussion_allowed_on_content_object(self): # Allow discussion on a single content object - registry = queryUtility(IRegistry) - settings = registry.forInterface(IDiscussionSettings) - # Create a conversation. conversation = IConversation(self.portal.doc1) @@ -448,9 +444,9 @@ class ConversationTest(PloneTestCase): comment3.title = 'Comment 3' comment3.text = 'Comment text' - new_comment1_id = conversation.addComment(comment1) - new_comment2_id = conversation.addComment(comment2) - new_comment3_id = conversation.addComment(comment3) + conversation.addComment(comment1) + conversation.addComment(comment2) + conversation.addComment(comment3) self.assertEquals(conversation.total_comments, 3) @@ -472,13 +468,13 @@ class ConversationTest(PloneTestCase): comment1.title = 'Comment 1' comment1.text = 'Comment text' comment1.author_username = "Jim" - new_comment1_id = conversation.addComment(comment1) + conversation.addComment(comment1) comment2 = createObject('plone.Comment') comment2.title = 'Comment 2' comment2.text = 'Comment text' comment2.author_username = "Joe" - new_comment2_id = conversation.addComment(comment2) + conversation.addComment(comment2) comment3 = createObject('plone.Comment') comment3.title = 'Comment 3' @@ -533,7 +529,7 @@ class ConversationTest(PloneTestCase): comment1.title = 'Comment 1' comment1.text = 'Comment text' comment1.creation_date = datetime.now() - timedelta(4) - new_comment1_id = conversation.addComment(comment1) + conversation.addComment(comment1) comment2 = createObject('plone.Comment') comment2.title = 'Comment 2' @@ -579,7 +575,7 @@ class ConversationTest(PloneTestCase): # object, as we just want to check the Conversation object API. conversation = IConversation(self.portal.doc1) - replies = IReplies(conversation) + IReplies(conversation) # Create a nested comment structure: # @@ -803,11 +799,11 @@ class RepliesTest(PloneTestCase): new_id_1_1 = replies_to_comment1.addComment(comment1_1) comment1_1 = self.portal.doc1.restrictedTraverse('++conversation++default/%s' % new_id_1_1) replies_to_comment1_1 = IReplies(comment1_1) - new_id_1_1_1 = replies_to_comment1_1.addComment(comment1_1_1) + replies_to_comment1_1.addComment(comment1_1_1) - new_id_1_2 = replies_to_comment1.addComment(comment1_2) + replies_to_comment1.addComment(comment1_2) - new_id_2_1 = replies_to_comment2.addComment(comment2_1) + replies_to_comment2.addComment(comment2_1) # check that replies only contain the direct comments # and no comments deeper than 1 diff --git a/plone/app/discussion/tests/test_indexers.py b/plone/app/discussion/tests/test_indexers.py index 1910911..7163512 100644 --- a/plone/app/discussion/tests/test_indexers.py +++ b/plone/app/discussion/tests/test_indexers.py @@ -1,6 +1,6 @@ import unittest -from datetime import datetime, timedelta +from datetime import datetime from DateTime import DateTime from zope.component import createObject @@ -10,11 +10,8 @@ from plone.app.discussion.tests.layer import DiscussionLayer from plone.app.discussion.interfaces import IConversation -from plone.indexer import indexer from plone.indexer.delegate import DelegatingIndexerFactory -from zope.component import provideAdapter - from plone.app.discussion import catalog @@ -128,7 +125,7 @@ class CommentIndexersTest(PloneTestCase): comment_long.title = 'Long Comment' comment_long.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 = self.conversation.addComment(comment_long) + self.conversation.addComment(comment_long) self.assertEquals(catalog.description(comment_long)(), '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 [...]') def test_dates(self): diff --git a/plone/app/discussion/tests/test_migration.py b/plone/app/discussion/tests/test_migration.py index a5802d7..037d461 100644 --- a/plone/app/discussion/tests/test_migration.py +++ b/plone/app/discussion/tests/test_migration.py @@ -91,14 +91,14 @@ class MigrationTest(PloneTestCase): talkback = self.discussion.getDiscussionFor(self.doc) # First comment - comment1_id = talkback.createReply(title='First comment', - text='This is my first comment.') + talkback.createReply(title='First comment', + text='This is my first comment.') comment1 = talkback.getReplies()[0] talkback_comment1 = self.discussion.getDiscussionFor(comment1) # Re: First comment - comment1_1_id = talkback_comment1.createReply(title='Re: First comment', - text='This is my first reply.') + talkback_comment1.createReply(title='Re: First comment', + text='This is my first reply.') comment1_1 = talkback_comment1.getReplies()[0] talkback_comment1_1 = self.discussion.getDiscussionFor(comment1_1) @@ -107,40 +107,30 @@ class MigrationTest(PloneTestCase): self.assertEquals(len(talkback_comment1_1.getReplies()), 0) #Re: Re: First comment - comment1_1_1_id = talkback_comment1_1.createReply(title='Re: Re: First comment', - text='This is my first re-reply.') + talkback_comment1_1.createReply(title='Re: Re: First comment', + text='This is my first re-reply.') comment1_1_1 = talkback_comment1_1.getReplies()[0] talkback_comment1_1_1 = self.discussion.getDiscussionFor(comment1_1_1) # Re: Re: Re: First comment - comment1_1_1_1_id = talkback_comment1_1_1.createReply(title='Re: Re: Re: First comment', - text='This is my first re-re-reply.') - comment1_1_1_1 = talkback_comment1_1_1.getReplies()[0] - talkback_comment1_1_1_1 = self.discussion.getDiscussionFor(comment1_1_1_1) + talkback_comment1_1_1.createReply(title='Re: Re: Re: First comment', + text='This is my first re-re-reply.') # Re: First comment (2) - comment1_2_id = talkback_comment1.createReply(title='Re: First comment (2)', - text='This is my first reply (2).') - comment1_2 = talkback_comment1.getReplies()[1] - talkback_comment1_2 = self.discussion.getDiscussionFor(comment1_2) + talkback_comment1.createReply(title='Re: First comment (2)', + text='This is my first reply (2).') # Re: First comment (3) - comment1_3_id = talkback_comment1.createReply(title='Re: First comment (3)', - text='This is my first reply (3).') - comment1_3 = talkback_comment1.getReplies()[2] - talkback_comment1_3 = self.discussion.getDiscussionFor(comment1_3) + talkback_comment1.createReply(title='Re: First comment (3)', + text='This is my first reply (3).') # Re: First comment (4) - comment1_4_id = talkback_comment1.createReply(title='Re: First comment (4)', - text='This is my first reply (4).') - comment1_4 = talkback_comment1.getReplies()[3] - talkback_comment1_4 = self.discussion.getDiscussionFor(comment1_4) + talkback_comment1.createReply(title='Re: First comment (4)', + text='This is my first reply (4).') # Second comment - comment2_id = talkback.createReply(title='Second comment', - text='This is my second comment.') - comment2 = talkback.getReplies()[1] - talkback_comment2 = self.discussion.getDiscussionFor(comment2) + talkback.createReply(title='Second comment', + text='This is my second comment.') # Call migration script self.view() diff --git a/plone/app/discussion/tests/test_moderation_view.py b/plone/app/discussion/tests/test_moderation_view.py index 398e7c9..532d793 100644 --- a/plone/app/discussion/tests/test_moderation_view.py +++ b/plone/app/discussion/tests/test_moderation_view.py @@ -1,26 +1,14 @@ import unittest from DateTime import DateTime -from datetime import datetime, timedelta - -from plone.registry import Registry from zope.component import createObject -from Acquisition import aq_base, aq_parent, aq_inner - -from OFS.Image import Image - -from plone.app.vocabularies.types import BAD_TYPES - -from Products.CMFCore.FSImage import FSImage from Products.CMFCore.utils import getToolByName -from Products.CMFPlone.tests import dummy from Products.PloneTestCase.ptc import PloneTestCase from plone.app.discussion.browser.moderation import View -from plone.app.discussion.interfaces import IConversation, IComment -from plone.app.discussion.interfaces import IReplies, IDiscussionSettings +from plone.app.discussion.interfaces import IConversation from plone.app.discussion.tests.layer import DiscussionLayer diff --git a/plone/app/discussion/tests/test_notifications.py b/plone/app/discussion/tests/test_notifications.py index 8a31730..cebf435 100644 --- a/plone/app/discussion/tests/test_notifications.py +++ b/plone/app/discussion/tests/test_notifications.py @@ -1,12 +1,7 @@ import unittest -from email import message_from_string - from Acquisition import aq_base -from zope.app.container.contained import ObjectAddedEvent -from zope.app.container.interfaces import IObjectAddedEvent - from zope.component import createObject from zope.component import getSiteManager from zope.component import queryUtility @@ -18,9 +13,7 @@ from Products.CMFPlone.tests.utils import MockMailHost from plone.registry.interfaces import IRegistry -from plone.app.discussion.comment import notify_user -from plone.app.discussion.interfaces import IComment, IConversation, IReplies -from plone.app.discussion.interfaces import IDiscussionSettings +from plone.app.discussion.interfaces import IConversation from plone.app.discussion.tests.layer import DiscussionLayer @@ -163,7 +156,6 @@ class TestModeratorNotificationUnit(PloneTestCase): # Enable moderator notification setting registry = queryUtility(IRegistry) - settings = registry.forInterface(IDiscussionSettings) registry['plone.app.discussion.interfaces.IDiscussionSettings.moderator_notification_enabled'] = True # Create test content @@ -221,7 +213,6 @@ class TestModeratorNotificationUnit(PloneTestCase): # Disable moderator notification setting and make sure no email is send # to the moderator. registry = queryUtility(IRegistry) - settings = registry.forInterface(IDiscussionSettings) registry['plone.app.discussion.interfaces.IDiscussionSettings.moderator_notification_enabled'] = False comment = createObject('plone.Comment')