Pep8.
This commit is contained in:
parent
943065c15f
commit
b4c22e90bf
@ -31,65 +31,100 @@ class RegistryTest(unittest.TestCase):
|
||||
self.assertTrue(registry.forInterface(IDiscussionSettings))
|
||||
|
||||
def test_discussion_controlpanel_view(self):
|
||||
view = getMultiAdapter((self.portal, self.portal.REQUEST),
|
||||
name="discussion-settings")
|
||||
view = getMultiAdapter(
|
||||
(self.portal, self.portal.REQUEST),
|
||||
name="discussion-settings"
|
||||
)
|
||||
view = view.__of__(self.portal)
|
||||
self.assertTrue(view())
|
||||
|
||||
def test_discussion_in_controlpanel(self):
|
||||
# Check if discussion is in the control panel
|
||||
self.controlpanel = getToolByName(self.portal, "portal_controlpanel")
|
||||
self.assertTrue('discussion' in [a.getAction(self)['id']
|
||||
for a in self.controlpanel.listActions()])
|
||||
self.assertTrue(
|
||||
'discussion' in [
|
||||
a.getAction(self)['id']
|
||||
for a in self.controlpanel.listActions()
|
||||
]
|
||||
)
|
||||
|
||||
def test_globally_enabled(self):
|
||||
# Check globally_enabled record
|
||||
self.assertTrue('globally_enabled' in IDiscussionSettings)
|
||||
self.assertEqual(
|
||||
self.registry['plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.globally_enabled'],
|
||||
False)
|
||||
self.registry[
|
||||
'plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.globally_enabled'
|
||||
],
|
||||
False
|
||||
)
|
||||
|
||||
def test_anonymous_comments(self):
|
||||
# Check anonymous_comments record
|
||||
self.assertTrue('anonymous_comments' in IDiscussionSettings)
|
||||
self.assertEqual(self.registry['plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.anonymous_comments'], False)
|
||||
self.assertEqual(
|
||||
self.registry[
|
||||
'plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.anonymous_comments'
|
||||
],
|
||||
False
|
||||
)
|
||||
|
||||
def test_moderation_enabled(self):
|
||||
# Check globally_enabled record
|
||||
self.assertTrue('moderation_enabled' in IDiscussionSettings)
|
||||
self.assertEqual(
|
||||
self.registry['plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.moderation_enabled'],
|
||||
False)
|
||||
self.registry[
|
||||
'plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.moderation_enabled'
|
||||
],
|
||||
False
|
||||
)
|
||||
|
||||
def test_text_transform(self):
|
||||
self.assertTrue('text_transform' in IDiscussionSettings)
|
||||
self.assertEqual(
|
||||
self.registry['plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.text_transform'],
|
||||
'text/plain')
|
||||
self.registry[
|
||||
'plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.text_transform'
|
||||
],
|
||||
'text/plain'
|
||||
)
|
||||
|
||||
def test_captcha(self):
|
||||
# Check globally_enabled record
|
||||
self.assertTrue('captcha' in IDiscussionSettings)
|
||||
self.assertEqual(self.registry['plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.captcha'],
|
||||
'disabled')
|
||||
self.assertEqual(
|
||||
self.registry[
|
||||
'plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.captcha'
|
||||
],
|
||||
'disabled'
|
||||
)
|
||||
|
||||
def test_show_commenter_image(self):
|
||||
# Check show_commenter_image record
|
||||
self.assertTrue('show_commenter_image' in IDiscussionSettings)
|
||||
self.assertEqual(self.registry['plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.show_commenter_image'], True)
|
||||
self.assertEqual(
|
||||
self.registry[
|
||||
'plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.show_commenter_image'
|
||||
],
|
||||
True
|
||||
)
|
||||
|
||||
def test_moderator_notification_enabled(self):
|
||||
# Check show_commenter_image record
|
||||
self.assertTrue('moderator_notification_enabled' in
|
||||
IDiscussionSettings)
|
||||
self.assertEqual(self.registry['plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.moderator_notification_enabled'], False)
|
||||
self.assertTrue(
|
||||
'moderator_notification_enabled' in IDiscussionSettings
|
||||
)
|
||||
self.assertEqual(
|
||||
self.registry[
|
||||
'plone.app.discussion.interfaces.' +
|
||||
'IDiscussionSettings.moderator_notification_enabled'
|
||||
],
|
||||
False
|
||||
)
|
||||
|
||||
#def test_user_notification_enabled(self):
|
||||
# # Check show_commenter_image record
|
||||
@ -117,23 +152,32 @@ class ConfigurationChangedSubscriberTest(unittest.TestCase):
|
||||
changes.
|
||||
"""
|
||||
# By default the one_state_workflow without moderation is enabled
|
||||
self.assertEqual(('one_state_workflow',),
|
||||
self.assertEqual(
|
||||
('one_state_workflow',),
|
||||
self.portal.portal_workflow.getChainForPortalType(
|
||||
'Discussion Item'))
|
||||
'Discussion Item'
|
||||
)
|
||||
)
|
||||
|
||||
# Enable moderation in the discussion control panel
|
||||
self.settings.moderation_enabled = True
|
||||
|
||||
# Make sure the comment_review_workflow with moderation enabled is
|
||||
# enabled
|
||||
self.assertEqual(('comment_review_workflow',),
|
||||
self.assertEqual(
|
||||
('comment_review_workflow',),
|
||||
self.portal.portal_workflow.getChainForPortalType(
|
||||
'Discussion Item'))
|
||||
'Discussion Item'
|
||||
)
|
||||
)
|
||||
# And back
|
||||
self.settings.moderation_enabled = False
|
||||
self.assertEqual(('one_state_workflow',),
|
||||
self.assertEqual(
|
||||
('one_state_workflow',),
|
||||
self.portal.portal_workflow.getChainForPortalType(
|
||||
'Discussion Item'))
|
||||
'Discussion Item'
|
||||
)
|
||||
)
|
||||
|
||||
def test_change_workflow_in_types_control_panel(self):
|
||||
"""Make sure the setting in the discussion control panel is changed
|
||||
@ -146,7 +190,8 @@ class ConfigurationChangedSubscriberTest(unittest.TestCase):
|
||||
# Enable the 'comment_review_workflow' with moderation enabled
|
||||
self.portal.portal_workflow.setChainForPortalTypes(
|
||||
('Discussion Item',),
|
||||
('comment_review_workflow',))
|
||||
('comment_review_workflow',)
|
||||
)
|
||||
|
||||
# Make sure the moderation_enabled settings has changed
|
||||
self.settings.moderation_enabled = True
|
||||
@ -154,13 +199,15 @@ class ConfigurationChangedSubscriberTest(unittest.TestCase):
|
||||
# Enable the 'comment_review_workflow' with moderation enabled
|
||||
self.portal.portal_workflow.setChainForPortalTypes(
|
||||
('Discussion Item',),
|
||||
('one_state_workflow',))
|
||||
('one_state_workflow',)
|
||||
)
|
||||
self.settings.moderation_enabled = True
|
||||
|
||||
# Enable a 'custom' discussion workflow
|
||||
self.portal.portal_workflow.setChainForPortalTypes(
|
||||
('Discussion Item',),
|
||||
('intranet_workflow',))
|
||||
('intranet_workflow',)
|
||||
)
|
||||
|
||||
# Setting has not changed. A Custom workflow disables the
|
||||
# enable_moderation checkbox in the discussion control panel. The
|
||||
|
@ -15,8 +15,9 @@ from Products.CMFCore.utils import getToolByName
|
||||
|
||||
from plone.app.testing import TEST_USER_ID, setRoles
|
||||
|
||||
from plone.app.discussion.testing import \
|
||||
from plone.app.discussion.testing import (
|
||||
PLONE_APP_DISCUSSION_INTEGRATION_TESTING
|
||||
)
|
||||
|
||||
from plone.app.discussion import interfaces
|
||||
from plone.app.discussion.interfaces import IConversation
|
||||
@ -25,7 +26,7 @@ from plone.app.discussion.interfaces import IReplies
|
||||
from plone.app.discussion.interfaces import IDiscussionSettings
|
||||
|
||||
try:
|
||||
import plone.dexterity
|
||||
from plone.dexterity.interfaces import IDexterityContent
|
||||
DEXTERITY = True
|
||||
except:
|
||||
DEXTERITY = False
|
||||
@ -44,9 +45,11 @@ class ConversationTest(unittest.TestCase):
|
||||
typetool = self.portal.portal_types
|
||||
typetool.constructContent('Document', self.portal, 'doc1')
|
||||
self.typetool = typetool
|
||||
self.portal_discussion = getToolByName(self.portal,
|
||||
self.portal_discussion = getToolByName(
|
||||
self.portal,
|
||||
'portal_discussion',
|
||||
None)
|
||||
None,
|
||||
)
|
||||
# Allow discussion
|
||||
registry = queryUtility(IRegistry)
|
||||
settings = registry.forInterface(IDiscussionSettings)
|
||||
@ -68,14 +71,18 @@ class ConversationTest(unittest.TestCase):
|
||||
# Check that the conversation methods return the correct data
|
||||
self.assertTrue(isinstance(comment.comment_id, long))
|
||||
self.assertTrue(IComment.providedBy(conversation[new_id]))
|
||||
self.assertEqual(aq_base(conversation[new_id].__parent__),
|
||||
aq_base(conversation))
|
||||
self.assertEqual(
|
||||
aq_base(conversation[new_id].__parent__),
|
||||
aq_base(conversation)
|
||||
)
|
||||
self.assertEqual(new_id, comment.comment_id)
|
||||
self.assertEqual(len(list(conversation.getComments())), 1)
|
||||
self.assertEqual(len(tuple(conversation.getThreads())), 1)
|
||||
self.assertEqual(conversation.total_comments, 1)
|
||||
self.assertTrue(conversation.last_comment_date - datetime.utcnow() <
|
||||
timedelta(seconds=1))
|
||||
self.assertTrue(
|
||||
conversation.last_comment_date - datetime.utcnow() <
|
||||
timedelta(seconds=1)
|
||||
)
|
||||
|
||||
def test_private_comment(self):
|
||||
conversation = IConversation(self.portal.doc1)
|
||||
@ -169,8 +176,8 @@ class ConversationTest(unittest.TestCase):
|
||||
|
||||
del conversation[new_id_1]
|
||||
|
||||
self.assertEqual(
|
||||
[{'comment': comment2, 'depth': 0, 'id': new_id_2},
|
||||
self.assertEqual([
|
||||
{'comment': comment2, 'depth': 0, 'id': new_id_2},
|
||||
{'comment': comment2_1, 'depth': 1, 'id': new_id_2_1},
|
||||
], list(conversation.getThreads()))
|
||||
|
||||
@ -212,10 +219,14 @@ class ConversationTest(unittest.TestCase):
|
||||
# By default, allow_discussion on newly created content objects is
|
||||
# set to False
|
||||
portal_discussion = getToolByName(self.portal, 'portal_discussion')
|
||||
self.assertEqual(portal_discussion.isDiscussionAllowedFor(
|
||||
self.portal.doc1), False)
|
||||
self.assertEqual(self.portal.doc1.getTypeInfo().allowDiscussion(),
|
||||
False)
|
||||
self.assertEqual(
|
||||
portal_discussion.isDiscussionAllowedFor(self.portal.doc1),
|
||||
False
|
||||
)
|
||||
self.assertEqual(
|
||||
self.portal.doc1.getTypeInfo().allowDiscussion(),
|
||||
False
|
||||
)
|
||||
|
||||
# The allow discussion flag is None by default
|
||||
self.assertFalse(getattr(self.portal.doc1, 'allow_discussion', None))
|
||||
@ -225,35 +236,51 @@ class ConversationTest(unittest.TestCase):
|
||||
# type and check if the Document object allows discussion now.
|
||||
document_fti = getattr(portal_types, 'Document')
|
||||
document_fti.manage_changeProperties(allow_discussion=True)
|
||||
self.assertEqual(portal_discussion.isDiscussionAllowedFor(
|
||||
self.portal.doc1), True)
|
||||
self.assertEqual(self.portal.doc1.getTypeInfo().allowDiscussion(),
|
||||
True)
|
||||
self.assertEqual(
|
||||
portal_discussion.isDiscussionAllowedFor(self.portal.doc1),
|
||||
True
|
||||
)
|
||||
self.assertEqual(
|
||||
self.portal.doc1.getTypeInfo().allowDiscussion(),
|
||||
True
|
||||
)
|
||||
|
||||
# We can also override the allow_discussion locally
|
||||
self.portal_discussion.overrideDiscussionFor(self.portal.doc1, False)
|
||||
# Check if the Document discussion is disabled
|
||||
self.assertEqual(portal_discussion.isDiscussionAllowedFor(
|
||||
self.portal.doc1), False)
|
||||
self.assertEqual(
|
||||
portal_discussion.isDiscussionAllowedFor(self.portal.doc1),
|
||||
False
|
||||
)
|
||||
# Check that the local allow_discussion flag is now explicitly set to
|
||||
# False
|
||||
self.assertEqual(getattr(self.portal.doc1, 'allow_discussion', None),
|
||||
False)
|
||||
self.assertEqual(
|
||||
getattr(self.portal.doc1, 'allow_discussion', None),
|
||||
False
|
||||
)
|
||||
|
||||
# Disallow discussion on the Document content type again
|
||||
document_fti.manage_changeProperties(allow_discussion=False)
|
||||
self.assertEqual(portal_discussion.isDiscussionAllowedFor(
|
||||
self.portal.doc1), False)
|
||||
self.assertEqual(self.portal.doc1.getTypeInfo().allowDiscussion(),
|
||||
False)
|
||||
self.assertEqual(
|
||||
portal_discussion.isDiscussionAllowedFor(self.portal.doc1),
|
||||
False
|
||||
)
|
||||
self.assertEqual(
|
||||
self.portal.doc1.getTypeInfo().allowDiscussion(),
|
||||
False
|
||||
)
|
||||
|
||||
# Now we override allow_discussion again (True) for the Document
|
||||
# content object
|
||||
self.portal_discussion.overrideDiscussionFor(self.portal.doc1, True)
|
||||
self.assertEqual(portal_discussion.isDiscussionAllowedFor(
|
||||
self.portal.doc1), True)
|
||||
self.assertEqual(getattr(self.portal.doc1, 'allow_discussion', None),
|
||||
True)
|
||||
self.assertEqual(
|
||||
portal_discussion.isDiscussionAllowedFor(self.portal.doc1),
|
||||
True
|
||||
)
|
||||
self.assertEqual(
|
||||
getattr(self.portal.doc1, 'allow_discussion', None),
|
||||
True
|
||||
)
|
||||
|
||||
def test_comments_enabled_on_doc_in_subfolder(self):
|
||||
typetool = self.portal.portal_types
|
||||
@ -338,7 +365,8 @@ class ConversationTest(unittest.TestCase):
|
||||
|
||||
# Create a conversation.
|
||||
conversation = self.portal.doc1.restrictedTraverse(
|
||||
'@@conversation_view')
|
||||
'@@conversation_view'
|
||||
)
|
||||
|
||||
# The Document content type is disabled by default
|
||||
self.assertEqual(conversation.enabled(), False)
|
||||
@ -416,7 +444,8 @@ class ConversationTest(unittest.TestCase):
|
||||
|
||||
# Create a conversation.
|
||||
conversation = self.portal.doc1.restrictedTraverse(
|
||||
'@@conversation_view')
|
||||
'@@conversation_view'
|
||||
)
|
||||
|
||||
# Discussion is disallowed by default
|
||||
self.assertEqual(conversation.enabled(), False)
|
||||
@ -599,30 +628,42 @@ class ConversationTest(unittest.TestCase):
|
||||
new_comment3_id = conversation.addComment(comment3)
|
||||
|
||||
# check if the latest comment is exactly one day old
|
||||
self.assertTrue(conversation.last_comment_date < datetime.utcnow() -
|
||||
timedelta(hours=23, minutes=59, seconds=59))
|
||||
self.assertTrue(conversation.last_comment_date >
|
||||
datetime.utcnow() - timedelta(days=1, seconds=1))
|
||||
self.assertTrue(
|
||||
conversation.last_comment_date < datetime.utcnow() -
|
||||
timedelta(hours=23, minutes=59, seconds=59)
|
||||
)
|
||||
self.assertTrue(
|
||||
conversation.last_comment_date >
|
||||
datetime.utcnow() - timedelta(days=1, seconds=1)
|
||||
)
|
||||
|
||||
# remove the latest comment
|
||||
del conversation[new_comment3_id]
|
||||
|
||||
# check if the latest comment has been updated
|
||||
# the latest comment should be exactly two days old
|
||||
self.assertTrue(conversation.last_comment_date < datetime.utcnow() -
|
||||
timedelta(days=1, hours=23, minutes=59, seconds=59))
|
||||
self.assertTrue(conversation.last_comment_date > datetime.utcnow() -
|
||||
timedelta(days=2, seconds=1))
|
||||
self.assertTrue(
|
||||
conversation.last_comment_date < datetime.utcnow() -
|
||||
timedelta(days=1, hours=23, minutes=59, seconds=59)
|
||||
)
|
||||
self.assertTrue(
|
||||
conversation.last_comment_date > datetime.utcnow() -
|
||||
timedelta(days=2, seconds=1)
|
||||
)
|
||||
|
||||
# remove the latest comment again
|
||||
del conversation[new_comment2_id]
|
||||
|
||||
# check if the latest comment has been updated
|
||||
# the latest comment should be exactly four days old
|
||||
self.assertTrue(conversation.last_comment_date < datetime.utcnow() -
|
||||
timedelta(days=3, hours=23, minutes=59, seconds=59))
|
||||
self.assertTrue(conversation.last_comment_date > datetime.utcnow() -
|
||||
timedelta(days=4, seconds=2))
|
||||
self.assertTrue(
|
||||
conversation.last_comment_date < datetime.utcnow() -
|
||||
timedelta(days=3, hours=23, minutes=59, seconds=59)
|
||||
)
|
||||
self.assertTrue(
|
||||
conversation.last_comment_date > datetime.utcnow() -
|
||||
timedelta(days=4, seconds=2)
|
||||
)
|
||||
|
||||
def test_get_comments_full(self):
|
||||
pass
|
||||
@ -685,8 +726,8 @@ class ConversationTest(unittest.TestCase):
|
||||
|
||||
# Get threads
|
||||
|
||||
self.assertEqual(
|
||||
[{'comment': comment1, 'depth': 0, 'id': new_id_1},
|
||||
self.assertEqual([
|
||||
{'comment': comment1, 'depth': 0, 'id': new_id_1},
|
||||
{'comment': comment1_1, 'depth': 1, 'id': new_id_1_1},
|
||||
{'comment': comment1_1_1, 'depth': 2, 'id': new_id_1_1_1},
|
||||
{'comment': comment1_2, 'depth': 1, 'id': new_id_1_2},
|
||||
@ -703,20 +744,26 @@ class ConversationTest(unittest.TestCase):
|
||||
# make sure we can traverse to conversations and get a URL and path
|
||||
|
||||
conversation = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default')
|
||||
'++conversation++default'
|
||||
)
|
||||
self.assertTrue(IConversation.providedBy(conversation))
|
||||
|
||||
self.assertEqual(('', 'plone', 'doc1', '++conversation++default'),
|
||||
conversation.getPhysicalPath())
|
||||
self.assertEqual('http://nohost/plone/doc1/++conversation++default',
|
||||
conversation.absolute_url())
|
||||
self.assertEqual(
|
||||
('', 'plone', 'doc1', '++conversation++default'),
|
||||
conversation.getPhysicalPath()
|
||||
)
|
||||
self.assertEqual(
|
||||
'http://nohost/plone/doc1/++conversation++default',
|
||||
conversation.absolute_url()
|
||||
)
|
||||
|
||||
def test_unconvertible_id(self):
|
||||
# make sure the conversation view doesn't break when given comment id
|
||||
# can't be converted to long
|
||||
|
||||
conversation = self.portal.doc1.restrictedTraverse(
|
||||
'++conversation++default/ThisCantBeRight')
|
||||
'++conversation++default/ThisCantBeRight'
|
||||
)
|
||||
self.assertEqual(conversation, None)
|
||||
|
||||
def test_parent(self):
|
||||
@ -737,8 +784,10 @@ class ConversationTest(unittest.TestCase):
|
||||
def test_no_comment(self):
|
||||
IConversation(self.portal.doc1)
|
||||
# Make sure no conversation has been created
|
||||
self.assertTrue('plone.app.discussion:conversation' not in
|
||||
IAnnotations(self.portal.doc1))
|
||||
self.assertTrue(
|
||||
'plone.app.discussion:conversation' not in
|
||||
IAnnotations(self.portal.doc1)
|
||||
)
|
||||
|
||||
|
||||
class ConversationEnabledForDexterityTypesTest(unittest.TestCase):
|
||||
@ -750,15 +799,16 @@ class ConversationEnabledForDexterityTypesTest(unittest.TestCase):
|
||||
setRoles(self.portal, TEST_USER_ID, ['Manager'])
|
||||
interface.alsoProvides(
|
||||
self.portal.REQUEST,
|
||||
interfaces.IDiscussionLayer)
|
||||
interfaces.IDiscussionLayer
|
||||
)
|
||||
|
||||
typetool = self.portal.portal_types
|
||||
typetool.constructContent('Document', self.portal, 'doc1')
|
||||
if DEXTERITY:
|
||||
from plone.dexterity.interfaces import IDexterityContent
|
||||
interface.alsoProvides(
|
||||
self.portal.doc1,
|
||||
IDexterityContent)
|
||||
IDexterityContent
|
||||
)
|
||||
|
||||
def _makeOne(self, *args, **kw):
|
||||
return self.portal.doc1.restrictedTraverse('@@conversation_view')
|
||||
|
Loading…
Reference in New Issue
Block a user