How to use the httprunner.parser.eval_lazy_data function in httprunner

To help you get started, we’ve selected a few httprunner examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github httprunner / httprunner / tests / test_parser.py View on Github external
def test_parse_environ(self):
        os.environ["PROJECT_KEY"] = "ABCDEFGH"
        content = {
            "variables": [
                {"PROJECT_KEY": "${ENV(PROJECT_KEY)}"}
            ]
        }
        result = parser.eval_lazy_data(content)

        content = {
            "variables": [
                {"PROJECT_KEY": "${ENV(PROJECT_KEY, abc)}"}
            ]
        }
        with self.assertRaises(exceptions.ParamsError):
            parser.eval_lazy_data(content)

        content = {
            "variables": [
                {"PROJECT_KEY": "${ENV(abc=123)}"}
            ]
        }
        with self.assertRaises(exceptions.ParamsError):
            parser.eval_lazy_data(content)
github httprunner / httprunner / tests / test_parser.py View on Github external
"abc"
        )
        self.assertEqual(
            parser.eval_lazy_data("var_1", variables_mapping=variables_mapping),
            "var_1"
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_1#XYZ", variables_mapping=variables_mapping),
            "abc#XYZ"
        )
        self.assertEqual(
            parser.eval_lazy_data("/$var_1/$var_2/var3", variables_mapping=variables_mapping),
            "/abc/def/var3"
        )
        self.assertEqual(
            parser.eval_lazy_data("/$var_1/$var_2/$var_1", variables_mapping=variables_mapping),
            "/abc/def/abc"
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_3", variables_mapping=variables_mapping),
            123
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_4", variables_mapping=variables_mapping),
            {"a": 1}
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_5", variables_mapping=variables_mapping),
            True
        )
        self.assertEqual(
            parser.eval_lazy_data("abc$var_5", variables_mapping=variables_mapping),
github httprunner / httprunner / tests / test_parser.py View on Github external
"/abc/def/var3"
        )
        self.assertEqual(
            parser.eval_lazy_data("/$var_1/$var_2/$var_1", variables_mapping=variables_mapping),
            "/abc/def/abc"
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_3", variables_mapping=variables_mapping),
            123
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_4", variables_mapping=variables_mapping),
            {"a": 1}
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_5", variables_mapping=variables_mapping),
            True
        )
        self.assertEqual(
            parser.eval_lazy_data("abc$var_5", variables_mapping=variables_mapping),
            "abcTrue"
        )
        self.assertEqual(
            parser.eval_lazy_data("abc$var_4", variables_mapping=variables_mapping),
            "abc{'a': 1}"
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_6", variables_mapping=variables_mapping),
            None
        )

        with self.assertRaises(exceptions.VariableNotFound):
