Back to index

plone3  3.1.7
test_DiscussionReply.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 http://zope.org/Collectors/CMF/318
00014 
00015 $Id: test_DiscussionReply.py 73035 2007-03-07 16:41:03Z jens $
00016 """
00017 
00018 import unittest
00019 from Testing import ZopeTestCase
00020 
00021 from AccessControl.SecurityManagement import newSecurityManager
00022 from zope.app.component.hooks import setSite
00023 
00024 from Products.CMFDefault.testing import FunctionalLayer
00025 
00026 
00027 class DiscussionReplyTest(ZopeTestCase.FunctionalTestCase):
00028 
00029     layer = FunctionalLayer
00030 
00031     def afterSetUp(self):
00032         setSite(self.app.site)
00033         self.portal = self.app.site
00034         # Become a Manager
00035         self.uf = self.portal.acl_users
00036         self.uf.userFolderAddUser('manager', '', ['Manager'], [])
00037         self.site_login('manager')
00038         # Make a document
00039         self.discussion = self.portal.portal_discussion
00040         self.portal.invokeFactory('Document', id='doc')
00041         self.discussion.overrideDiscussionFor(self.portal.doc, 1)
00042         # Publish it
00043         self.workflow = self.portal.portal_workflow
00044         self.workflow.doActionFor(self.portal.doc, 'publish')
00045 
00046     def site_login(self, name):
00047         user = self.uf.getUserById(name)
00048         user = user.__of__(self.uf)
00049         newSecurityManager(None, user)
00050 
00051     def testDiscussionReply(self):
00052         self.discussion.getDiscussionFor(self.portal.doc)
00053         self.portal.doc.talkback.createReply('Title', 'Text')
00054         reply = self.portal.doc.talkback.objectValues()[0]
00055         self.assertEqual(reply.Title(), 'Title')
00056         self.assertEqual(reply.EditableBody(), 'Text')
00057 
00058 
00059 class DiscussionReplyTestMember(DiscussionReplyTest):
00060 
00061     # Run the test again as another Member, i.e. reply to someone
00062     # else's document.
00063 
00064     def afterSetUp(self):
00065         DiscussionReplyTest.afterSetUp(self)
00066         self.uf.userFolderAddUser('member', '', ['Member'], [])
00067         self.site_login('member')
00068 
00069 
00070 def test_suite():
00071     suite = unittest.TestSuite()
00072     suite.addTest(unittest.makeSuite(DiscussionReplyTest))
00073     suite.addTest(unittest.makeSuite(DiscussionReplyTestMember))
00074     return suite
00075 
00076 if __name__ == '__main__':
00077     from Products.CMFCore.testing import run
00078     run(test_suite())