Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
CMFPlone.tests.testPortalFactory.TestPortalFactory Class Reference
Inheritance diagram for CMFPlone.tests.testPortalFactory.TestPortalFactory:
Inheritance graph
[legend]
Collaboration diagram for CMFPlone.tests.testPortalFactory.TestPortalFactory:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def afterSetUp
def testTraverse
def testTraverseTwiceByDifferentContentTypes
def testTempFolderLocalRoles
def testTempFolderLocalRolesWithBlocking
def testTempFolderPermissionAq
def testTempObjectLocalRolesBug
def testTempFolderPermissions
def setRequestMethod
def getAuthenticator
def setupAuthenticator

Public Attributes

 membership

Detailed Description

Definition at line 23 of file testPortalFactory.py.


Member Function Documentation

Definition at line 25 of file testPortalFactory.py.

00025 
00026     def afterSetUp(self):
00027         self.membership = self.portal.portal_membership
00028         self.membership.addMember('member', 'secret', ['Member'], [])
00029         self.membership.addMember('manager', 'secret', ['Manager'], [])

Definition at line 30 of file PloneTestCase.py.

00030 
00031     def getAuthenticator(self):
00032         tag = AuthenticatorView('context', 'request').authenticator()
00033         pattern = '<input .*name="(\w+)".*value="(\w+)"'
00034         return match(pattern, tag).groups()

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFPlone.tests.PloneTestCase.PloneTestCase.setRequestMethod (   self,
  method 
) [inherited]
This is a stub now, but in case you want to try
   something fancy on Your Branch (tm), put it here.

Definition at line 26 of file PloneTestCase.py.

00026 
00027     def setRequestMethod(self, method):
00028         self.app.REQUEST.set('REQUEST_METHOD', method)
00029         self.app.REQUEST.method = method

Here is the caller graph for this function:

Definition at line 35 of file PloneTestCase.py.

00035 
00036     def setupAuthenticator(self):
00037         name, token = self.getAuthenticator()
00038         self.app.REQUEST.form[name] = token
00039 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 43 of file testPortalFactory.py.

00043 
00044     def testTempFolderLocalRoles(self):
00045         # Temporary objects should "inherit" local roles from container
00046         member = self.membership.getMemberById('member')
00047         self.portal.acl_users.addRole('Foo')
00048 
00049         self.folder.manage_addLocalRoles('member', ('Foo',))
00050         self.folder.invokeFactory('Folder', id='folder2')
00051         self.folder.folder2.manage_addLocalRoles('member', ('Reviewer',))
00052 
00053         self.assertEqual(sortTuple(member.getRolesInContext(self.folder)),
00054                          ('Authenticated', 'Foo', 'Member'))
00055 
00056         temp_object = self.folder.restrictedTraverse('portal_factory/Document/tmp_id')
00057         self.assertEqual(sortTuple(member.getRolesInContext(temp_object)),
00058                          ('Authenticated', 'Foo', 'Member'))
00059 
00060         temp_object2 = self.folder.folder2.restrictedTraverse('portal_factory/Document/tmp_id')
00061         self.assertEqual(sortTuple(member.getRolesInContext(temp_object2)),
00062                          ('Authenticated', 'Foo', 'Member', 'Reviewer'))

Here is the call graph for this function:

Definition at line 63 of file testPortalFactory.py.

00063 
00064     def testTempFolderLocalRolesWithBlocking(self):
00065         # Temporary objects should "inherit" local roles from container,
00066         # but also need to respect PLIP 16 local role blocking
00067         member = self.membership.getMemberById('member')
00068         self.portal.acl_users.addRole('Foo')
00069 
00070         self.folder.manage_addLocalRoles('member', ('Foo',))
00071         self.folder.invokeFactory('Folder', id='folder2')
00072         self.folder.folder2.manage_addLocalRoles('member', ('Reviewer',))
00073         # make folder2 not inherit local roles
00074         self.portal.plone_utils.acquireLocalRoles(self.folder.folder2, status=0)
00075 
00076         self.assertEqual(sortTuple(member.getRolesInContext(self.folder.folder2)),
00077                          ('Authenticated', 'Member', 'Reviewer'))
00078 
00079         temp_object2 = self.folder.folder2.restrictedTraverse('portal_factory/Document/tmp_id')
00080         self.assertEqual(sortTuple(member.getRolesInContext(temp_object2)),
00081                          ('Authenticated', 'Member', 'Reviewer'))

Here is the call graph for this function:

Definition at line 82 of file testPortalFactory.py.

