Back to index

plone3  3.1.7
test_DiscussionTool.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Unit tests for DiscussionTool module.
00014 
00015 $Id: test_DiscussionTool.py 81923 2007-11-18 22:51:13Z jens $
00016 """
00017 
00018 import unittest
00019 import Testing
00020 
00021 from zope.component import getSiteManager
00022 from zope.testing.cleanup import cleanUp
00023 
00024 from Products.CMFCore.interfaces import IDiscussionTool
00025 from Products.CMFCore.tests.base.dummy import DummyFolder
00026 from Products.CMFCore.tests.base.dummy import DummySite
00027 from Products.CMFCore.tests.base.dummy import DummyTool
00028 from Products.CMFCore.tests.base.testcase import SecurityTest
00029 
00030 
00031 class DiscussionToolTests(SecurityTest):
00032 
00033     def _makeOne(self, *args, **kw):
00034         from Products.CMFDefault.DiscussionTool import DiscussionTool
00035 
00036         return DiscussionTool(*args, **kw)
00037 
00038     def setUp(self):
00039         SecurityTest.setUp(self)
00040         self.site = DummySite('site')
00041         sm = getSiteManager()
00042         self.site._setObject( 'portal_discussion', self._makeOne() )
00043         sm.registerUtility(self.site.portal_discussion, IDiscussionTool)
00044         self.site._setObject( 'portal_types', DummyTool() )
00045 
00046     def tearDown(self):
00047         cleanUp()
00048         SecurityTest.tearDown(self)
00049 
00050     def test_z2interfaces(self):
00051         from Interface.Verify import verifyClass
00052         from Products.CMFCore.interfaces.portal_discussion \
00053                 import portal_discussion as IDiscussionTool
00054         from Products.CMFDefault.DiscussionTool import DiscussionTool
00055 
00056         verifyClass(IDiscussionTool, DiscussionTool)
00057 
00058     def test_z3interfaces(self):
00059         from zope.interface.verify import verifyClass
00060         from Products.CMFCore.interfaces import IDiscussionTool
00061         from Products.CMFDefault.DiscussionTool import DiscussionTool
00062 
00063         verifyClass(IDiscussionTool, DiscussionTool)
00064 
00065     def test_overrideDiscussionFor(self):
00066         dtool = self.site.portal_discussion
00067         foo = self.site._setObject( 'foo', DummyFolder() )
00068         baz = foo._setObject( 'baz', DummyFolder() )
00069 
00070         dtool.overrideDiscussionFor(foo, 1)
00071         self.failUnless( hasattr(foo.aq_base, 'allow_discussion') )
00072         try:
00073             dtool.overrideDiscussionFor(baz, None)
00074         except KeyError:
00075             self.fail('CMF Collector issue #201 (acquisition bug): '
00076                       'KeyError raised')
00077         dtool.overrideDiscussionFor(foo, None)
00078         self.failIf( hasattr(foo.aq_base, 'allow_discussion') )
00079 
00080         # https://bugs.launchpad.net/zope-cmf/+bug/162532: Don't break
00081         # if allow_discussion only exists at the class level
00082         class DummyContent:
00083             allow_discussion = False
00084             def getId(self): return 'dummy'
00085 
00086         dummy = DummyContent()
00087         try:
00088             dtool.overrideDiscussionFor(dummy, None)
00089         except AttributeError:
00090             self.fail('Launchpad issue 162532: AttributeError raised')
00091 
00092     def test_isDiscussionAllowedFor(self):
00093         # Test for Collector issue #398 (allow_discussion wrongly
00094         # acquired and used from parent)
00095         dtool = self.site.portal_discussion
00096         foo = self.site._setObject( 'foo', DummyFolder() )
00097         baz = foo._setObject( 'baz', DummyFolder() )
00098         dtool.overrideDiscussionFor(foo, 1)
00099 
00100         self.failIf(dtool.isDiscussionAllowedFor(baz))
00101 
00102     def test_getDiscussionFor(self):
00103         dtool = self.site.portal_discussion
00104         foo = self.site._setObject( 'foo', DummyFolder() )
00105         foo.allow_discussion = 1
00106         baz = foo._setObject( 'baz', DummyFolder() )
00107         baz.allow_discussion = 1
00108 
00109         self.failIf( hasattr(foo.aq_base, 'talkback') )
00110         talkback = dtool.getDiscussionFor(foo)
00111         self.failUnless( hasattr(foo.aq_base, 'talkback') )
00112         self.failIf( hasattr(baz.aq_base, 'talkback') )
00113         talkback = dtool.getDiscussionFor(baz)
00114         self.failUnless( hasattr(baz.aq_base, 'talkback'),
00115                          'CMF Collector issue #119 (acquisition bug): '
00116                          'talkback not created' )
00117 
00118 
00119 def test_suite():
00120     return unittest.TestSuite((
00121         unittest.makeSuite(DiscussionToolTests),
00122         ))
00123 
00124 if __name__ == '__main__':
00125     unittest.main(defaultTest='test_suite')