本文整理汇总了Python中st2common.persistence.rbac.Role.get_all方法的典型用法代码示例。如果您正苦于以下问题:Python Role.get_all方法的具体用法?Python Role.get_all怎么用?Python Role.get_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.persistence.rbac.Role
的用法示例。
在下文中一共展示了Role.get_all方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sync_roles_locally_removed_roles_are_removed_from_db
# 需要导入模块: from st2common.persistence.rbac import Role [as 别名]
# 或者: from st2common.persistence.rbac.Role import get_all [as 别名]
def test_sync_roles_locally_removed_roles_are_removed_from_db(self):
syncer = RBACDefinitionsDBSyncer()
# Initial state, DB is empty, we sync with two roles defined on disk
self.assertEqual(len(Role.get_all()), 0)
api1 = RoleDefinitionFileFormatAPI(name='test_role_1', description='test description 1',
permission_grants=[])
api2 = RoleDefinitionFileFormatAPI(name='test_role_2', description='test description 2',
permission_grants=[])
created_role_dbs, deleted_role_dbs = syncer.sync_roles(role_definition_apis=[api1, api2])
self.assertEqual(len(created_role_dbs), 2)
self.assertItemsEqual(deleted_role_dbs, [])
# Assert role and grants have been created in the DB
self.assertEqual(len(Role.get_all()), 2)
self.assertRoleDBObjectExists(role_db=created_role_dbs[0])
self.assertRoleDBObjectExists(role_db=created_role_dbs[1])
# We sync again, this time with one role (role 1) removed locally
created_role_dbs, deleted_role_dbs = syncer.sync_roles(role_definition_apis=[api2])
self.assertEqual(len(created_role_dbs), 1)
self.assertEqual(len(deleted_role_dbs), 2)
# Assert role and grants have been created in the DB
self.assertEqual(len(Role.get_all()), 1)
self.assertRoleDBObjectExists(role_db=created_role_dbs[0])
self.assertEqual(Role.get_all()[0].name, 'test_role_2')
示例2: get_all_roles
# 需要导入模块: from st2common.persistence.rbac import Role [as 别名]
# 或者: from st2common.persistence.rbac.Role import get_all [as 别名]
def get_all_roles(exclude_system=False):
"""
Retrieve all the available roles.
:param exclude_system: True to exclude system roles.
:type exclude_system: ``bool``
:rtype: ``list`` of :class:`RoleDB`
"""
if exclude_system:
result = Role.query(system=False)
else:
result = Role.get_all()
return result