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


Python fixturesloader.get_fixtures_base_path函数代码示例

本文整理汇总了Python中st2tests.fixturesloader.get_fixtures_base_path函数的典型用法代码示例。如果您正苦于以下问题:Python get_fixtures_base_path函数的具体用法?Python get_fixtures_base_path怎么用?Python get_fixtures_base_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_get_pack_resource_file_abs_path

    def test_get_pack_resource_file_abs_path(self):
        # Mock the packs path to point to the fixtures directory
        cfg.CONF.content.packs_base_paths = get_fixtures_base_path()

        # Invalid resource type
        expected_msg = 'Invalid resource type: fooo'
        self.assertRaisesRegexp(ValueError, expected_msg, get_pack_resource_file_abs_path,
                                pack_name='dummy_pack_1',
                                resource_type='fooo',
                                file_path='test.py')

        # Invalid paths (directory traversal and absolute paths)
        file_paths = ['/tmp/foo.py', '../foo.py', '/etc/passwd', '../../foo.py']
        for file_path in file_paths:
            expected_msg = 'Invalid file path: .*%s' % (file_path)
            self.assertRaisesRegexp(ValueError, expected_msg, get_pack_resource_file_abs_path,
                                    pack_name='dummy_pack_1',
                                    resource_type='action',
                                    file_path=file_path)

        # Valid paths
        file_paths = ['foo.py', 'a/foo.py', 'a/b/foo.py']
        for file_path in file_paths:
            expected = os.path.join(get_fixtures_base_path(), 'dummy_pack_1/actions', file_path)
            result = get_pack_resource_file_abs_path(pack_name='dummy_pack_1',
                                                     resource_type='action',
                                                     file_path=file_path)
            self.assertEqual(result, expected)
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:28,代码来源:test_content_utils.py

示例2: test_load_role_definitions_duplicate_role_definition

    def test_load_role_definitions_duplicate_role_definition(self):
        loader = RBACDefinitionsLoader()

        # Try to load all the roles from disk where two definitions refer to the same role
        file_path1 = os.path.join(get_fixtures_base_path(), 'rbac_invalid/roles/role_three1.yaml')
        file_path2 = os.path.join(get_fixtures_base_path(), 'rbac_invalid/roles/role_three2.yaml')
        file_paths = [file_path1, file_path2]

        loader._get_role_definitions_file_paths = mock.Mock()
        loader._get_role_definitions_file_paths.return_value = file_paths

        expected_msg = 'Duplicate definition file found for role "role_three_name_conflict"'
        self.assertRaisesRegexp(ValueError, expected_msg, loader.load_role_definitions)
开发者ID:lyandut,项目名称:st2,代码行数:13,代码来源:test_rbac_loader.py

示例3: test_load_role_definition_validation_error

    def test_load_role_definition_validation_error(self):
        loader = RBACDefinitionsLoader()

        # Invalid permission which doesn't apply to the resource in question
        file_path = os.path.join(get_fixtures_base_path(), "rbac_invalid/roles/role_one.yaml")
        expected_msg = 'Invalid permission type "rule_all" for resource type "action"'
        self.assertRaisesRegexp(ValueError, expected_msg, loader.load_role_definition_from_file, file_path=file_path)

        # Invalid permission type which doesn't exist
        file_path = os.path.join(get_fixtures_base_path(), "rbac_invalid/roles/role_two.yaml")
        expected_msg = ".*Failed validating 'enum'.*"
        self.assertRaisesRegexp(
            jsonschema.ValidationError, expected_msg, loader.load_role_definition_from_file, file_path=file_path
        )
开发者ID:alexmakarski,项目名称:st2,代码行数:14,代码来源:test_rbac_loader.py