github httprunner / httprunner / tests / test_parser.py View on Github external
"/abc/def/abc"
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_3", variables_mapping=variables_mapping),
            123
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_4", variables_mapping=variables_mapping),
            {"a": 1}
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_5", variables_mapping=variables_mapping),
            True
        )
        self.assertEqual(
            parser.eval_lazy_data("abc$var_5", variables_mapping=variables_mapping),
            "abcTrue"
        )
        self.assertEqual(
            parser.eval_lazy_data("abc$var_4", variables_mapping=variables_mapping),
            "abc{'a': 1}"
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_6", variables_mapping=variables_mapping),
            None
        )

        with self.assertRaises(exceptions.VariableNotFound):
            parser.eval_lazy_data("/api/$SECRET_KEY", variables_mapping=variables_mapping)

        self.assertEqual(
            parser.eval_lazy_data(["$var_1", "$var_2"], variables_mapping=variables_mapping),
github httprunner / httprunner / tests / test_parser.py View on Github external
def test_parse_data_functions(self):
        functions_mapping = {
            "gen_random_string": gen_random_string
        }
        result = parser.eval_lazy_data("${gen_random_string(5)}", functions_mapping=functions_mapping)
        self.assertEqual(len(result), 5)

        add_two_nums = lambda a, b=1: a + b
        functions_mapping["add_two_nums"] = add_two_nums
        self.assertEqual(
            parser.eval_lazy_data("${add_two_nums(1)}", functions_mapping=functions_mapping),
            2
        )
        self.assertEqual(
            parser.eval_lazy_data("${add_two_nums(1, 2)}", functions_mapping=functions_mapping),
            3
        )
        self.assertEqual(
            parser.eval_lazy_data("/api/${add_two_nums(1, 2)}", functions_mapping=functions_mapping),
            "/api/3"
        )
github httprunner / httprunner / tests / test_parser.py View on Github external
"var_1"
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_1#XYZ", variables_mapping=variables_mapping),
            "abc#XYZ"
        )
        self.assertEqual(
            parser.eval_lazy_data("/$var_1/$var_2/var3", variables_mapping=variables_mapping),
            "/abc/def/var3"
        )
        self.assertEqual(
            parser.eval_lazy_data("/$var_1/$var_2/$var_1", variables_mapping=variables_mapping),
            "/abc/def/abc"
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_3", variables_mapping=variables_mapping),
            123
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_4", variables_mapping=variables_mapping),
            {"a": 1}
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_5", variables_mapping=variables_mapping),
            True
        )
        self.assertEqual(
            parser.eval_lazy_data("abc$var_5", variables_mapping=variables_mapping),
            "abcTrue"
        )
        self.assertEqual(
            parser.eval_lazy_data("abc$var_4", variables_mapping=variables_mapping),
github httprunner / httprunner / tests / test_parser.py View on Github external
"abc#XYZ"
        )
        self.assertEqual(
            parser.eval_lazy_data("/$var_1/$var_2/var3", variables_mapping=variables_mapping),
            "/abc/def/var3"
        )
        self.assertEqual(
            parser.eval_lazy_data("/$var_1/$var_2/$var_1", variables_mapping=variables_mapping),
            "/abc/def/abc"
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_3", variables_mapping=variables_mapping),
            123
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_4", variables_mapping=variables_mapping),
            {"a": 1}
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_5", variables_mapping=variables_mapping),
            True
        )
        self.assertEqual(
            parser.eval_lazy_data("abc$var_5", variables_mapping=variables_mapping),
            "abcTrue"
        )
        self.assertEqual(
            parser.eval_lazy_data("abc$var_4", variables_mapping=variables_mapping),
            "abc{'a': 1}"
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_6", variables_mapping=variables_mapping),
github httprunner / httprunner / tests / test_parser.py View on Github external
def test_eval_lazy_data(self):
        variables_mapping = {
            "var_1": "abc",
            "var_2": "def",
            "var_3": 123,
            "var_4": {"a": 1},
            "var_5": True,
            "var_6": None
        }
        self.assertEqual(
            parser.eval_lazy_data("$var_1", variables_mapping=variables_mapping),
            "abc"
        )
        self.assertEqual(
            parser.eval_lazy_data("var_1", variables_mapping=variables_mapping),
            "var_1"
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_1#XYZ", variables_mapping=variables_mapping),
            "abc#XYZ"
        )
        self.assertEqual(
            parser.eval_lazy_data("/$var_1/$var_2/var3", variables_mapping=variables_mapping),
            "/abc/def/var3"
        )
        self.assertEqual(
            parser.eval_lazy_data("/$var_1/$var_2/$var_1", variables_mapping=variables_mapping),
            "/abc/def/abc"
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_3", variables_mapping=variables_mapping),
github httprunner / httprunner / tests / test_parser.py View on Github external
"var_6": None
        }
        self.assertEqual(
            parser.eval_lazy_data("$var_1", variables_mapping=variables_mapping),
            "abc"
        )
        self.assertEqual(
            parser.eval_lazy_data("var_1", variables_mapping=variables_mapping),
            "var_1"
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_1#XYZ", variables_mapping=variables_mapping),
            "abc#XYZ"
        )
        self.assertEqual(
            parser.eval_lazy_data("/$var_1/$var_2/var3", variables_mapping=variables_mapping),
            "/abc/def/var3"
        )
        self.assertEqual(
            parser.eval_lazy_data("/$var_1/$var_2/$var_1", variables_mapping=variables_mapping),
            "/abc/def/abc"
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_3", variables_mapping=variables_mapping),
            123
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_4", variables_mapping=variables_mapping),
            {"a": 1}
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_5", variables_mapping=variables_mapping),
github httprunner / httprunner / tests / test_parser.py View on Github external
"abcTrue"
        )
        self.assertEqual(
            parser.eval_lazy_data("abc$var_4", variables_mapping=variables_mapping),
            "abc{'a': 1}"
        )
        self.assertEqual(
            parser.eval_lazy_data("$var_6", variables_mapping=variables_mapping),
            None
        )

        with self.assertRaises(exceptions.VariableNotFound):
            parser.eval_lazy_data("/api/$SECRET_KEY", variables_mapping=variables_mapping)

        self.assertEqual(
            parser.eval_lazy_data(["$var_1", "$var_2"], variables_mapping=variables_mapping),
            ["abc", "def"]
        )
        self.assertEqual(
            parser.eval_lazy_data({"$var_1": "$var_2"}, variables_mapping=variables_mapping),
            {"abc": "def"}
        )