00082 
00083     def testTempFolderPermissionAq(self):
00084         from Products.CMFPlone.FactoryTool import FACTORY_INFO
00085         # Temporary folder should acquire same permissions as the intended parent
00086         self.login('manager')
00087         self.portal.invokeFactory('Folder', id='folder1')
00088         folder1 = self.portal.folder1
00089         folder1.invokeFactory('Folder', id='folder2')
00090         folder2 = folder1.folder2
00091         folder2.invokeFactory('Folder', id='folder3')
00092         folder3 = folder1.folder2.folder3
00093         folder3.restrictedTraverse('portal_factory/Document/tmp_id')
00094         # clear out the cached factory info (this would happen by itself in an actual request)
00095         self.portal.REQUEST.set(FACTORY_INFO, {})
00096 
00097         # make sure no permission is available initially
00098         self.login('member')
00099         pm = self.portal.portal_membership
00100         assert (not pm.checkPermission(ADD_DOC_PERM, folder3))
00101         self.assertRaises(Unauthorized, folder3.restrictedTraverse, 'portal_factory/Document/tmp_id/atct_edit')
00102         # clear out the cached factory info (this would happen by itself in an actual request)
00103         self.portal.REQUEST.set(FACTORY_INFO, {})
00104 
00105         # grant the add permission on the parent
00106         self.login('manager')
00107         folder3.manage_permission(ADD_DOC_PERM, ['Authenticated'], 1)
00108 
00109         # now make sure we can see it
00110         self.login('member')
00111         assert (pm.checkPermission(ADD_DOC_PERM, folder3))
00112         #folder3.setConstrainTypesMode(0)
00113         folder3.restrictedTraverse('portal_factory/Document/tmp_id/atct_edit')
00114         # clear out the cached factory info (this would happen by itself in an actual request)
00115         self.portal.REQUEST.set(FACTORY_INFO, {})
00116 
00117         # blow away folder3 and start again
00118         self.login('manager')
00119         folder2.manage_delObjects(['folder3'])
00120         folder2.invokeFactory('Folder', id='folder3')
00121         folder3 = folder1.folder2.folder3
00122 
00123         # grant the add permission on the grandparent
00124         folder2.manage_permission(ADD_DOC_PERM, ['Authenticated'], 1)
00125 
00126         # now make sure we can see it
00127         self.login('member')
00128         assert (pm.checkPermission(ADD_DOC_PERM, folder3))
00129         folder3.restrictedTraverse('portal_factory/Document/tmp_id')
00130         # clear out the cached factory info (this would happen by itself in an actual request)
00131         self.portal.REQUEST.set(FACTORY_INFO, {})
00132 
00133         # blow away folder2 and start again
00134         self.login('manager')
00135         folder1.manage_delObjects(['folder2'])
00136         folder1.invokeFactory('Folder', id='folder2')
00137         folder2 = folder1.folder2
00138         folder2.invokeFactory('Folder', id='folder3')
00139         folder3 = folder1.folder2.folder3
00140 
00141         # add the permission on the portal root
00142         self.portal.manage_permission(ADD_DOC_PERM, ['Authenticated'], 1)
00143 
00144         # now make sure we can see it
00145         self.login('member')
00146         assert (pm.checkPermission(ADD_DOC_PERM, folder3))
00147         folder3.restrictedTraverse('portal_factory/Document/tmp_id')
00148         # clear out the cached factory info (this would happen by itself in an actual request)
00149         self.portal.REQUEST.set(FACTORY_INFO, {})
00150 

Here is the call graph for this function:

Definition at line 177 of file testPortalFactory.py.

00177 
00178     def testTempFolderPermissions(self):
00179         # TempFolder should "inherit" permission mappings from container
00180         previous_roles = [r for r in self.folder.rolesOfPermission(AddPortalContent) if r['name'] == 'Anonymous']
00181         self.folder.manage_permission(AddPortalContent, ['Anonymous'], 1)
00182         new_roles = [r for r in self.folder.rolesOfPermission(AddPortalContent) if r['name'] == 'Anonymous']
00183         self.failIfEqual(previous_roles, new_roles)
00184 
00185         temp_folder = self.folder.restrictedTraverse(
00186                                 'portal_factory/Document/tmp_id').aq_parent
00187         temp_roles = [r for r in temp_folder.rolesOfPermission(AddPortalContent) if r['name'] == 'Anonymous']
00188 
00189         self.assertEqual(temp_roles, new_roles)
00190 

Definition at line 151 of file testPortalFactory.py.

00151 
00152     def testTempObjectLocalRolesBug(self):
00153         # Evil monkey patch should not change all objects of a class
00154         self.createMemberarea('member')
00155         member = self.membership.getMemberById('member')
00156 
00157         # Make an unrelated non-temporary object for comparison
00158         self.login('manager')
00159         self.portal.invokeFactory('Document', id='nontmp_id')
00160         nontemp_object = getattr(self.portal, 'nontmp_id')
00161 
00162         # Assume identify of the ordinary member
00163         self.login('member')
00164         folder = self.membership.getHomeFolder()
00165         temp_object = folder.restrictedTraverse('portal_factory/Document/tmp_id')
00166 
00167         # Make sure member is owner of temporary object
00168         self.assertEqual(sortTuple(member.getRolesInContext(temp_object)),
00169                          ('Authenticated', 'Member', 'Owner'))
00170         self.assertEqual(temp_object.Creator(), 'member')
00171 
00172         # Make sure member is not owner of non-temporary object
00173         # (i.e. make sure our evil monkey patch of the temporary instance has
00174         # not resulted in our patching all instances of the class)
00175         self.assertEqual(sortTuple(member.getRolesInContext(nontemp_object)),
00176                          ('Authenticated', 'Member'))

Here is the call graph for this function:

Definition at line 30 of file testPortalFactory.py.

00030 
00031     def testTraverse(self):
00032         temp_doc = self.folder.restrictedTraverse('portal_factory/Document/tmp_id')
00033         self.assertEqual(temp_doc.portal_type, 'Document')
00034         self.assertEqual(temp_doc.getId(), 'tmp_id')

Definition at line 35 of file testPortalFactory.py.

00035 
00036     def testTraverseTwiceByDifferentContentTypes(self):
00037         temp_doc = self.folder.restrictedTraverse('portal_factory/Document/tmp_id')
00038         self.assertEqual(temp_doc.portal_type, 'Document')
00039         self.assertEqual(temp_doc.getId(), 'tmp_id')
00040         temp_img = self.folder.restrictedTraverse('portal_factory/Image/tmp_id_image')
00041         self.assertEqual(temp_img.portal_type, 'Image')
00042         self.assertEqual(temp_img.getId(), 'tmp_id_image')


Member Data Documentation

Definition at line 26 of file testPortalFactory.py.


The documentation for this class was generated from the following file: