haha
This commit is contained in:
58
test1.py
58
test1.py
@@ -348,12 +348,59 @@ def _code_indicates_success(value: Any) -> Optional[bool]:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def _to_int_or_none(value: Any) -> Optional[int]:
|
||||||
|
try:
|
||||||
|
if value is None:
|
||||||
|
return None
|
||||||
|
if isinstance(value, bool):
|
||||||
|
return int(value)
|
||||||
|
if isinstance(value, (int, float)):
|
||||||
|
return int(value)
|
||||||
|
text = str(value).strip()
|
||||||
|
if not text:
|
||||||
|
return None
|
||||||
|
if text.lstrip("-").isdigit():
|
||||||
|
return int(text)
|
||||||
|
return None
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _extract_interface_message(data: dict) -> str:
|
||||||
|
for key in ("msg", "message", "error", "errorMsg", "detail", "retMsg"):
|
||||||
|
value = data.get(key)
|
||||||
|
if isinstance(value, str) and value.strip():
|
||||||
|
return value.strip()
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
def _is_sms_already_sent_response(data: dict, message: str) -> bool:
|
||||||
|
code_keys = ("code", "retCode", "resultCode", "statusCode", "errno")
|
||||||
|
code_val = None
|
||||||
|
for key in code_keys:
|
||||||
|
if key in data:
|
||||||
|
code_val = _to_int_or_none(data.get(key))
|
||||||
|
if code_val is not None:
|
||||||
|
break
|
||||||
|
if code_val != 1001:
|
||||||
|
return False
|
||||||
|
|
||||||
|
text = (message or "").strip()
|
||||||
|
if not text:
|
||||||
|
return False
|
||||||
|
# 这类文案通常表示验证码已下发或短信频控,不应判定为滑块失败。
|
||||||
|
hints = ("验证码已发送", "短信验证码已发送", "请稍后重试", "请稍等")
|
||||||
|
return any(h in text for h in hints)
|
||||||
|
|
||||||
|
|
||||||
def _assert_interface_success(body: Any) -> None:
|
def _assert_interface_success(body: Any) -> None:
|
||||||
data = _coerce_json_body(body)
|
data = _coerce_json_body(body)
|
||||||
if not isinstance(data, dict):
|
if not isinstance(data, dict):
|
||||||
return
|
return
|
||||||
|
|
||||||
fail_reasons: list[str] = []
|
fail_reasons: list[str] = []
|
||||||
|
message = _extract_interface_message(data)
|
||||||
|
is_soft_success = _is_sms_already_sent_response(data, message)
|
||||||
|
|
||||||
for key in ("success", "ok"):
|
for key in ("success", "ok"):
|
||||||
if key in data and not bool(data[key]):
|
if key in data and not bool(data[key]):
|
||||||
@@ -364,19 +411,16 @@ def _assert_interface_success(body: Any) -> None:
|
|||||||
continue
|
continue
|
||||||
code_ok = _code_indicates_success(data[key])
|
code_ok = _code_indicates_success(data[key])
|
||||||
if code_ok is False:
|
if code_ok is False:
|
||||||
|
if is_soft_success:
|
||||||
|
continue
|
||||||
fail_reasons.append(f"{key}={data[key]}")
|
fail_reasons.append(f"{key}={data[key]}")
|
||||||
|
|
||||||
message = ""
|
|
||||||
for key in ("msg", "message", "error", "errorMsg", "detail", "retMsg"):
|
|
||||||
value = data.get(key)
|
|
||||||
if isinstance(value, str) and value.strip():
|
|
||||||
message = value.strip()
|
|
||||||
break
|
|
||||||
|
|
||||||
if message:
|
if message:
|
||||||
lowered = message.lower()
|
lowered = message.lower()
|
||||||
fail_words = ("失败", "错误", "无效", "fail", "error", "invalid", "请重新", "未通过")
|
fail_words = ("失败", "错误", "无效", "fail", "error", "invalid", "请重新", "未通过")
|
||||||
if any(word in lowered for word in fail_words):
|
if any(word in lowered for word in fail_words):
|
||||||
|
if is_soft_success:
|
||||||
|
return
|
||||||
fail_reasons.append(f"msg={message}")
|
fail_reasons.append(f"msg={message}")
|
||||||
|
|
||||||
if fail_reasons:
|
if fail_reasons:
|
||||||
|
|||||||
Reference in New Issue
Block a user