mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 17:29:56 +08:00
fix: compatibility with v2, headers.Content-Type
This commit is contained in:
@@ -6,12 +6,21 @@ from typing import List, Dict, Text
|
||||
|
||||
|
||||
def convert_jmespath(raw: Text) -> Text:
|
||||
# content.xx/json.xx => body.xx
|
||||
if raw.startswith("content"):
|
||||
return f"body{raw[len('content'):]}"
|
||||
elif raw.startswith("json"):
|
||||
return f"body{raw[len('json'):]}"
|
||||
|
||||
return raw
|
||||
# add quotes for field with separator, e.g. headers.Content-Type
|
||||
raw_list = []
|
||||
for item in raw.split("."):
|
||||
if "-" in item:
|
||||
raw_list.append(f'"{item}"')
|
||||
else:
|
||||
raw_list.append(item)
|
||||
|
||||
return ".".join(raw_list)
|
||||
|
||||
|
||||
def convert_extractors(extractors: List) -> Dict:
|
||||
|
||||
22
httprunner/compat_test.py
Normal file
22
httprunner/compat_test.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from httprunner import compat
|
||||
|
||||
|
||||
class TestCompat(unittest.TestCase):
|
||||
|
||||
def test_convert_jmespath(self):
|
||||
|
||||
self.assertEqual(
|
||||
compat.convert_jmespath("content.abc"),
|
||||
"body.abc"
|
||||
)
|
||||
self.assertEqual(
|
||||
compat.convert_jmespath("json.abc"),
|
||||
"body.abc"
|
||||
)
|
||||
self.assertEqual(
|
||||
compat.convert_jmespath("headers.Content-Type"),
|
||||
'headers."Content-Type"'
|
||||
)
|
||||
Reference in New Issue
Block a user