refactor(fudai): 拆出额外验证 + 兜底无效详情检查(1121→1084,-37 行)
- handle_extra_validation:调用 validate_fudai_detail,失败时关闭详情 + 写日志 - handle_invalid_detail_fallback:价值=0 且内容空时判定为"无效详情"提前 return 新增 9 个单元测试,1239 → 1248 用例全过。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
f075f94b31
commit
b8a35656a0
3 files changed
+132
-41
No files matched your search
@@ -941,3 +941,73 @@ def test_first_open_filter_skip_normal_triggers_close_switch():
|
||||
)
|
||||
)
|
||||
assert should_return is True
|
||||
|
||||
|
||||
# ---- handle_extra_validation ---- #
|
||||
|
||||
def test_extra_validation_detail_none_returns_false():
|
||||
a = MagicMock()
|
||||
assert fudai_detail_blocks.handle_extra_validation(a, None, _time.time()) is False
|
||||
|
||||
|
||||
def test_extra_validation_valid_returns_false():
|
||||
a = MagicMock()
|
||||
detail = ("c", "x", "x", "x", 5.0, ("s", _time.time() + 100, 100))
|
||||
with patch(
|
||||
"douyin.fudai.douyin_fudai_detail.validate_fudai_detail",
|
||||
return_value=(True, ""),
|
||||
):
|
||||
assert fudai_detail_blocks.handle_extra_validation(a, detail, _time.time()) is False
|
||||
|
||||
|
||||
def test_extra_validation_invalid_returns_true_and_closes():
|
||||
a = MagicMock()
|
||||
detail = ("c", "x", "x", "x", 5.0, ("s", _time.time() + 100, 100))
|
||||
with patch(
|
||||
"douyin.fudai.douyin_fudai_detail.validate_fudai_detail",
|
||||
return_value=(False, "bad"),
|
||||
), patch(
|
||||
"douyin.fudai.douyin_fudai_detail.close_fudai_detail"
|
||||
) as cd:
|
||||
assert fudai_detail_blocks.handle_extra_validation(a, detail, _time.time()) is True
|
||||
cd.assert_called_once_with(a)
|
||||
|
||||
|
||||
def test_extra_validation_swallows_exception():
|
||||
a = MagicMock()
|
||||
with patch(
|
||||
"douyin.fudai.douyin_fudai_detail.validate_fudai_detail",
|
||||
side_effect=RuntimeError("boom"),
|
||||
):
|
||||
assert fudai_detail_blocks.handle_extra_validation(a, ("x",), _time.time()) is False
|
||||
|
||||
|
||||
# ---- handle_invalid_detail_fallback ---- #
|
||||
|
||||
def test_invalid_detail_fallback_zero_value_empty_content_returns_true():
|
||||
a = MagicMock()
|
||||
detail = ("", "x", "x", "x", 0.0)
|
||||
assert fudai_detail_blocks.handle_invalid_detail_fallback(a, detail, _time.time()) is True
|
||||
|
||||
|
||||
def test_invalid_detail_fallback_with_content_returns_false():
|
||||
a = MagicMock()
|
||||
detail = ("有内容", "x", "x", "x", 0.0)
|
||||
assert fudai_detail_blocks.handle_invalid_detail_fallback(a, detail, _time.time()) is False
|
||||
|
||||
|
||||
def test_invalid_detail_fallback_with_value_returns_false():
|
||||
a = MagicMock()
|
||||
detail = ("", "x", "x", "x", 5.0)
|
||||
assert fudai_detail_blocks.handle_invalid_detail_fallback(a, detail, _time.time()) is False
|
||||
|
||||
|
||||
def test_invalid_detail_fallback_short_tuple_returns_false():
|
||||
a = MagicMock()
|
||||
detail = ("only_one",)
|
||||
assert fudai_detail_blocks.handle_invalid_detail_fallback(a, detail, _time.time()) is False
|
||||
|
||||
|
||||
def test_invalid_detail_fallback_non_tuple_returns_false():
|
||||
a = MagicMock()
|
||||
assert fudai_detail_blocks.handle_invalid_detail_fallback(a, None, _time.time()) is False
|
||||
Reference in new issue
Block a user