mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
fix #1209: only convert jmespath path for some fields in white list
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## 3.1.9 (2022-04-17)
|
## 3.1.9 (2022-04-17)
|
||||||
|
|
||||||
|
- fix #1209: only convert jmespath path for some fields in white list
|
||||||
- fix #1233: parse upload info with session variables
|
- fix #1233: parse upload info with session variables
|
||||||
- fix #1246: catch exceptions when getting socket address failed
|
- fix #1246: catch exceptions when getting socket address failed
|
||||||
- fix #1247: catch exceptions caused by GA report failure
|
- fix #1247: catch exceptions caused by GA report failure
|
||||||
|
|||||||
@@ -58,11 +58,9 @@ def _convert_jmespath(raw: Text) -> Text:
|
|||||||
|
|
||||||
raw_list = []
|
raw_list = []
|
||||||
for item in raw.split("."):
|
for item in raw.split("."):
|
||||||
if "-" in item and "[-" not in item:
|
if item.lower().startswith("content-") or item.lower() in ["user-agent"]:
|
||||||
# add quotes for field with separator
|
# add quotes for some field in white list
|
||||||
# e.g. headers.Content-Type => headers."Content-Type"
|
# e.g. headers.Content-Type => headers."Content-Type"
|
||||||
# also need to avoid replacing negative index in jmespath
|
|
||||||
# e.g. body.users[-1] => body.users[-1], keep unchanged
|
|
||||||
item = item.strip('"')
|
item = item.strip('"')
|
||||||
raw_list.append(f'"{item}"')
|
raw_list.append(f'"{item}"')
|
||||||
elif item.isdigit():
|
elif item.isdigit():
|
||||||
@@ -257,12 +255,12 @@ def ensure_cli_args(args: List) -> List:
|
|||||||
"""
|
"""
|
||||||
# remove deprecated --failfast
|
# remove deprecated --failfast
|
||||||
if "--failfast" in args:
|
if "--failfast" in args:
|
||||||
logger.warning(f"remove deprecated argument: --failfast")
|
logger.warning("remove deprecated argument: --failfast")
|
||||||
args.pop(args.index("--failfast"))
|
args.pop(args.index("--failfast"))
|
||||||
|
|
||||||
# convert --report-file to --html
|
# convert --report-file to --html
|
||||||
if "--report-file" in args:
|
if "--report-file" in args:
|
||||||
logger.warning(f"replace deprecated argument --report-file with --html")
|
logger.warning("replace deprecated argument --report-file with --html")
|
||||||
index = args.index("--report-file")
|
index = args.index("--report-file")
|
||||||
args[index] = "--html"
|
args[index] = "--html"
|
||||||
args.append("--self-contained-html")
|
args.append("--self-contained-html")
|
||||||
@@ -270,7 +268,7 @@ def ensure_cli_args(args: List) -> List:
|
|||||||
# keep compatibility with --save-tests in v2
|
# keep compatibility with --save-tests in v2
|
||||||
if "--save-tests" in args:
|
if "--save-tests" in args:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"generate conftest.py keep compatibility with --save-tests in v2"
|
"generate conftest.py keep compatibility with --save-tests in v2"
|
||||||
)
|
)
|
||||||
args.pop(args.index("--save-tests"))
|
args.pop(args.index("--save-tests"))
|
||||||
_generate_conftest_for_summary(args)
|
_generate_conftest_for_summary(args)
|
||||||
|
|||||||
@@ -32,12 +32,14 @@ class TestCompat(unittest.TestCase):
|
|||||||
compat.convert_variables(None, "tests/data/a-b.c/1.yml")
|
compat.convert_variables(None, "tests/data/a-b.c/1.yml")
|
||||||
|
|
||||||
def test_convert_jmespath(self):
|
def test_convert_jmespath(self):
|
||||||
|
|
||||||
self.assertEqual(compat._convert_jmespath("content.abc"), "body.abc")
|
self.assertEqual(compat._convert_jmespath("content.abc"), "body.abc")
|
||||||
self.assertEqual(compat._convert_jmespath("json.abc"), "body.abc")
|
self.assertEqual(compat._convert_jmespath("json.abc"), "body.abc")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
compat._convert_jmespath("headers.Content-Type"), 'headers."Content-Type"'
|
compat._convert_jmespath("headers.Content-Type"), 'headers."Content-Type"'
|
||||||
)
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
compat._convert_jmespath('headers.User-Agent'), 'headers."User-Agent"'
|
||||||
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
compat._convert_jmespath('headers."Content-Type"'), 'headers."Content-Type"'
|
compat._convert_jmespath('headers."Content-Type"'), 'headers."Content-Type"'
|
||||||
)
|
)
|
||||||
@@ -49,6 +51,10 @@ class TestCompat(unittest.TestCase):
|
|||||||
compat._convert_jmespath("body.users[-1]"),
|
compat._convert_jmespath("body.users[-1]"),
|
||||||
"body.users[-1]",
|
"body.users[-1]",
|
||||||
)
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
compat._convert_jmespath("body.result.WorkNode_-1"),
|
||||||
|
"body.result.WorkNode_-1",
|
||||||
|
)
|
||||||
with self.assertRaises(SystemExit):
|
with self.assertRaises(SystemExit):
|
||||||
compat._convert_jmespath("2.buildings.0.building_id")
|
compat._convert_jmespath("2.buildings.0.building_id")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user