87 lines
2.8 KiB
Python
87 lines
2.8 KiB
Python
from __future__ import annotations
|
|
|
|
import time
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from douyin.fudai.core.fudai_detail_orchestrator_pkg.read_with_retries import (
|
|
read_fudai_detail_with_retries,
|
|
)
|
|
|
|
|
|
def _mk_analyser():
|
|
a = MagicMock()
|
|
a._log_kv = MagicMock()
|
|
a.operation = MagicMock()
|
|
a.operation.delay = MagicMock()
|
|
a.fudai_detail_max_attempts = 2
|
|
a.fudai_detail_retry_delay_seconds = 0.2
|
|
a.fudai_detail_initial_wait_seconds = 0.3
|
|
a.fudai_detail_verified_wait_seconds = 0.2
|
|
a._fudai_detail_verified = False
|
|
a.current_room_title = "房间A"
|
|
a.current_room_title_raw = "房间A"
|
|
return a
|
|
|
|
|
|
def test_invalid_countdown_text_should_not_short_circuit_first_attempt():
|
|
analyser = _mk_analyser()
|
|
now = time.time()
|
|
first_tuple = ("", "60:37", 0, 0, 1599.0, (now, now + 3600, 3637))
|
|
second_tuple = ("", "00:54", 0, 0, 1599.0, (now, now + 54, 54))
|
|
|
|
call_seq = [
|
|
("ok", first_tuple, {}),
|
|
("ok", second_tuple, {}),
|
|
]
|
|
|
|
with patch(
|
|
"douyin.fudai.core.fudai_detail_orchestrator_pkg.read_with_retries.read_fudai_detail_once",
|
|
side_effect=call_seq,
|
|
) as mock_read_once, patch(
|
|
"douyin.fudai.core.fudai_detail_orchestrator_pkg.read_with_retries.validate_fudai_detail",
|
|
return_value=(True, "ok"),
|
|
):
|
|
result = read_fudai_detail_with_retries(
|
|
analyser=analyser,
|
|
fudai_x=0,
|
|
read_once_callback=None,
|
|
close_detail_callback=None,
|
|
ensure_open_callback=None,
|
|
)
|
|
|
|
assert mock_read_once.call_count == 2
|
|
|
|
|
|
def test_invalid_countdown_text_is_rejected_by_filter_layer():
|
|
from douyin.fudai.core.fudai_filter_pkg.should_skip import should_skip_fudai_by_config
|
|
|
|
analyser = _mk_analyser()
|
|
detail = ("", "60:37", 0, 0, 1599.0, (time.time(), time.time() + 3600, 3637))
|
|
skip, reason = should_skip_fudai_by_config(analyser, detail)
|
|
assert skip is True
|
|
assert reason == "countdown_invalid"
|
|
|
|
|
|
def test_missing_countdown_text_does_not_log_default_sixty_seconds():
|
|
analyser = _mk_analyser()
|
|
now = time.time()
|
|
only_tuple = ("福袋", "", 10, 1, 999.0, (now, now, None))
|
|
|
|
with patch(
|
|
"douyin.fudai.core.fudai_detail_orchestrator_pkg.read_with_retries.read_fudai_detail_once",
|
|
return_value=("ok", only_tuple, {}),
|
|
), patch(
|
|
"douyin.fudai.core.fudai_detail_orchestrator_pkg.read_with_retries.validate_fudai_detail",
|
|
return_value=(True, "ok"),
|
|
):
|
|
read_fudai_detail_with_retries(
|
|
analyser=analyser,
|
|
fudai_x=0,
|
|
read_once_callback=None,
|
|
close_detail_callback=None,
|
|
ensure_open_callback=None,
|
|
)
|
|
|
|
log_text = "\n".join(str(c) for c in analyser._log_kv.call_args_list)
|
|
assert "倒计时=未识别,剩余59秒" not in log_text
|