示例4: test_register_from_pack_action_metadata_fails_validation

    def test_register_from_pack_action_metadata_fails_validation(self):
        # No fail on failure flag, should succeed
        pack_dir = os.path.join(get_fixtures_base_path(), "dummy_pack_4")
        cmd = BASE_CMD_ARGS + ["--register-pack=%s" % (pack_dir)]
        exit_code, _, stderr = run_command(cmd=cmd)
        self.assertTrue("Registered 0 actions." in stderr)
        self.assertEqual(exit_code, 0)

        # Fail on failure, should fail
        pack_dir = os.path.join(get_fixtures_base_path(), "dummy_pack_4")
        cmd = BASE_CMD_ARGS + ["--register-pack=%s" % (pack_dir), "--register-fail-on-failure"]
        exit_code, _, stderr = run_command(cmd=cmd)
        self.assertTrue("object has no attribute 'get'" in stderr)
        self.assertEqual(exit_code, 1)
开发者ID:azamsheriff,项目名称:st2,代码行数:14,代码来源:test_register_content_script.py

示例5: test_load_user_role_assignments_duplicate_user_definition

    def test_load_user_role_assignments_duplicate_user_definition(self):
        loader = RBACDefinitionsLoader()

        # Try to load all the user role assignments from disk where two definitions refer to the
        # same user
        file_path1 = os.path.join(get_fixtures_base_path(), "rbac_invalid/assignments/user_foo1.yaml")
        file_path2 = os.path.join(get_fixtures_base_path(), "rbac_invalid/assignments/user_foo2.yaml")
        file_paths = [file_path1, file_path2]

        loader._get_role_assiginments_file_paths = mock.Mock()
        loader._get_role_assiginments_file_paths.return_value = file_paths

        expected_msg = 'Duplicate definition file found for user "userfoo"'
        self.assertRaisesRegexp(ValueError, expected_msg, loader.load_user_role_assignments)
开发者ID:alexmakarski,项目名称:st2,代码行数:14,代码来源:test_rbac_loader.py

示例6: test_register_from_pack_action_metadata_fails_validation

    def test_register_from_pack_action_metadata_fails_validation(self):
        # No fail on failure flag, should succeed
        pack_dir = os.path.join(get_fixtures_base_path(), 'dummy_pack_4')
        cmd = BASE_REGISTER_ACTIONS_CMD_ARGS + ['--register-pack=%s' % (pack_dir)]
        exit_code, _, stderr = run_command(cmd=cmd)
        self.assertTrue('Registered 0 actions.' in stderr)
        self.assertEqual(exit_code, 0)

        # Fail on failure, should fail
        pack_dir = os.path.join(get_fixtures_base_path(), 'dummy_pack_4')
        cmd = BASE_REGISTER_ACTIONS_CMD_ARGS + ['--register-pack=%s' % (pack_dir),
                                                '--register-fail-on-failure']
        exit_code, _, stderr = run_command(cmd=cmd)
        self.assertTrue('object has no attribute \'get\'' in stderr)
        self.assertEqual(exit_code, 1)
开发者ID:MohammadHabbab,项目名称:st2,代码行数:15,代码来源:test_register_content_script.py

示例7: test_load_role_definition_with_all_global_permission_types

    def test_load_role_definition_with_all_global_permission_types(self):
        loader = RBACDefinitionsLoader()

        file_path = os.path.join(get_fixtures_base_path(), 'rbac/roles/role_seven.yaml')
        role_definition_api = loader.load_role_definition_from_file(file_path=file_path)

        self.assertEqual(role_definition_api.name, 'role_seven')
开发者ID:lyandut,项目名称:st2,代码行数:7,代码来源:test_rbac_loader.py

示例8: test_register_from_pack_success

    def test_register_from_pack_success(self):
        pack_dir = os.path.join(get_fixtures_base_path(), "dummy_pack_1")

        cmd = BASE_CMD_ARGS + ["--register-pack=%s" % (pack_dir)]
        exit_code, _, stderr = run_command(cmd=cmd)
        self.assertTrue("Registered 1 actions." in stderr)
        self.assertEqual(exit_code, 0)
开发者ID:azamsheriff,项目名称:st2,代码行数:7,代码来源:test_register_content_script.py

