def test_update_inherit(self):
     #context = None
     request = {}
     roles_view = RolesView(self.folder, request)
     status = None
     reindex = False
     self.assertEqual(False, roles_view.update_inherit(status, reindex))
 def test_update_role_settings(self):
     #context = None
     request = {}
     roles_view = RolesView(self.folder, request)
     new_settings = []
     reindex = False
     self.assertEqual(
         False, roles_view.update_role_settings(new_settings, reindex))
 def test_roles(self):
     #context = None
     request = {}
     roles_view = RolesView(self.folder, request)
     expected = [{'id': u'GroupAdmin', 'title': u'title_can_manage'},
                 {'id': u'GroupContributor', 'title': u'title_can_edit'},
                 {'id': u'GroupEditor', 'title': u'title_can_edit'},
                 {'id': u'GroupReader', 'title': u'title_can_view'}]
     self.assertEqual(expected, roles_view.roles())
    def __iter__(self):
        for item in self.previous:
            pathkey = self.pathkey(*item.keys())[0]
            roleskey = self.roleskey(*item.keys())[0]

            if not pathkey or not roleskey or \
               roleskey not in item:    # not enough info
                yield item; continue

            obj = self.context.unrestrictedTraverse(item[pathkey].lstrip('/'), None)
            if obj is None:             # path doesn't exist
                yield item; continue

            if IRoleManager.providedBy(obj):
                new_settings = []
                groups = getToolByName(self.context, 'portal_groups')
                newrolemap = self.options.get('local-roles-mapping', {})
                if newrolemap:
                    newrolemap = newrolemap.split('\n')
                    newrolemap = dict([(t.split(':')[0].strip(),
                                     t.split(':')[1].strip())
                                 for t in newrolemap if ':' in t])
                for principal, roles in item[roleskey].items():
                    if roles:
                        if newrolemap:
                            roles = [newrolemap.get(r, r) for r in roles]
                        obj.manage_addLocalRoles(principal, roles)
                        obj.reindexObjectSecurity()
                        if HAS_GS:
                            new_settings.append({
                                'id': principal,
                                'type': groups.getGroupById(principal) and 'group' or 'user',
                                'roles': [r for r in roles if queryUtility(IRolesPageRole, r)],
                            })
                if HAS_GS and ILocalGroupSpacePASRoles.providedBy(obj):
                    roles_view = RolesView(obj, TestRequest())
                    roles_view.update_role_settings(new_settings)

            yield item
 def test_existing_role_settings(self):
     #context = None
     request = {}
     roles_view = RolesView(self.folder, request)
     self.assertEqual([], roles_view.existing_role_settings())