feat(douyu): 支持批量导出用户名
This commit is contained in:
@@ -9,6 +9,7 @@ from web.backend.schemas import (
|
||||
DouyuCollabAccountLookupOut,
|
||||
DouyuCollabCkExportOut,
|
||||
DouyuCollabOrderOut,
|
||||
DouyuCollabUsernameExportOut,
|
||||
)
|
||||
from web.backend.services import douyu_collab_service as collab
|
||||
|
||||
@@ -501,6 +502,62 @@ class TestDouyuCollabOrders:
|
||||
collab_api.copy_external_order_ck(order.id, self.session, operator)
|
||||
assert excinfo.value.status_code == 403
|
||||
|
||||
def test_export_usernames_dedupes_and_skips_empty(self):
|
||||
first = collab.create_order(
|
||||
self.session,
|
||||
self.admin,
|
||||
order_no="DY-USER-1",
|
||||
account_username="douyu-account-a",
|
||||
draft=True,
|
||||
)
|
||||
second = collab.create_order(
|
||||
self.session,
|
||||
self.admin,
|
||||
order_no="DY-USER-2",
|
||||
account_username="douyu-account-a",
|
||||
draft=True,
|
||||
)
|
||||
blank = collab.create_order(
|
||||
self.session,
|
||||
self.admin,
|
||||
order_no="DY-USER-3",
|
||||
draft=True,
|
||||
)
|
||||
|
||||
result = collab.export_usernames(
|
||||
self.session,
|
||||
[first.id, second.id, blank.id],
|
||||
)
|
||||
|
||||
assert result["total"] == 3
|
||||
assert result["exported"] == 2
|
||||
assert result["unique"] == 1
|
||||
assert result["usernames"] == ["douyu-account-a"]
|
||||
assert [item["order_no"] for item in result["items"]] == [
|
||||
"DY-USER-1",
|
||||
"DY-USER-2",
|
||||
]
|
||||
assert result["skipped"] == [
|
||||
{
|
||||
"id": blank.id,
|
||||
"order_no": "DY-USER-3",
|
||||
"reason": "这单还没填斗鱼用户名",
|
||||
}
|
||||
]
|
||||
DouyuCollabUsernameExportOut.model_validate(result)
|
||||
|
||||
def test_export_usernames_rejects_empty_and_too_many(self):
|
||||
with pytest.raises(collab.CollabError) as excinfo:
|
||||
collab.export_usernames(self.session, [])
|
||||
assert excinfo.value.code == "username_export_empty"
|
||||
|
||||
with pytest.raises(collab.CollabError) as excinfo:
|
||||
collab.export_usernames(
|
||||
self.session,
|
||||
list(range(1, collab.USERNAME_EXPORT_BATCH_MAX + 2)),
|
||||
)
|
||||
assert excinfo.value.code == "username_export_too_large"
|
||||
|
||||
def test_ck_export_permission_defaults_to_operation(self):
|
||||
from web.backend.permissions import ROLE_PERMISSIONS
|
||||
|
||||
@@ -519,6 +576,7 @@ class TestDouyuCollabOrders:
|
||||
assert "/api/douyu/external-orders/accounts/lookup" in paths
|
||||
assert "/api/douyu/external-orders/ck/export" in paths
|
||||
assert "/api/douyu/external-orders/{order_id}/ck/copy" in paths
|
||||
assert "/api/douyu/external-orders/usernames/export" in paths
|
||||
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}"]
|
||||
|
||||
Reference in New Issue
Block a user