Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let `_make_validate` method supports the `list` structures JSON #18

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+14 −12
Diff settings

Always

Just for now

Copy path View file
@@ -12,7 +12,6 @@
except ImportError:
JSONDecodeError = ValueError


IGNORE_REQUEST_HEADERS = [
"host",
"accept",
@@ -183,7 +182,7 @@ def _make_request_data(self, teststep_dict, entry_json):
# post_data = utils.x_www_form_urlencoded(post_data)
pass
else:
#TODO: make compatible with more mimeType
# TODO: make compatible with more mimeType
pass

teststep_dict["request"][request_data_key] = post_data
@@ -252,16 +251,18 @@ def _make_validate(self, teststep_dict, entry_json):
else:
resp_content_json = json.loads(text)

if not isinstance(resp_content_json, dict):
return

for key, value in resp_content_json.items():
if isinstance(value, (dict, list)):
continue

teststep_dict["validate"].append(
{"eq": ["content.{}".format(key), value]}
)
if isinstance(resp_content_json, dict):
for key, value in resp_content_json.items():

This comment has been minimized.

Copy link
@debugtalk

debugtalk Feb 2, 2019

Contributor
if isinstance(value, (dict, list)):
    continue

这一部分还是有必要的,因为假如 value 为 dict/list,已经算是复杂结构体了,保持不变的可能性较小,所以不宜直接将其作为比较项。

This comment has been minimized.

Copy link
@asdf2014

asdf2014 Feb 3, 2019

Author

的确,不过目前我这边用的还没有这个问题 😅

teststep_dict["validate"].append(
{"eq": ["content.{}".format(key), value]}
)
elif isinstance(resp_content_json, list):
for i in range(0, len(resp_content_json)):
resp_content_json = resp_content_json[i]

This comment has been minimized.

Copy link
@debugtalk

debugtalk Feb 2, 2019

Contributor

这里有两个问题:
1、重复使用 resp_content_json 这个变量名容易产生混淆,建议对 list 的元素采用不同的变量名;
2、你这里假设 list 始终是 [{a:a},{b:b},...] 的形式,那假如出现 [{a:a},b,...] 的情况就会出现问题。

This comment has been minimized.

Copy link
@asdf2014

asdf2014 Feb 3, 2019

Author

是的,想要通用的话,还是要多考虑一下这块,期待后续 validator 支持 jmespath 的语法~~

for key, value in resp_content_json.items():
teststep_dict["validate"].append(
{"eq": ["content.{}.{}".format(i, key), value]}
)

def _prepare_teststep(self, entry_json):
""" extract info from entry dict and make teststep
@@ -318,6 +319,7 @@ def _prepare_teststeps(self, testcase):
teststeps list are parsed from HAR log entries list.
"""

def is_exclude(url, exclude_str):
exclude_str_list = exclude_str.split("|")
for exclude_str in exclude_str_list:
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.