90 lines
3.0 KiB
Python
90 lines
3.0 KiB
Python
from __future__ import annotations
|
||
|
||
import time
|
||
from unittest.mock import MagicMock, patch
|
||
|
||
from douyin.fudai.core.fudai_filter_pkg.join_decision import basic_join_decision
|
||
|
||
|
||
def _mk_analyser():
|
||
a = MagicMock()
|
||
a._log_kv = MagicMock()
|
||
a._run_id = "test-run"
|
||
a.needswitch = True
|
||
a.high_value_fudai_enabled = True
|
||
a.high_value_fudai_threshold_yuan = 500.0
|
||
a.high_value_fudai_join_ahead_seconds = 100
|
||
a.high_value_fudai_max_reservations = 3
|
||
a.switch_room_wait_after_stage_diag_seconds = 1.5
|
||
a.wait_minutes = 5
|
||
a.room_pos = 0
|
||
a.last_fudai_x = 0
|
||
a.current_room_title = "测试直播间"
|
||
a.current_room_title_raw = "测试直播间"
|
||
a._fudai_detail_task_count_from_stage = 1
|
||
a.reservations = []
|
||
a.operation = MagicMock()
|
||
a.device_id = "MOCK"
|
||
a.click = MagicMock()
|
||
a.swipe_up_to_next_live = MagicMock()
|
||
return a
|
||
|
||
|
||
def test_high_value_countdown_gt_records_reservation_and_returns_true():
|
||
analyser = _mk_analyser()
|
||
future_ts = time.time() + 300 # > join_ahead_seconds
|
||
detail = ("高价值福袋", "05:00", 10, 1, 1999.0, (time.time(), future_ts, 300))
|
||
|
||
with patch(
|
||
"douyin.fudai.core.fudai_filter_pkg.join_decision.should_skip_fudai_by_config",
|
||
return_value=(True, "countdown_gt_118"),
|
||
), patch(
|
||
"douyin.reservation.reservation_logic.record.record_high_value_reservation",
|
||
return_value=False,
|
||
) as mock_record:
|
||
ok = basic_join_decision(analyser, detail)
|
||
|
||
assert ok is True
|
||
mock_record.assert_called_once()
|
||
# 记录预约后应立即切换直播间(needswitch=True)
|
||
analyser.swipe_up_to_next_live.assert_called_once()
|
||
|
||
|
||
def test_high_value_countdown_within_join_window_attends():
|
||
analyser = _mk_analyser()
|
||
future_ts = time.time() + 30 # <= join_ahead_seconds
|
||
detail = ("高价值福袋", "00:30", 10, 1, 1999.0, (time.time(), future_ts, 30))
|
||
|
||
with patch(
|
||
"douyin.fudai.core.fudai_filter_pkg.join_decision.should_skip_fudai_by_config",
|
||
return_value=(True, "countdown_gt_118"),
|
||
), patch(
|
||
"douyin.fudai.core.fudai_attend.attend_choujiang",
|
||
return_value=True,
|
||
) as mock_attend:
|
||
ok = basic_join_decision(analyser, detail)
|
||
|
||
assert ok is True
|
||
mock_attend.assert_called_once()
|
||
|
||
|
||
def test_single_room_mode_bypasses_reservation_path():
|
||
analyser = _mk_analyser()
|
||
analyser.needswitch = False
|
||
future_ts = time.time() + 300
|
||
detail = ("高价值福袋", "05:00", 10, 1, 1999.0, (time.time(), future_ts, 300))
|
||
|
||
with patch(
|
||
"douyin.fudai.core.fudai_filter_pkg.join_decision.should_skip_fudai_by_config",
|
||
return_value=(True, "countdown_gt_118"),
|
||
), patch(
|
||
"douyin.reservation.reservation_logic.record.record_high_value_reservation",
|
||
return_value=False,
|
||
) as mock_record:
|
||
ok = basic_join_decision(analyser, detail)
|
||
|
||
# 单间模式走“直接参与”路径,不会进入“高价值预约记录”分支
|
||
assert ok is False
|
||
mock_record.assert_not_called()
|
||
analyser.swipe_up_to_next_live.assert_not_called()
|