def testExecuteWithoutRole(self):
        e = LocalRoleAction()
        e.principal = 'user1'
        e.roles = set()

        ex = getMultiAdapter((self.portal, e, DummyEvent(self.folder)),
                             IExecutable)
        self.assertEquals(False, ex())
    def testExecuteWithError(self):
        acl_users = getToolByName(self.portal, 'acl_users')
        e = LocalRoleAction()
        e.principal = '%s-non-existent-user' % acl_users.getUserById('user1')
        e.roles = set(['Reader', ])

        ex = getMultiAdapter((self.portal, e, DummyEvent(self.folder)),
                             IExecutable)
        self.assertEquals(False, ex())
    def testExecuteWithGroup(self):
        e = LocalRoleAction()
        e.principal = 'Fav Customer'
        e.roles = set(['Reader', ])

        ex = getMultiAdapter((self.portal, e, DummyEvent(self.folder)),
                             IExecutable)
        self.assertEquals(True, ex())
        localroles = self.folder.get_local_roles_for_userid(userid=e.principal)
        self.failUnless(tuple(e.roles) == localroles)
    def testExecuteAsMember(self):
        e = LocalRoleAction()
        e.principal = 'user1'
        e.roles = set(['Reader', ])
        # User will have only Member role in the
        # context
        setRoles(self.portal, TEST_USER_ID, ['Member'])

        ex = getMultiAdapter((self.portal, e, DummyEvent(self.folder)),
                             IExecutable)
        self.assertEquals(True, ex())
        localroles = self.folder.get_local_roles_for_userid(userid=e.principal)
        self.failUnless(tuple(e.roles) == localroles)
    def testPickPrincipleFromContext(self):
        # Setup scenario
        self.portal.invokeFactory('Folder', 'customer', title='Fav Customer')
        folder = self.portal['customer']
        e = LocalRoleAction()
        e.field = 'title'
        e.roles = set(['Reader', ])

        ex = getMultiAdapter((self.portal, e, DummyEvent(folder)),
                             IExecutable)
        self.assertEquals(True, ex())
        localroles = folder.get_local_roles_for_userid(userid='Fav Customer')
        self.failUnless(tuple(e.roles) == localroles)
    def testExecuteWithoutMembershipTool(self):
        ''' Test what happens if portal_membership is not available '''
        # Remove portal_tool
        self.portal._delOb('portal_membership')

        # Execute action
        e = LocalRoleAction()
        e.principal = '${title}'
        e.roles = set(['Reader', ])

        ex = getMultiAdapter((self.portal, e, DummyEvent(self.folder)),
                             IExecutable)
        self.assertEquals(False, ex())
    def testExecuteInterp(self):
        # Setup scenario
        self.portal.portal_registration.addMember('mrfoo', '12345', ())
        self.portal.invokeFactory('Folder', 'mrfoo', title='mrfoo')
        folder = self.portal['mrfoo']
        e = LocalRoleAction()
        e.principal = '${title}'
        e.roles = set(['Reader', ])

        ex = getMultiAdapter((self.portal, e, DummyEvent(folder)),
                             IExecutable)
        self.assertEquals(True, ex())
        localroles = folder.get_local_roles_for_userid(userid='mrfoo')
        self.failUnless(tuple(e.roles) == localroles)
 def testActionSummary(self):
     e = LocalRoleAction()
     e.principal = '${title}'
     e.roles = set(['Reader', ])
     summary = u"Apply local roles ${roles} to ${principal}"
     self.assertEquals(summary, e.summary)