48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
from douyin.fudai.core.fudai_attend import attend_choujiang
|
|
|
|
|
|
def test_attend_choujiang_fallback_click_on_unknown_button_text() -> None:
|
|
analyser = MagicMock()
|
|
analyser._fudai_button_status = "未知状态"
|
|
analyser._fudai_button_text = "按钮文案发生变化"
|
|
analyser._fudai_button_ocr_time = 10**12
|
|
analyser._fudai_button_room_pos = 0
|
|
analyser.room_pos = 0
|
|
analyser._run_id = "test-run"
|
|
analyser._log_kv = MagicMock()
|
|
analyser.click = MagicMock()
|
|
analyser.operation = MagicMock()
|
|
analyser.operation.delay = MagicMock()
|
|
analyser.last_attend_fail_reason = ""
|
|
|
|
ok = attend_choujiang(analyser)
|
|
|
|
assert ok is True
|
|
analyser.click.assert_called_once()
|
|
|
|
|
|
def test_attend_choujiang_treat_notice_text_as_attended() -> None:
|
|
analyser = MagicMock()
|
|
analyser._fudai_button_status = "已参与"
|
|
analyser._fudai_button_text = "直播间,否则会失去抽奖机会"
|
|
analyser._fudai_button_ocr_time = 10**12
|
|
analyser._fudai_button_room_pos = 0
|
|
analyser.room_pos = 0
|
|
analyser._run_id = "test-run"
|
|
analyser._current_fudai_future_ts = 0.0
|
|
analyser._log_kv = MagicMock()
|
|
analyser.click = MagicMock()
|
|
analyser.operation = MagicMock()
|
|
analyser.operation.delay = MagicMock()
|
|
analyser.last_attend_fail_reason = ""
|
|
|
|
ok = attend_choujiang(analyser)
|
|
|
|
assert ok is True
|
|
# “已参与”路径会点击关闭详情
|
|
analyser.click.assert_called_once()
|