示例9: test_register_from_pack_success

    def test_register_from_pack_success(self):
        pack_dir = os.path.join(get_fixtures_base_path(), 'dummy_pack_1')

        cmd = BASE_REGISTER_ACTIONS_CMD_ARGS + ['--register-pack=%s' % (pack_dir)]
        exit_code, _, stderr = run_command(cmd=cmd)
        self.assertTrue('Registered 1 actions.' in stderr)
        self.assertEqual(exit_code, 0)
开发者ID:MohammadHabbab,项目名称:st2,代码行数:7,代码来源:test_register_content_script.py

示例10: test_register_triggers_from_pack

    def test_register_triggers_from_pack(self):
        base_path = get_fixtures_base_path()
        pack_dir = os.path.join(base_path, 'dummy_pack_1')

        trigger_type_dbs = TriggerType.get_all()
        self.assertEqual(len(trigger_type_dbs), 0)

        count = triggers_registrar.register_triggers(pack_dir=pack_dir)
        self.assertEqual(count, 2)

        # Verify TriggerTypeDB and corresponding TriggerDB objects have been created
        trigger_type_dbs = TriggerType.get_all()
        trigger_dbs = Trigger.get_all()
        self.assertEqual(len(trigger_type_dbs), 2)
        self.assertEqual(len(trigger_dbs), 2)

        self.assertEqual(trigger_type_dbs[0].name, 'event_handler')
        self.assertEqual(trigger_type_dbs[0].pack, 'dummy_pack_1')
        self.assertEqual(trigger_dbs[0].name, 'event_handler')
        self.assertEqual(trigger_dbs[0].pack, 'dummy_pack_1')
        self.assertEqual(trigger_dbs[0].type, 'dummy_pack_1.event_handler')

        self.assertEqual(trigger_type_dbs[1].name, 'head_sha_monitor')
        self.assertEqual(trigger_type_dbs[1].pack, 'dummy_pack_1')
        self.assertEqual(trigger_type_dbs[1].payload_schema['type'], 'object')
开发者ID:ddevalco,项目名称:st2,代码行数:25,代码来源:test_triggers_registrar.py

示例11: _override_common_opts

def _override_common_opts():
    packs_base_path = get_fixtures_base_path()
    CONF.set_override(name='system_packs_base_path', override=packs_base_path, group='content')
    CONF.set_override(name='api_url', override='http://localhost', group='auth')
    CONF.set_override(name='admin_users', override=['admin_user'], group='system')
    CONF.set_override(name='mask_secrets', override=True, group='log')
    CONF.set_override(name='url', override='zake://', group='coordination')
    CONF.set_override(name='lock_timeout', override=1, group='coordination')
开发者ID:ruslantum,项目名称:st2,代码行数:8,代码来源:config.py

示例12: test_load_group_to_role_mappings_missing_mandatory_attribute

    def test_load_group_to_role_mappings_missing_mandatory_attribute(self):
        loader = RBACDefinitionsLoader()

        file_path = os.path.join(get_fixtures_base_path(),
                                 'rbac_invalid/mappings/mapping_one_missing_roles.yaml')

        expected_msg = '\'roles\' is a required property'
        self.assertRaisesRegexp(jsonschema.ValidationError, expected_msg,
                                loader.load_group_to_role_map_assignment_from_file,
                                file_path=file_path)

        file_path = os.path.join(get_fixtures_base_path(),
                                 'rbac_invalid/mappings/mapping_two_missing_group.yaml')

        expected_msg = '\'group\' is a required property'
        self.assertRaisesRegexp(jsonschema.ValidationError, expected_msg,
                                loader.load_group_to_role_map_assignment_from_file,
                                file_path=file_path)
开发者ID:lyandut,项目名称:st2,代码行数:18,代码来源:test_rbac_loader.py

