168 lines
5.8 KiB
Python
168 lines
5.8 KiB
Python
from __future__ import annotations
|
|
|
|
import time
|
|
from types import SimpleNamespace
|
|
from unittest.mock import MagicMock
|
|
|
|
|
|
def test_record_high_value_reservation_preserves_button_fields():
|
|
from douyin.reservation.reservation_logic.record import record_high_value_reservation
|
|
|
|
analyser = SimpleNamespace(
|
|
_log_kv=MagicMock(return_value=None),
|
|
_fudai_button_text="一键发表评论",
|
|
_fudai_button_status="需要评论",
|
|
)
|
|
reservations = []
|
|
|
|
ok = record_high_value_reservation(
|
|
analyser=analyser,
|
|
fudai_content_text="儿童电话手表",
|
|
prize_value_yuan=899.0,
|
|
lastsecond=120,
|
|
future_timestamp=time.time() + 600,
|
|
x=162,
|
|
needswitch=True,
|
|
wait_minutes=0,
|
|
post_switch_delay_s=0.0,
|
|
room_pos=1,
|
|
reservations=reservations,
|
|
reservation_focus_until_ts_ref=[0.0],
|
|
close_detail_callback=lambda: None,
|
|
swipe_up_switch_callback=lambda: None,
|
|
swipe_down_back_callback=lambda: None,
|
|
add_reservation_callback=lambda items, item: items.append(item),
|
|
sort_reservations_callback=lambda: None,
|
|
write_state_callback=lambda: None,
|
|
room_title="学而思",
|
|
room_title_raw="学而思",
|
|
task_count=2,
|
|
time_text="10:00",
|
|
participants=0,
|
|
copies=1,
|
|
)
|
|
|
|
assert ok is False
|
|
assert reservations[0]["button_text"] == "一键发表评论"
|
|
assert reservations[0]["button_status"] == "需要评论"
|
|
|
|
|
|
def test_record_high_value_reservation_preserves_prejoined_fansclub_marker():
|
|
from douyin.reservation.reservation_logic.record import record_high_value_reservation
|
|
|
|
analyser = SimpleNamespace(
|
|
_log_kv=MagicMock(return_value=None),
|
|
_fudai_button_text="加入购物粉丝团并关注主播",
|
|
_fudai_button_status="需要加入粉丝团",
|
|
_reservation_prejoined_fansclub=True,
|
|
_reservation_prejoin_fansclub_button_text="加入购物粉丝团并关注主播",
|
|
_reservation_prejoin_fansclub_ts=123.0,
|
|
)
|
|
reservations = []
|
|
|
|
ok = record_high_value_reservation(
|
|
analyser=analyser,
|
|
fudai_content_text="高价值福袋",
|
|
prize_value_yuan=159.0,
|
|
lastsecond=200,
|
|
future_timestamp=time.time() + 600,
|
|
x=162,
|
|
needswitch=True,
|
|
wait_minutes=0,
|
|
post_switch_delay_s=0.0,
|
|
room_pos=5,
|
|
reservations=reservations,
|
|
reservation_focus_until_ts_ref=[0.0],
|
|
close_detail_callback=lambda: None,
|
|
swipe_up_switch_callback=lambda: None,
|
|
swipe_down_back_callback=lambda: None,
|
|
add_reservation_callback=lambda items, item: items.append(item),
|
|
sort_reservations_callback=lambda: None,
|
|
write_state_callback=lambda: None,
|
|
room_title="交个朋友",
|
|
room_title_raw="交个朋友",
|
|
task_count=2,
|
|
time_text="03:21",
|
|
participants=0,
|
|
copies=1,
|
|
)
|
|
|
|
assert ok is False
|
|
assert reservations[0]["prejoined_fansclub_before_reservation"] is True
|
|
assert reservations[0]["prejoin_fansclub_button_text"] == "加入购物粉丝团并关注主播"
|
|
assert reservations[0]["prejoin_fansclub_ts"] == 123.0
|
|
|
|
|
|
def test_write_reservations_state_preserves_prejoined_fansclub_marker(tmp_path):
|
|
from douyin.reservation.douyin_reservation import write_reservations_state
|
|
|
|
state_path = tmp_path / "reservations.json"
|
|
write_reservations_state(
|
|
state_path=str(state_path),
|
|
reservations=[
|
|
{
|
|
"future_ts": time.time() + 600,
|
|
"prize_value_yuan": 159.0,
|
|
"content": "高价值福袋",
|
|
"pos_seen": 5,
|
|
"room_title": "交个朋友",
|
|
"room_title_raw": "交个朋友",
|
|
"task_count": 2,
|
|
"button_text": "加入购物粉丝团并关注主播",
|
|
"button_status": "需要加入粉丝团",
|
|
"prejoined_fansclub_before_reservation": True,
|
|
"prejoin_fansclub_button_text": "加入购物粉丝团并关注主播",
|
|
"prejoin_fansclub_ts": 123.0,
|
|
}
|
|
],
|
|
room_pos=5,
|
|
current_room_title="交个朋友",
|
|
current_room_title_raw="交个朋友",
|
|
reason="test",
|
|
)
|
|
|
|
import json
|
|
|
|
data = json.loads(state_path.read_text(encoding="utf-8"))
|
|
item = data["reservations"][0]
|
|
assert item["prejoined_fansclub_before_reservation"] is True
|
|
assert item["prejoin_fansclub_button_text"] == "加入购物粉丝团并关注主播"
|
|
assert item["prejoin_fansclub_ts"] == 123.0
|
|
|
|
|
|
def test_duplicate_reservation_preserves_prejoined_fansclub_marker():
|
|
from douyin.reservation.reservation_logic.add import add_reservation_core_logic
|
|
|
|
ft = time.time() + 600
|
|
reservations = [
|
|
{
|
|
"future_ts": ft,
|
|
"prize_value_yuan": 159.0,
|
|
"content": "高价值福袋",
|
|
"room_title": "交个朋友",
|
|
}
|
|
]
|
|
item = {
|
|
"future_ts": ft,
|
|
"prize_value_yuan": 159.0,
|
|
"content": "高价值福袋",
|
|
"room_title": "交个朋友",
|
|
"prejoined_fansclub_before_reservation": True,
|
|
"prejoin_fansclub_button_text": "加入购物粉丝团并关注主播",
|
|
"prejoin_fansclub_ts": 123.0,
|
|
}
|
|
|
|
ok = add_reservation_core_logic(
|
|
reservations=reservations,
|
|
item=item,
|
|
max_reservations=10,
|
|
analyser=SimpleNamespace(_log_kv=MagicMock(return_value=None)),
|
|
write_state_callback=lambda: None,
|
|
)
|
|
|
|
assert ok is False
|
|
assert len(reservations) == 1
|
|
assert reservations[0]["prejoined_fansclub_before_reservation"] is True
|
|
assert reservations[0]["prejoin_fansclub_button_text"] == "加入购物粉丝团并关注主播"
|
|
assert reservations[0]["prejoin_fansclub_ts"] == 123.0
|