fix(douyu): coordinate collab and platform account leases
Avoid automatic allocation of accounts with active external collaboration, require explicit manual takeover of platform leases, and add Douyu account identity search.
This commit is contained in:
@@ -276,6 +276,20 @@ class TestSyncAndMapping(_Base):
|
||||
assert listed["pagination"]["total"] == 1
|
||||
assert legacy.id != mapped.id
|
||||
|
||||
def test_list_searches_assigned_douyu_account_identity(self):
|
||||
task = self.task()
|
||||
account = self.account("douyu-search-account")
|
||||
account.nickname = "斗鱼昵称-搜索"
|
||||
account.uid = "90000123"
|
||||
task.account_id = account.id
|
||||
self.session.commit()
|
||||
|
||||
for keyword in ("douyu-search-account", "斗鱼昵称-搜索", "90000123"):
|
||||
listed = service.list_tasks(self.session, keyword=keyword)
|
||||
assert listed["pagination"]["total"] == 1
|
||||
assert listed["items"][0]["id"] == task.id
|
||||
assert listed["items"][0]["account"]["id"] == account.id
|
||||
|
||||
def test_list_hides_tasks_paid_before_order_match_cutoff(self):
|
||||
mapping = self.mapping()
|
||||
task = PlatformFulfillmentTask(
|
||||
@@ -1151,6 +1165,88 @@ class TestAccountSelection(_Base):
|
||||
|
||||
assert [row.username for row in candidates] == ["small", "large"]
|
||||
|
||||
def test_active_collab_order_blocks_all_automatic_candidate_pools(self):
|
||||
account = self.account("active-collab-candidate", points=2000)
|
||||
self.session.add(
|
||||
AccountCommodityState(
|
||||
account_id=account.id,
|
||||
platform="douyu",
|
||||
scope="elite",
|
||||
commodity_id=COMMODITY,
|
||||
commodity_name=INTERNAL_SKU,
|
||||
availability="available",
|
||||
observed_at=NOW,
|
||||
valid_until=NOW + timedelta(hours=1),
|
||||
)
|
||||
)
|
||||
order = DouyuExternalOrder(
|
||||
order_no="DY-ACTIVE-CANDIDATE",
|
||||
account_id=account.id,
|
||||
account_username=account.username,
|
||||
status=collab.STATUS_TO_RECHARGE,
|
||||
owner_id=self.admin.id,
|
||||
created_by=self.admin.id,
|
||||
)
|
||||
self.session.add(order)
|
||||
self.session.commit()
|
||||
|
||||
assert (
|
||||
account_selector.eligible_accounts(
|
||||
self.session,
|
||||
commodity_id=COMMODITY,
|
||||
required_points=1280,
|
||||
now=NOW,
|
||||
)
|
||||
== []
|
||||
)
|
||||
assert (
|
||||
account_selector.live_candidate_accounts(
|
||||
self.session,
|
||||
required_points=1280,
|
||||
commodity_id=COMMODITY,
|
||||
)
|
||||
== []
|
||||
)
|
||||
assert (
|
||||
account_selector.capability_candidate_accounts(
|
||||
self.session,
|
||||
commodity_id=COMMODITY,
|
||||
required_points=1280,
|
||||
now=NOW,
|
||||
)
|
||||
== []
|
||||
)
|
||||
|
||||
order.status = collab.STATUS_DONE
|
||||
self.session.commit()
|
||||
|
||||
assert [
|
||||
row.account_id
|
||||
for row in account_selector.eligible_accounts(
|
||||
self.session,
|
||||
commodity_id=COMMODITY,
|
||||
required_points=1280,
|
||||
now=NOW,
|
||||
)
|
||||
] == [account.id]
|
||||
assert [
|
||||
row.id
|
||||
for row in account_selector.live_candidate_accounts(
|
||||
self.session,
|
||||
required_points=1280,
|
||||
commodity_id=COMMODITY,
|
||||
)
|
||||
] == [account.id]
|
||||
assert [
|
||||
row.id
|
||||
for row in account_selector.capability_candidate_accounts(
|
||||
self.session,
|
||||
commodity_id=COMMODITY,
|
||||
required_points=1280,
|
||||
now=NOW,
|
||||
)
|
||||
] == [account.id]
|
||||
|
||||
def test_lease_is_unique_per_account(self):
|
||||
account = self.account("leased")
|
||||
candidate = account_selector.eligible_accounts(
|
||||
|
||||
Reference in New Issue
Block a user