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


Python User.query方法代码示例

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


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

示例1: test_logging_profiling_is_disabled

# 需要导入模块: from st2common.persistence.auth import User [as 别名]
# 或者: from st2common.persistence.auth.User import query [as 别名]
 def test_logging_profiling_is_disabled(self, mock_log):
     disable_profiling()
     queryset = User.query(name__in=['test1', 'test2'], order_by=['+aa', '-bb'], limit=1)
     result = log_query_and_profile_data_for_queryset(queryset=queryset)
     self.assertEqual(queryset, result)
     call_args_list = mock_log.debug.call_args_list
     self.assertItemsEqual(call_args_list, [])
开发者ID:StackStorm,项目名称:st2,代码行数:9,代码来源:test_model_utils_profiling.py

示例2: test_logging_profiling_is_enabled

# 需要导入模块: from st2common.persistence.auth import User [as 别名]
# 或者: from st2common.persistence.auth.User import query [as 别名]
    def test_logging_profiling_is_enabled(self, mock_log):
        enable_profiling()
        queryset = User.query(name__in=['test1', 'test2'], order_by=['+aa', '-bb'], limit=1)
        result = log_query_and_profile_data_for_queryset(queryset=queryset)

        call_args_list = mock_log.debug.call_args_list
        call_args = call_args_list[0][0]
        call_kwargs = call_args_list[0][1]

        expected_result = ("db.user_d_b.find({'name': {'$in': ['test1', 'test2']}})"
                           ".sort({aa: 1, bb: -1}).limit(1);")
        self.assertEqual(queryset, result)
        self.assertTrue(expected_result in call_args[0])
        self.assertTrue('mongo_query' in call_kwargs['extra'])
        self.assertTrue('mongo_shell_query' in call_kwargs['extra'])
开发者ID:StackStorm,项目名称:st2,代码行数:17,代码来源:test_model_utils_profiling.py

示例3: test_sync_assignments_user_doesnt_exist_in_db

# 需要导入模块: from st2common.persistence.auth import User [as 别名]
# 或者: from st2common.persistence.auth.User import query [as 别名]
    def test_sync_assignments_user_doesnt_exist_in_db(self):
        # Make sure that the assignments for the users which don't exist in the db are still saved
        syncer = RBACDefinitionsDBSyncer()

        self._insert_mock_roles()

        username = 'doesntexistwhaha_3'

        # Initial state, no roles
        user_db = UserDB(name=username)
        self.assertEqual(len(User.query(name=username)), 0)
        role_dbs = get_roles_for_user(user_db=user_db)
        self.assertItemsEqual(role_dbs, [])

        # Do the sync with two roles defined
        api = UserRoleAssignmentFileFormatAPI(
            username=user_db.name, roles=['role_1', 'role_2'], file_path='assignments/foobar.yaml')

        syncer.sync_users_role_assignments(role_assignment_apis=[api])

        role_dbs = get_roles_for_user(user_db=user_db)
        self.assertEqual(len(role_dbs), 2)
        self.assertEqual(role_dbs[0], self.roles['role_1'])
        self.assertEqual(role_dbs[1], self.roles['role_2'])
开发者ID:lyandut,项目名称:st2,代码行数:26,代码来源:test_rbac_syncer.py

示例4: test_sync_assignments_are_removed_user_doesnt_exist_in_db

# 需要导入模块: from st2common.persistence.auth import User [as 别名]
# 或者: from st2common.persistence.auth.User import query [as 别名]
    def test_sync_assignments_are_removed_user_doesnt_exist_in_db(self):
        # Make sure that the assignments for the users which don't exist in the db are correctly
        # removed
        syncer = RBACDefinitionsDBSyncer()

        self._insert_mock_roles()

        username = 'doesntexistwhaha_1'

        # Initial state, no roles
        user_db = UserDB(name=username)
        self.assertEqual(len(User.query(name=username)), 0)
        role_dbs = get_roles_for_user(user_db=user_db)
        self.assertItemsEqual(role_dbs, [])

        # Do the sync with two roles defined
        api = UserRoleAssignmentFileFormatAPI(
            username=user_db.name, roles=['role_1', 'role_2'],
            file_path='assignments/%s.yaml' % user_db.name)

        syncer.sync_users_role_assignments(role_assignment_apis=[api])

        role_dbs = get_roles_for_user(user_db=user_db)
        self.assertEqual(len(role_dbs), 2)
        self.assertEqual(role_dbs[0], self.roles['role_1'])
        self.assertEqual(role_dbs[1], self.roles['role_2'])

        # Sync with no roles on disk - existing roles should be removed
        syncer.sync_users_role_assignments(role_assignment_apis=[])

        role_dbs = get_roles_for_user(user_db=user_db)

        self.assertEqual(len(role_dbs), 0)

        username = 'doesntexistwhaha_2'

        # Initial state, no roles
        user_db = UserDB(name=username)
        self.assertEqual(len(User.query(name=username)), 0)
        role_dbs = get_roles_for_user(user_db=user_db)
        self.assertItemsEqual(role_dbs, [])

        # Do the sync with three roles defined
        api = UserRoleAssignmentFileFormatAPI(
            username=user_db.name, roles=['role_1', 'role_2', 'role_3'],
            file_path='assignments/%s.yaml' % user_db.name)

        syncer.sync_users_role_assignments(role_assignment_apis=[api])

        role_dbs = get_roles_for_user(user_db=user_db)
        self.assertEqual(len(role_dbs), 3)
        self.assertEqual(role_dbs[0], self.roles['role_1'])
        self.assertEqual(role_dbs[1], self.roles['role_2'])
        self.assertEqual(role_dbs[2], self.roles['role_3'])
        role_assignment_dbs = get_role_assignments_for_user(user_db=user_db)
        self.assertEqual(len(role_assignment_dbs), 3)
        self.assertEqual(role_assignment_dbs[0].source, 'assignments/%s.yaml' % user_db.name)

        # Sync with one role on disk - two roles should be removed
        api = UserRoleAssignmentFileFormatAPI(
            username=user_db.name, roles=['role_3'],
            file_path='assignments/%s.yaml' % user_db.name)

        syncer.sync_users_role_assignments(role_assignment_apis=[api])

        role_dbs = get_roles_for_user(user_db=user_db)
        self.assertEqual(len(role_dbs), 1)
        self.assertEqual(role_dbs[0], self.roles['role_3'])
开发者ID:lyandut,项目名称:st2,代码行数:70,代码来源:test_rbac_syncer.py


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