Back to index

plone3  3.1.7
test_cmfessentials.py
Go to the documentation of this file.
00001 ################################################################################
00002 #
00003 # Copyright (c) 2002-2005, Benjamin Saller <bcsaller@ideasuite.com>, and
00004 #                              the respective authors. All rights reserved.
00005 # For a list of Archetypes contributors see docs/CREDITS.txt.
00006 #
00007 # Redistribution and use in source and binary forms, with or without
00008 # modification, are permitted provided that the following conditions are met:
00009 #
00010 # * Redistributions of source code must retain the above copyright notice, this
00011 #   list of conditions and the following disclaimer.
00012 # * Redistributions in binary form must reproduce the above copyright notice,
00013 #   this list of conditions and the following disclaimer in the documentation
00014 #   and/or other materials provided with the distribution.
00015 # * Neither the name of the author nor the names of its contributors may be used
00016 #   to endorse or promote products derived from this software without specific
00017 #   prior written permission.
00018 #
00019 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00020 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00022 # FOR A PARTICULAR PURPOSE.
00023 #
00024 ################################################################################
00025 
00026 from Testing.ZopeTestCase import user_password
00027 from Products.Five.testbrowser import Browser
00028 
00029 from Products.Archetypes.tests.atsitetestcase import ATSiteTestCase
00030 from Products.Archetypes.tests.atsitetestcase import ATFunctionalSiteTestCase
00031 from Products.Archetypes.tests.utils import makeContent
00032 
00033 
00034 from Products.CMFCore.utils import _checkPermission as checkPerm
00035 from Products.CMFCore import permissions
00036 
00037 
00038 class TestPermissions(ATSiteTestCase):
00039     demo_types = ['DDocument', 'SimpleType', 'SimpleFolder',
00040                   'Fact', 'ComplexType']
00041 
00042     def afterSetUp(self):
00043         ATSiteTestCase.afterSetUp(self)
00044         # install AT within portal
00045         self.login()
00046         self.demo_instances = []
00047         for t in self.demo_types:
00048             # XXX: Fails with "Unauthorized" exception from
00049             #      CMFDefault/DiscussionTool.py:84, in overrideDiscussionFor
00050             #
00051             #      Note that BaseObject.initializeArchetype has a bare except
00052             #      that prints out the error instead of letting it through, so
00053             #      that there is no exception when running the test.
00054             inst = makeContent(self.folder, portal_type=t, id=t)
00055             self.demo_instances.append(inst)
00056 
00057     def testPermissions(self):
00058         for content in self.demo_instances:
00059             # XXX: Strangely enough we have correct permissions here, but not so
00060             #      in initializeArchetype
00061             self.failUnless(checkPerm(permissions.View, content))
00062             self.failUnless(checkPerm(permissions.AccessContentsInformation, content))
00063             self.failUnless(checkPerm(permissions.ModifyPortalContent, content))
00064 
00065     def testRendering(self):
00066         # Attempt to call each object and make sure it presents a rendered
00067         # html view
00068         for content in self.demo_instances:
00069             self.failUnless(isinstance(content(), basestring))
00070             self.failUnless(content().strip().startswith('<!DOCTYPE'))
00071 
00072 
00073 class TestFTICopy(ATFunctionalSiteTestCase):
00074     """Test for http://dev.plone.org/plone/ticket/6734: Cannot filter
00075     Addable Types with folderish FTI in portal_types.
00076     """
00077     
00078     def test6734(self):
00079         self.loginAsPortalOwner()
00080 
00081         # We start off by copying the existing SimpleFolder type to
00082         # our own type 'MySimpleFolder'.  For this type, we set the
00083         # SimpleFolder type to be the sole allowed content type.
00084         types = self.portal.portal_types
00085         types.manage_pasteObjects(types.manage_copyObjects(['SimpleFolder']))
00086         types.manage_renameObjects(['copy_of_SimpleFolder'], ['MySimpleFolder'])
00087         my_type = types['MySimpleFolder']
00088         attrs = dict(allowed_content_types=('SimpleFolder',),
00089                      filter_content_types=True,
00090                      portal_type='MySimpleFolder',
00091                      title='MySimpleFolder')
00092         my_type.__dict__.update(attrs)
00093 
00094         browser = Browser()
00095         browser.addHeader('Authorization',
00096                           'Basic %s:%s' % ('portal_owner', user_password))
00097         browser.open(self.folder.absolute_url())
00098         browser.getLink('Add new').click()
00099         browser.getControl('MySimpleFolder').click()
00100         browser.getControl('Add').click()
00101 
00102         browser.getControl('Title').value = 'My dope folder'
00103         browser.getControl('Save').click()
00104         self.failUnless('Changes saved.' in browser.contents)
00105         self.failUnless('My dope folder' in browser.contents)
00106 
00107 
00108 def test_suite():
00109     from unittest import TestSuite, makeSuite
00110     suite = TestSuite()
00111     suite.addTest(makeSuite(TestPermissions))
00112     suite.addTest(makeSuite(TestFTICopy))
00113     return suite