当前位置: 首页>>代码示例>>Python>>正文


Python Roles.register_permissions方法代码示例

本文整理汇总了Python中models.roles.Roles.register_permissions方法的典型用法代码示例。如果您正苦于以下问题:Python Roles.register_permissions方法的具体用法?Python Roles.register_permissions怎么用?Python Roles.register_permissions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.roles.Roles的用法示例。


在下文中一共展示了Roles.register_permissions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_editor_hooks

# 需要导入模块: from models.roles import Roles [as 别名]
# 或者: from models.roles.Roles import register_permissions [as 别名]
    def test_editor_hooks(self):
        module1 = Module('module1', '', [], [])
        module2 = Module('module2', '', [], [])
        module3 = Module('module3', '', [], [])
        module4 = Module('module4', '', [], [])
        Roles.register_permissions(module1, lambda unused: [
            Permission('permissiona', 'a'), Permission('permissionb', 'b')])

        Roles.register_permissions(module2, lambda unused: [
            Permission('permissionc', 'c'), Permission('permissiond', 'd')])
        Roles.register_permissions(module4, lambda unused: [
            Permission('permissiong', 'g'), Permission('permissiond', 'h')])
        handler = RoleRESTHandler()
        handler.course = self.course

        datastore_permissions = {
            module1.name: ['permission', 'permissiona', 'permissionb'],
            module2.name: ['permissionc', 'permissiond'],
            module3.name: ['permissione', 'permissionf']
        }
        datastore_dict = {
            'name': 'Role Name',
            'users': ['[email protected]', '[email protected]'],
            'permissions': datastore_permissions
        }
        editor_dict = handler.transform_for_editor_hook(datastore_dict)
        self.assertEquals(editor_dict['name'], 'Role Name')
        self.assertEquals(editor_dict['users'], '[email protected], [email protected]')
        modules = editor_dict['modules']
        # Test registered assigned permission
        permissionc = modules[module2.name][0]
        self.assertEquals(permissionc['assigned'], True)
        self.assertEquals(permissionc['name'], 'permissionc')
        self.assertEquals(permissionc['description'], 'c')
        # Test unregistered module with assigned permission
        permissionsf = modules[RoleRESTHandler.INACTIVE_MODULES][1]
        self.assertEquals(permissionsf['assigned'], True)
        self.assertEquals(permissionsf['name'], 'permissionf')
        self.assertEquals(
            permissionsf['description'],
            'This permission was set by the module "module3" which is '
            'currently not registered.'
        )
        # Test registered module with assigned unregistered permission
        permission = modules[module1.name][2]
        self.assertEquals(permission['assigned'], True)
        self.assertEquals(permission['name'], 'permission')
        self.assertEquals(
            permission['description'],
            'This permission is currently not registered.'
        )
        # Test registered unassigned permissions
        permissiong = editor_dict['modules'][module4.name][0]
        self.assertEquals(permissiong['assigned'], False)
        self.assertEquals(permissiong['name'], 'permissiong')
        self.assertEquals(permissiong['description'], 'g')
        # Call the hook which gets called when saving
        new_datastore_dict = handler.transform_after_editor_hook(datastore_dict)
        # If original dict matches new dict then both hooks work correctly
        self.assertEquals(datastore_dict, new_datastore_dict)
开发者ID:jomolinare,项目名称:course-builder,代码行数:62,代码来源:modules_dashboard.py


注:本文中的models.roles.Roles.register_permissions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。