예제 #1
0
    def test_get_module_item_functions(self):
        from httprunner import utils
        module_mapping = loader.load_python_module(utils)

        gen_md5 = loader.get_module_item(module_mapping, "functions", "gen_md5")
        self.assertTrue(validator.is_function(("gen_md5", gen_md5)))
        self.assertEqual(gen_md5("abc"), "900150983cd24fb0d6963f7d28e17f72")

        with self.assertRaises(exceptions.FunctionNotFound):
            loader.get_module_item(module_mapping, "functions", "gen_md4")
예제 #2
0
    def test_get_module_item_variables(self):
        from tests import debugtalk
        module_mapping = loader.load_python_module(debugtalk)

        SECRET_KEY = loader.get_module_item(module_mapping, "variables",
                                            "SECRET_KEY")
        self.assertTrue(validator.is_variable(("SECRET_KEY", SECRET_KEY)))
        self.assertEqual(SECRET_KEY, "DebugTalk")

        with self.assertRaises(exceptions.VariableNotFound):
            loader.get_module_item(module_mapping, "variables", "SECRET_KEY2")
예제 #3
0
    def test_get_module_item_functions(self):
        from httprunner import utils
        module_mapping = loader.load_python_module(utils)

        get_uniform_comparator = loader.get_module_item(
            module_mapping, 'functions', 'get_uniform_comparator')
        assert validator.is_function(("get_uniform_comparator",
                                      get_uniform_comparator))
        assert get_uniform_comparator('==') == 'equals'

        with pytest.raises(exceptions.FunctionNotFound):
            loader.get_module_item(module_mapping, 'functions', 'gen_md4')
예제 #4
0
    def test_get_module_item_functions(self):
        from httprunner import utils
        module_mapping = loader.load_python_module(utils)

        get_uniform_comparator = loader.get_module_item(
            module_mapping, "functions", "get_uniform_comparator")
        self.assertTrue(
            validator.is_function(
                ("get_uniform_comparator", get_uniform_comparator)))
        self.assertEqual(get_uniform_comparator("=="), "equals")

        with self.assertRaises(exceptions.FunctionNotFound):
            loader.get_module_item(module_mapping, "functions", "gen_md4")
예제 #5
0
    def test_get_module_item_variables(self):
        dot_env_path = os.path.join(os.getcwd(), "tests", ".env")
        loader.load_dot_env_file(dot_env_path)

        from tests import debugtalk
        module_mapping = loader.load_python_module(debugtalk)

        SECRET_KEY = loader.get_module_item(module_mapping, "variables",
                                            "SECRET_KEY")
        self.assertTrue(validator.is_variable(("SECRET_KEY", SECRET_KEY)))
        self.assertEqual(SECRET_KEY, "DebugTalk")

        with self.assertRaises(exceptions.VariableNotFound):
            loader.get_module_item(module_mapping, "variables", "SECRET_KEY2")
예제 #6
0
파일: context.py 프로젝트: zdmd/HttpRunner
    def _get_bind_item(self, item_type, item_name):
        """ get specified function or variable.

        Args:
            item_type(str): functions or variables
            item_name(str): function name or variable name

        Returns:
            object: specified function or variable object.
        """
        if item_type == "functions":
            if item_name in self.functions:
                return self.functions[item_name]

            try:
                # check if builtin functions
                item_func = eval(item_name)
                if callable(item_func):
                    # is builtin function
                    return item_func
            except (NameError, TypeError):
                # is not builtin function, continue to search
                pass
        else:
            # item_type == "variables":
            if item_name in self.variables:
                return self.variables[item_name]

        debugtalk_module = loader.load_debugtalk_module(self.file_path)
        return loader.get_module_item(debugtalk_module, item_type, item_name)
예제 #7
0
    def test_get_module_item_variables(self):
        from tests import confcustom
        module_mapping = loader.load_python_module(confcustom)

        SECRET_KEY = loader.get_module_item(module_mapping, 'variables',
                                            'SECRET_KEY')
        assert validator.is_variable(('SECRET_KEY', SECRET_KEY))
        assert SECRET_KEY == 'MyHttpRunner'