feat(douyu): 增加协作单礼包字典与权限控制
This commit is contained in:
@@ -127,6 +127,134 @@ class TestDouyuCollabOrders:
|
||||
assert order.status == collab.STATUS_TO_RECHARGE
|
||||
DouyuCollabOrderOut.model_validate(collab.serialize_one(self.session, order))
|
||||
|
||||
def test_manual_gift_without_goods_snapshot_keeps_name_and_points(self):
|
||||
order = collab.create_order(
|
||||
self.session,
|
||||
self.admin,
|
||||
order_no="DY-MANUAL-001",
|
||||
shop="店铺A",
|
||||
account_username="douyu-account-a",
|
||||
gift_name="套装-暗影哥特",
|
||||
required_points=888,
|
||||
home_images=["collab/home-manual.png"],
|
||||
client=FakeClient(),
|
||||
)
|
||||
assert order.gift_name == "套装-暗影哥特"
|
||||
assert order.commodity_id == ""
|
||||
assert order.required_points == 888
|
||||
assert order.status == collab.STATUS_TO_RECHARGE
|
||||
|
||||
collab.update_order(
|
||||
self.session,
|
||||
self.admin,
|
||||
order,
|
||||
{
|
||||
"gift_name": "套装-暗影哥特",
|
||||
"commodity_id": "",
|
||||
"required_points": 888,
|
||||
"remark": "接口未返回商品,手动填写",
|
||||
},
|
||||
expected_version=order.version,
|
||||
)
|
||||
payload = collab.serialize_one(self.session, order)
|
||||
assert payload["gift_name"] == "套装-暗影哥特"
|
||||
assert payload["commodity_id"] == ""
|
||||
assert payload["required_points"] == 888
|
||||
DouyuCollabOrderOut.model_validate(payload)
|
||||
|
||||
def test_gift_catalog_crud_rename_cascades_and_delete_guard(self):
|
||||
gift = collab.create_gift(
|
||||
self.session,
|
||||
self.admin,
|
||||
name="套装-暗影哥特",
|
||||
points=888,
|
||||
remark="接口未返回商品",
|
||||
)
|
||||
assert gift.points == 888
|
||||
with pytest.raises(collab.CollabError) as duplicated:
|
||||
collab.create_gift(
|
||||
self.session,
|
||||
self.admin,
|
||||
name="套装-暗影哥特",
|
||||
points=900,
|
||||
)
|
||||
assert duplicated.value.code == "gift_exists"
|
||||
|
||||
order = collab.create_order(
|
||||
self.session,
|
||||
self.admin,
|
||||
order_no="DY-GIFT-001",
|
||||
shop="店铺A",
|
||||
account_username="douyu-account-a",
|
||||
gift_name=gift.name,
|
||||
required_points=None,
|
||||
home_images=["collab/home-gift.png"],
|
||||
client=FakeClient(),
|
||||
)
|
||||
assert order.gift_name == "套装-暗影哥特"
|
||||
assert order.commodity_id == ""
|
||||
assert order.required_points == 888
|
||||
|
||||
collab.update_gift(
|
||||
self.session,
|
||||
self.admin,
|
||||
gift,
|
||||
{"name": "套装-暗影哥特-返场", "points": 999},
|
||||
)
|
||||
self.session.refresh(order)
|
||||
assert order.gift_name == "套装-暗影哥特-返场"
|
||||
assert order.required_points == 888
|
||||
|
||||
with pytest.raises(collab.CollabError) as in_use:
|
||||
collab.delete_gift(self.session, self.admin, gift)
|
||||
assert in_use.value.code == "gift_in_use"
|
||||
|
||||
spare = collab.create_gift(
|
||||
self.session,
|
||||
self.admin,
|
||||
name="套装-星河流浪者",
|
||||
points=1680,
|
||||
)
|
||||
assert [
|
||||
row.name for row in collab.list_gifts(self.session, active_only=True)
|
||||
] == [
|
||||
"套装-暗影哥特-返场",
|
||||
"套装-星河流浪者",
|
||||
]
|
||||
collab.delete_gift(self.session, self.admin, spare)
|
||||
assert [row.name for row in collab.list_gifts(self.session)] == [
|
||||
"套装-暗影哥特-返场"
|
||||
]
|
||||
|
||||
collab.create_gift(
|
||||
self.session,
|
||||
self.admin,
|
||||
name="礼包A",
|
||||
points=999,
|
||||
)
|
||||
api_order = collab.create_order(
|
||||
self.session,
|
||||
self.admin,
|
||||
order_no="DY-GIFT-API-001",
|
||||
shop="店铺A",
|
||||
account_username="douyu-account-a",
|
||||
gift_name="礼包A",
|
||||
required_points=None,
|
||||
home_images=["collab/home-gift-api.png"],
|
||||
client=FakeClient(),
|
||||
)
|
||||
# 接口恢复返回商品后以接口积分为准,字典只做兜底。
|
||||
assert api_order.required_points == 100
|
||||
assert api_order.commodity_id == "gift-a"
|
||||
|
||||
def test_gift_catalog_write_requires_manage_permission(self):
|
||||
from web.backend.permissions import get_role_permissions
|
||||
|
||||
support = get_role_permissions("support")
|
||||
assert "douyu:collab:view" in support
|
||||
assert "douyu:collab:manage" not in support
|
||||
assert "douyu:collab:manage" in get_role_permissions("operation")
|
||||
|
||||
def test_same_account_allows_multiple_orders(self):
|
||||
collab.create_order(
|
||||
self.session,
|
||||
@@ -680,3 +808,9 @@ class TestDouyuCollabOrders:
|
||||
assert "/api/douyu/collab-shops/{shop_id}" in paths
|
||||
assert "put" in paths["/api/douyu/collab-shops/{shop_id}"]
|
||||
assert "delete" in paths["/api/douyu/collab-shops/{shop_id}"]
|
||||
assert "/api/douyu/collab-gifts" in paths
|
||||
assert "get" in paths["/api/douyu/collab-gifts"]
|
||||
assert "post" in paths["/api/douyu/collab-gifts"]
|
||||
assert "/api/douyu/collab-gifts/{gift_id}" in paths
|
||||
assert "put" in paths["/api/douyu/collab-gifts/{gift_id}"]
|
||||
assert "delete" in paths["/api/douyu/collab-gifts/{gift_id}"]
|
||||
|
||||
@@ -26,7 +26,7 @@ TESTS_DIR = Path(__file__).resolve().parent
|
||||
PROJECT_ROOT = TESTS_DIR.parent
|
||||
VERSIONS_DIR = PROJECT_ROOT / "web" / "backend" / "migrations" / "versions"
|
||||
|
||||
HEAD_REVISION = "20261106_0065"
|
||||
HEAD_REVISION = "20261106_0066"
|
||||
|
||||
# 迁移新增、但不声明在模型里的复合查询索引。
|
||||
EXTRA_INDEXES = (
|
||||
|
||||
Reference in New Issue
Block a user