示例13: test_script_with_paramters_parameter_serialization

    def test_script_with_paramters_parameter_serialization(self):
        models = self.fixtures_loader.load_models(
            fixtures_pack="generic", fixtures_dict={"actions": ["local_script_with_params.yaml"]}
        )
        action_db = models["actions"]["local_script_with_params.yaml"]
        entry_point = os.path.join(get_fixtures_base_path(), "generic/actions/local_script_with_params.sh")

        action_parameters = {
            "param_string": "test string",
            "param_integer": 1,
            "param_float": 2.55,
            "param_boolean": True,
            "param_list": ["a", "b", "c"],
            "param_object": {"foo": "bar"},
        }

        runner = self._get_runner(action_db=action_db, entry_point=entry_point)
        runner.pre_run()
        status, result, _ = runner.run(action_parameters=action_parameters)
        runner.post_run(status, result)

        self.assertEqual(status, action_constants.LIVEACTION_STATUS_SUCCEEDED)
        self.assertTrue("PARAM_STRING=test string" in result["stdout"])
        self.assertTrue("PARAM_INTEGER=1" in result["stdout"])
        self.assertTrue("PARAM_FLOAT=2.55" in result["stdout"])
        self.assertTrue("PARAM_BOOLEAN=1" in result["stdout"])
        self.assertTrue("PARAM_LIST=a,b,c" in result["stdout"])
        self.assertTrue('PARAM_OBJECT={"foo": "bar"}' in result["stdout"])

        action_parameters = {
            "param_string": "test string",
            "param_integer": 1,
            "param_float": 2.55,
            "param_boolean": False,
            "param_list": ["a", "b", "c"],
            "param_object": {"foo": "bar"},
        }

        runner = self._get_runner(action_db=action_db, entry_point=entry_point)
        runner.pre_run()
        status, result, _ = runner.run(action_parameters=action_parameters)
        runner.post_run(status, result)

        self.assertEqual(status, action_constants.LIVEACTION_STATUS_SUCCEEDED)
        self.assertTrue("PARAM_BOOLEAN=0" in result["stdout"])

        action_parameters = {"param_string": "", "param_integer": None, "param_float": None}

        runner = self._get_runner(action_db=action_db, entry_point=entry_point)
        runner.pre_run()
        status, result, _ = runner.run(action_parameters=action_parameters)
        runner.post_run(status, result)

        self.assertEqual(status, action_constants.LIVEACTION_STATUS_SUCCEEDED)
        self.assertTrue("PARAM_STRING=\n" in result["stdout"])
        self.assertTrue("PARAM_INTEGER=\n" in result["stdout"])
        self.assertTrue("PARAM_FLOAT=\n" in result["stdout"])
开发者ID:rlugojr,项目名称:st2,代码行数:57,代码来源:test_localrunner.py

示例14: test_register_policy_invalid_policy_type_references

    def test_register_policy_invalid_policy_type_references(self):
        # Policy references an invalid (inexistent) policy type
        registrar = PolicyRegistrar()
        policy_path = os.path.join(get_fixtures_base_path(), "dummy_pack_1/policies/policy_2.yaml")

        expected_msg = 'Referenced policy_type "action.mock_policy_error" doesnt exist'
        self.assertRaisesRegexp(
            ValueError, expected_msg, registrar._register_policy, pack="dummy_pack_1", policy=policy_path
        )
开发者ID:azamsheriff,项目名称:st2,代码行数:9,代码来源:test_policies.py

示例15: test_load_user_role_assignments_success

    def test_load_user_role_assignments_success(self):
        loader = RBACDefinitionsLoader()

        file_path = os.path.join(get_fixtures_base_path(), "rbac/assignments/user3.yaml")
        user_role_assignment_api = loader.load_user_role_assignments_from_file(file_path=file_path)

        self.assertEqual(user_role_assignment_api.username, "user3")
        self.assertEqual(user_role_assignment_api.description, "Observer assignments")
        self.assertEqual(user_role_assignment_api.roles, ["observer"])
开发者ID:alexmakarski,项目名称:st2,代码行数:9,代码来源:test_rbac_loader.py


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