Back to index

plone3  3.1.7
test_PortalContent.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 PortalContent module.
00014 
00015 $Id: test_PortalContent.py 77004 2007-06-24 08:57:54Z yuppie $
00016 """
00017 
00018 import unittest
00019 import Testing
00020 
00021 from AccessControl.SecurityManagement import newSecurityManager
00022 from Acquisition import aq_base
00023 from OFS.Folder import Folder
00024 from zope.testing.cleanup import cleanUp
00025 
00026 from Products.CMFCore.exceptions import NotFound
00027 from Products.CMFCore.testing import TraversingEventZCMLLayer
00028 from Products.CMFCore.tests.base.dummy import DummyContent
00029 from Products.CMFCore.tests.base.dummy import DummyObject
00030 from Products.CMFCore.tests.base.dummy import DummySite
00031 from Products.CMFCore.tests.base.dummy import DummyTool
00032 from Products.CMFCore.tests.base.dummy import DummyUserFolder
00033 from Products.CMFCore.tests.base.testcase import SecurityRequestTest
00034 
00035 
00036 class PortalContentTests(unittest.TestCase):
00037 
00038     def tearDown(self):
00039         cleanUp()
00040 
00041     def test_z2interfaces(self):
00042         from Interface.Verify import verifyClass
00043         from Products.CMFCore.interfaces.Contentish \
00044                 import Contentish as IContentish
00045         from Products.CMFCore.interfaces.Dynamic \
00046                 import DynamicType as IDynamicType
00047         from Products.CMFCore.PortalContent import PortalContent
00048 
00049         verifyClass(IContentish, PortalContent)
00050         verifyClass(IDynamicType, PortalContent)
00051 
00052     def test_z3interfaces(self):
00053         from zope.interface.verify import verifyClass
00054         from Products.CMFCore.interfaces import IContentish
00055         from Products.CMFCore.interfaces import IDynamicType
00056         from Products.CMFCore.PortalContent import PortalContent
00057 
00058         verifyClass(IContentish, PortalContent)
00059         verifyClass(IDynamicType, PortalContent)
00060 
00061     def _setupCallTests(self, aliases):
00062         # root
00063         root = Folder( 'root' )
00064 
00065         # set up dummy type info with problematic double-default alias
00066         root._setObject( 'portal_types', DummyTool() )
00067         root.portal_types._type_actions = aliases
00068 
00069         # dummy content and skin
00070         root._setObject( 'dummycontent', DummyContent() )
00071         root._setObject( 'dummy_view', DummyObject() )
00072         return root.dummycontent
00073 
00074     def test_DoubleDefaultAlias(self):
00075         test_aliases = ( ('(Default)', '(Default)'),
00076                          ('view', 'dummy_view'),
00077                        )
00078         ob = self._setupCallTests(test_aliases)
00079         # PortalContent no longer supports the BBB '(Default)' alias
00080         self.assertRaises(NotFound, ob)
00081 
00082     def test_BlankDefaultAlias(self):
00083         test_aliases = ( ('(Default)', ''),
00084                          ('view', 'dummy_view'),
00085                        )
00086         ob = self._setupCallTests(test_aliases)
00087         # blank values are not valid
00088         self.assertRaises(NotFound, ob)
00089 
00090     def test_SpecificAlias(self):
00091         test_aliases = ( ('(Default)', 'dummy_view'),
00092                        )
00093         ob = self._setupCallTests(test_aliases)
00094         self.assertEqual( ob(), 'dummy' )
00095 
00096 
00097 class TestContentCopyPaste(SecurityRequestTest):
00098 
00099     # Tests related to http://www.zope.org/Collectors/CMF/205
00100     # Copy/pasting a content item must set ownership to pasting user
00101 
00102     layer = TraversingEventZCMLLayer
00103 
00104     def setUp(self):
00105         SecurityRequestTest.setUp(self)
00106 
00107         self.root._setObject('site', DummySite('site'))
00108         self.site = self.root.site
00109         self.acl_users = self.site._setObject('acl_users', DummyUserFolder())
00110 
00111     def _initContent(self, folder, id):
00112         from Products.CMFCore.PortalContent import PortalContent
00113 
00114         c = PortalContent()
00115         c._setId(id)
00116         c.meta_type = 'File'
00117         folder._setObject(id, c)
00118         return folder._getOb(id)
00119 
00120     def test_CopyPasteSetsOwnership(self):
00121         # Copy/pasting a File should set new ownership including local roles
00122         from OFS.Folder import Folder
00123 
00124         acl_users = self.acl_users
00125         folder1 = self.site._setObject('folder1', Folder('folder1'))
00126         folder2 = self.site._setObject('folder2', Folder('folder2'))
00127 
00128         newSecurityManager(None, acl_users.user_foo)
00129         content = self._initContent(folder1, 'content')
00130         content.manage_setLocalRoles(acl_users.user_foo.getId(), ['Owner'])
00131 
00132         newSecurityManager(None, acl_users.all_powerful_Oz)
00133         cb = folder1.manage_copyObjects(['content'])
00134         folder2.manage_pasteObjects(cb)
00135 
00136         # Now test executable ownership and "owner" local role
00137         # "member" should have both.
00138         moved = folder2._getOb('content')
00139         self.assertEqual(aq_base(moved.getOwner()),
00140                          aq_base(acl_users.all_powerful_Oz))
00141 
00142         local_roles = moved.get_local_roles()
00143         self.assertEqual(len(local_roles), 1)
00144         userid, roles = local_roles[0]
00145         self.assertEqual(userid, acl_users.all_powerful_Oz.getId())
00146         self.assertEqual(len(roles), 1)
00147         self.assertEqual(roles[0], 'Owner')
00148 
00149 
00150 def test_suite():
00151     return unittest.TestSuite((
00152         unittest.makeSuite(PortalContentTests),
00153         unittest.makeSuite(TestContentCopyPaste),
00154         ))
00155 
00156 if __name__ == '__main__':
00157     from Products.CMFCore.testing import run
00158     run(test_suite())