fix(marquee): 首页轮播脱敏名改为按 user_id 恒定 + 去 Faker 依赖 (#49)
Co-authored-by: OuYingJun1024 <1034284404@qq.com> Reviewed-on: #49 Co-authored-by: ouzhou <ouzhou@wonderable.ai> Co-committed-by: ouzhou <ouzhou@wonderable.ai>
This commit was merged in pull request #49.
This commit is contained in:
@@ -91,6 +91,80 @@ def test_user_filter_by_status(admin_client: TestClient, admin_token: str) -> No
|
||||
assert all(u["status"] == "active" for u in r.json()["items"])
|
||||
|
||||
|
||||
def test_user_list_sort_filter_range(admin_client: TestClient, admin_token: str) -> None:
|
||||
"""用户列表:渠道/昵称筛选 + id 升降序 + 时间范围 + 非法 sort_by 422。"""
|
||||
db = SessionLocal()
|
||||
try:
|
||||
u1 = user_repo.upsert_user_for_login(db, phone="13811110001", register_channel="sms")
|
||||
u1.nickname = "排序测试甲"
|
||||
u2 = user_repo.upsert_user_for_login(db, phone="13811110002", register_channel="wechat")
|
||||
u2.nickname = "排序测试乙"
|
||||
db.commit()
|
||||
id1, id2 = u1.id, u2.id
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
# 渠道精确筛选
|
||||
r = admin_client.get(
|
||||
"/admin/api/users", params={"register_channel": "wechat"}, headers=_auth(admin_token)
|
||||
)
|
||||
assert r.status_code == 200, r.text
|
||||
assert all(u["register_channel"] == "wechat" for u in r.json()["items"])
|
||||
|
||||
# 昵称模糊筛选
|
||||
r = admin_client.get(
|
||||
"/admin/api/users", params={"nickname": "排序测试", "limit": 100}, headers=_auth(admin_token)
|
||||
)
|
||||
ids = {u["id"] for u in r.json()["items"]}
|
||||
assert id1 in ids and id2 in ids
|
||||
|
||||
# id 升序 / 降序
|
||||
asc_ids = [
|
||||
u["id"]
|
||||
for u in admin_client.get(
|
||||
"/admin/api/users",
|
||||
params={"sort_by": "id", "sort_order": "asc", "limit": 100},
|
||||
headers=_auth(admin_token),
|
||||
).json()["items"]
|
||||
]
|
||||
assert asc_ids == sorted(asc_ids)
|
||||
desc_ids = [
|
||||
u["id"]
|
||||
for u in admin_client.get(
|
||||
"/admin/api/users",
|
||||
params={"sort_by": "id", "sort_order": "desc", "limit": 100},
|
||||
headers=_auth(admin_token),
|
||||
).json()["items"]
|
||||
]
|
||||
assert desc_ids == sorted(desc_ids, reverse=True)
|
||||
|
||||
# 时间范围:2000 年之前无人;之后有人(验证范围条件确实生效)
|
||||
assert (
|
||||
admin_client.get(
|
||||
"/admin/api/users", params={"created_to": "2000-01-01T00:00:00Z"},
|
||||
headers=_auth(admin_token),
|
||||
).json()["items"]
|
||||
== []
|
||||
)
|
||||
assert (
|
||||
len(
|
||||
admin_client.get(
|
||||
"/admin/api/users", params={"created_from": "2000-01-01T00:00:00Z", "limit": 100},
|
||||
headers=_auth(admin_token),
|
||||
).json()["items"]
|
||||
)
|
||||
>= 1
|
||||
)
|
||||
|
||||
# 非法 sort_by → 422
|
||||
assert (
|
||||
admin_client.get(
|
||||
"/admin/api/users", params={"sort_by": "phone"}, headers=_auth(admin_token)
|
||||
).status_code
|
||||
== 422
|
||||
)
|
||||
|
||||
|
||||
def test_wallet_and_withdraw_lists(admin_client: TestClient, admin_token: str) -> None:
|
||||
uid = _seed_user_with_data("13800000004")
|
||||
r = admin_client.get(
|
||||
@@ -112,6 +186,65 @@ def test_feedback_list(admin_client: TestClient, admin_token: str) -> None:
|
||||
assert all(f["status"] == "new" for f in r.json()["items"])
|
||||
|
||||
|
||||
def test_ad_coin_audit_full_count_truncate_and_only_mismatch(
|
||||
admin_client: TestClient, admin_token: str
|
||||
) -> None:
|
||||
"""A+B:total/mismatch_count 按全量统计(不受 limit 影响),truncated 旗标 + only_mismatch 过滤。
|
||||
|
||||
用 capped 行造确定性数据(应发恒 0,coin==0 即一致),不依赖发奖公式:
|
||||
3 条 coin=0(一致) + 2 条 coin=7(不一致) → 全量 total=5、mismatch=2。
|
||||
"""
|
||||
from app.models.ad_reward import AdRewardRecord
|
||||
|
||||
d = "2020-01-15" # 固定历史日 + 独立 user,隔离其它用例数据
|
||||
db = SessionLocal()
|
||||
try:
|
||||
uid = user_repo.upsert_user_for_login(db, phone="13800009999", register_channel="sms").id
|
||||
for i in range(3):
|
||||
db.add(AdRewardRecord(
|
||||
trans_id=f"adaudit-ok-{i}", user_id=uid, coin=0, status="capped",
|
||||
reward_scene="reward_video", reward_date=d,
|
||||
))
|
||||
for i in range(2):
|
||||
db.add(AdRewardRecord(
|
||||
trans_id=f"adaudit-bad-{i}", user_id=uid, coin=7, status="capped",
|
||||
reward_scene="reward_video", reward_date=d,
|
||||
))
|
||||
db.commit()
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
base = {"date": d, "user_id": uid}
|
||||
|
||||
# 全量:total=5、mismatch=2、不截断、返回 5 条
|
||||
body = admin_client.get(
|
||||
"/admin/api/ad-coin-audit", params={**base, "limit": 100}, headers=_auth(admin_token)
|
||||
).json()
|
||||
assert body["total"] == 5
|
||||
assert body["mismatch_count"] == 2
|
||||
assert body["truncated"] is False
|
||||
assert len(body["items"]) == 5
|
||||
|
||||
# 截断:limit=2 → 统计仍全量、truncated=True、只回 2 条
|
||||
body = admin_client.get(
|
||||
"/admin/api/ad-coin-audit", params={**base, "limit": 2}, headers=_auth(admin_token)
|
||||
).json()
|
||||
assert body["total"] == 5 and body["mismatch_count"] == 2
|
||||
assert body["truncated"] is True
|
||||
assert len(body["items"]) == 2
|
||||
|
||||
# only_mismatch:只回 ✗ 行(2 条),统计仍全量、不截断
|
||||
body = admin_client.get(
|
||||
"/admin/api/ad-coin-audit",
|
||||
params={**base, "limit": 100, "only_mismatch": True},
|
||||
headers=_auth(admin_token),
|
||||
).json()
|
||||
assert body["total"] == 5 and body["mismatch_count"] == 2
|
||||
assert body["truncated"] is False
|
||||
assert len(body["items"]) == 2
|
||||
assert all(it["matched"] is False for it in body["items"])
|
||||
|
||||
|
||||
def test_read_apis_require_auth(admin_client: TestClient) -> None:
|
||||
"""所有 M2 读接口未带 token → 401(router 级 get_current_admin 守卫)。"""
|
||||
for path in [
|
||||
|
||||
Reference in New Issue
Block a user