84251770b4
## 背景 线上首页轮播候选记录中,测试账号 u33(11111111111)贡献约 51.8% 的真实记录,导致该用户频繁出现。 ## 改动 - App 首页轮播真实记录查询排除全部已配置测试账号 - 后台首页轮播可展示记录同步采用相同过滤口径 - 同时兼容 TEST_ACCOUNT_PHONE 与 TEST_ACCOUNT_PHONES - 测试账号配置变化时立即使轮播查询缓存失效 - 不删除历史业务数据,仅在展示查询中排除 ## 验证 - ruff check:通过 - pytest tests/test_ops_marquee.py -q:1 passed --------- Co-authored-by: linkeyu <798648091@qq.com> Reviewed-on: #215 Co-authored-by: linkeyu <linkeyu@wonderable.ai> Co-committed-by: linkeyu <linkeyu@wonderable.ai>
78 lines
2.8 KiB
Python
78 lines
2.8 KiB
Python
from __future__ import annotations
|
|
|
|
from app.core.config import settings
|
|
from app.db.session import SessionLocal
|
|
from app.models.comparison import ComparisonRecord
|
|
from app.models.user import User
|
|
from app.repositories import ops_marquee
|
|
|
|
|
|
def _clear_real_rows_cache() -> None:
|
|
ops_marquee._real_rows_cache.update(at=None, rows=None, test_phones=None)
|
|
|
|
|
|
def test_real_marquee_records_exclude_configured_test_account(monkeypatch) -> None:
|
|
legacy_test_phone = "19900009991"
|
|
listed_test_phone = "19900009992"
|
|
real_phone = "19900009993"
|
|
monkeypatch.setattr(settings, "TEST_ACCOUNT_PHONE", legacy_test_phone)
|
|
monkeypatch.setattr(settings, "TEST_ACCOUNT_PHONES", listed_test_phone)
|
|
_clear_real_rows_cache()
|
|
|
|
try:
|
|
with SessionLocal() as db:
|
|
legacy_test_user = User(
|
|
phone=legacy_test_phone,
|
|
username="29900009991",
|
|
register_channel="sms",
|
|
)
|
|
listed_test_user = User(
|
|
phone=listed_test_phone,
|
|
username="29900009992",
|
|
register_channel="sms",
|
|
)
|
|
real_user = User(
|
|
phone=real_phone,
|
|
username="29900009993",
|
|
register_channel="sms",
|
|
)
|
|
db.add_all([legacy_test_user, listed_test_user, real_user])
|
|
db.flush()
|
|
db.add_all([
|
|
ComparisonRecord(
|
|
user_id=legacy_test_user.id,
|
|
trace_id="marquee-legacy-test-account-trace",
|
|
status="success",
|
|
saved_amount_cents=29_991,
|
|
items=[],
|
|
comparison_results=[],
|
|
),
|
|
ComparisonRecord(
|
|
user_id=listed_test_user.id,
|
|
trace_id="marquee-listed-test-account-trace",
|
|
status="success",
|
|
saved_amount_cents=29_992,
|
|
items=[],
|
|
comparison_results=[],
|
|
),
|
|
ComparisonRecord(
|
|
user_id=real_user.id,
|
|
trace_id="marquee-real-account-trace",
|
|
status="success",
|
|
saved_amount_cents=29_993,
|
|
items=[],
|
|
comparison_results=[],
|
|
),
|
|
])
|
|
db.flush()
|
|
|
|
app_rows = ops_marquee._recent_real_rows(db)
|
|
browse_rows, _ = ops_marquee.list_real_records(db, mode="real", limit=1_000)
|
|
finally:
|
|
_clear_real_rows_cache()
|
|
|
|
assert all(saved not in {29_991, 29_992} for _uid, saved, _nickname in app_rows)
|
|
assert any(saved == 29_993 for _uid, saved, _nickname in app_rows)
|
|
assert all(row["saved_amount_cents"] not in {29_991, 29_992} for row in browse_rows)
|
|
assert any(row["saved_amount_cents"] == 29_993 for row in browse_rows)
|