fix(exchange,case_validator),refactor(),feat(model): 解决 Pydantic 模型初始化与变量占位符的类型冲突,优化变量替换逻辑,重构 CaseInfo 模型并引入延迟校验机制
- 引入 SmartInt 和 SmartDict 类型,支持 YAML 占位符与业务类型的自动转换。 - 优化 CaseInfo 互斥校验逻辑,确保 request 与 api_action 二选一。 - 统一使用 Pydantic V2 的 model_config 规范。 - 将变量替换时机提前至模型实例化之前,支持占位符在校验前完成真实值注入, 保证了 int/bool 等字段的类型转换正确性。 - 优化断言渲染时机,支持响应提取值关联。
This commit is contained in:
@@ -15,10 +15,10 @@ import time
|
||||
import urllib.parse
|
||||
import hashlib
|
||||
|
||||
from commons.databases import db
|
||||
# from commons.databases import db
|
||||
|
||||
from commons.file_processors.processor_factory import get_processor_class
|
||||
from commons import settings
|
||||
# from commons.file_processors.yaml_processor import YamlProcessor as get_processor_class
|
||||
from core import settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -62,31 +62,31 @@ def add(a, b):
|
||||
return str(int(a) + int(b))
|
||||
|
||||
|
||||
@Funcs.register("sql")
|
||||
def sql(s: str) -> str:
|
||||
res = db.execute_sql(s)
|
||||
|
||||
return res[0][0]
|
||||
# @Funcs.register("sql")
|
||||
# def sql(s: str) -> str:
|
||||
# res = db.execute_sql(s)
|
||||
#
|
||||
# return res[0][0]
|
||||
|
||||
|
||||
@Funcs.register("new_id")
|
||||
def new_id():
|
||||
# 自增,永不重复
|
||||
id_file = get_processor_class(settings.id_path)
|
||||
data = id_file.load()
|
||||
data["id"] += 1
|
||||
id_file.save(data)
|
||||
|
||||
return data["id"]
|
||||
# @Funcs.register("new_id")
|
||||
# def new_id():
|
||||
# # 自增,永不重复
|
||||
# id_file = get_processor_class(settings.id_path)
|
||||
# data = id_file.load()
|
||||
# data["id"] += 1
|
||||
# id_file.save(data)
|
||||
#
|
||||
# return data["id"]
|
||||
|
||||
|
||||
@Funcs.register("last_id")
|
||||
def last_id() -> str:
|
||||
# 不自增,只返回结果
|
||||
|
||||
id_file = get_processor_class(settings.id_path)
|
||||
data = id_file.load()
|
||||
return data["id"]
|
||||
# @Funcs.register("last_id")
|
||||
# def last_id() -> str:
|
||||
# # 不自增,只返回结果
|
||||
#
|
||||
# id_file = get_processor_class(settings.id_path)
|
||||
# data = id_file.load()
|
||||
# return data["id"]
|
||||
|
||||
|
||||
@Funcs.register("md5")
|
||||
@@ -131,9 +131,9 @@ def rsa_decode(content: str) -> str:
|
||||
...
|
||||
|
||||
|
||||
@Funcs.register()
|
||||
@Funcs.register("gen_phone")
|
||||
def func_name_test():
|
||||
...
|
||||
return "我被替换了!!!"
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user