-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 更新全局变量替换逻辑 * 修复变量赋值 * 删除SQL变量 * 修复类型检查 * 修复环境变量读取 * 捕获请求数据变量解析错误信息
- Loading branch information
Showing
5 changed files
with
82 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
from jsonpath import findall | ||
|
||
from httpfpt.common.env_handler import write_env_vars | ||
from httpfpt.common.errors import JsonPathFindError, VariableError | ||
from httpfpt.common.variable_cache import variable_cache | ||
from httpfpt.common.yaml_handler import write_yaml_vars | ||
from httpfpt.core.path_conf import RUN_ENV_PATH | ||
from httpfpt.enums.var_type import VarType | ||
|
||
|
||
def record_variables(jsonpath: str, target: dict, key: str, set_type: str, env: str) -> None: | ||
""" | ||
记录变量 | ||
:param jsonpath: | ||
:param set_type: | ||
:param target: | ||
:param key: | ||
:param env: | ||
:return: | ||
""" | ||
value = findall(jsonpath, target) | ||
if not value: | ||
raise JsonPathFindError(f'jsonpath 取值失败, 表达式: {jsonpath}') | ||
value_str = str(value[0]) | ||
if set_type == VarType.CACHE: | ||
variable_cache.set(key, value_str) | ||
elif set_type == VarType.ENV: | ||
write_env_vars(RUN_ENV_PATH, env, key, value_str) | ||
elif set_type == VarType.GLOBAL: | ||
write_yaml_vars({key: value_str}) | ||
else: | ||
raise VariableError(f'变量设置失败, 用例参数 "type: {set_type}" 值错误, 请使用 cache / env / global') |