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


Python PermissionGrant.get_by_id方法代码示例

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


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

示例1: test_sync_roles_single_role_definition_three_grants

# 需要导入模块: from st2common.persistence.rbac import PermissionGrant [as 别名]
# 或者: from st2common.persistence.rbac.PermissionGrant import get_by_id [as 别名]
    def test_sync_roles_single_role_definition_three_grants(self):
        syncer = RBACDefinitionsDBSyncer()

        # One role with two grants
        permission_grants = [
            {
                'resource_uid': 'pack:mapack1',
                'permission_types': ['pack_all']
            },
            {
                'resource_uid': 'pack:mapack2',
                'permission_types': ['rule_view', 'action_view']
            },
            {
                'permission_types': ['sensor_list', 'action_list']
            }
        ]
        api = RoleDefinitionFileFormatAPI(name='test_role_2', description='test description 2',
                                          permission_grants=permission_grants)
        created_role_dbs, deleted_role_dbs = syncer.sync_roles(role_definition_apis=[api])
        self.assertEqual(len(created_role_dbs), 1)
        self.assertItemsEqual(deleted_role_dbs, [])
        self.assertEqual(created_role_dbs[0].name, 'test_role_2')
        self.assertEqual(created_role_dbs[0].description, 'test description 2')
        self.assertEqual(len(created_role_dbs[0].permission_grants), 3)

        # Assert role and grants have been created in the DB
        self.assertRoleDBObjectExists(role_db=created_role_dbs[0])

        for permission_grant_id in created_role_dbs[0].permission_grants:
            self.assertGrantDBObjectExists(permission_grant_id)

        grant_db = PermissionGrant.get_by_id(str(created_role_dbs[0].permission_grants[0]))
        self.assertEqual(grant_db.resource_uid, permission_grants[0]['resource_uid'])
        self.assertEqual(grant_db.resource_type, 'pack')
        self.assertEqual(grant_db.permission_types, permission_grants[0]['permission_types'])

        grant_db = PermissionGrant.get_by_id(str(created_role_dbs[0].permission_grants[2]))
        self.assertEqual(grant_db.resource_uid, None)
        self.assertEqual(grant_db.resource_type, None)
        self.assertEqual(grant_db.permission_types, permission_grants[2]['permission_types'])
开发者ID:lyandut,项目名称:st2,代码行数:43,代码来源:test_rbac_syncer.py

示例2: assertGrantDBObjectExists

# 需要导入模块: from st2common.persistence.rbac import PermissionGrant [as 别名]
# 或者: from st2common.persistence.rbac.PermissionGrant import get_by_id [as 别名]
 def assertGrantDBObjectExists(self, permission_grant_id):
     result = PermissionGrant.get_by_id(str(permission_grant_id))
     self.assertTrue(result)
     self.assertEqual(permission_grant_id, str(result.id))
开发者ID:agilee,项目名称:st2,代码行数:6,代码来源:test_rbac_syncer.py


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