优化(账号分配): 增加换绑与CK分类及测试操作

This commit is contained in:
yml
2026-11-26 22:57:27 +08:00
parent d17c14b84f
commit e6c89d9f59
6 changed files with 484 additions and 11 deletions
+77
View File
@@ -226,6 +226,83 @@ class TestAssignablePool(_Base):
class TestAssignmentPools(_Base):
def test_default_rebind_ready_pool_requires_available_rebind_and_unexpired_ck(
self,
):
ready = self.make_account(
"pool-rebind-ready",
role_bind_status="bound",
role_change_available_at=self.now - timedelta(hours=1),
ck_expected_expires_at=self.now + timedelta(days=3),
)
expiring = self.make_account(
"pool-rebind-expiring-ck",
role_bind_status="bound",
role_change_available_at=self.now - timedelta(hours=1),
ck_expected_expires_at=self.now + timedelta(hours=8),
)
self.make_account(
"pool-rebind-cooldown",
role_bind_status="bound",
role_change_available_at=self.now + timedelta(days=2),
ck_expected_expires_at=self.now + timedelta(days=3),
)
self.make_account(
"pool-rebind-unbound",
role_bind_status="unbound",
ck_expected_expires_at=self.now + timedelta(days=3),
)
self.make_account(
"pool-rebind-expired-ck",
role_bind_status="bound",
role_change_available_at=self.now - timedelta(hours=1),
ck_expected_expires_at=self.now - timedelta(hours=1),
)
result = list_accounts(
assign_status="unassigned",
assignable_only=True,
occupancy="free",
bind_change_status="available",
ck_expiry_status="not_expired",
page=1,
page_size=50,
include_sensitive=False,
db=self.session,
current=self.admin,
)
items = {item.username: item for item in result["items"]}
assert set(items) == {ready.username, expiring.username}
assert items[ready.username].bind_change_status == "available"
assert items[ready.username].bind_change_label == "可换绑"
assert items[ready.username].ck_expiry_status == "valid"
assert items[expiring.username].ck_expiry_status == "expiring"
assert items[expiring.username].ck_expiry_label == "24 小时内到期"
def test_rebind_and_ck_category_filters_can_be_used_independently(self):
cooling = self.make_account(
"pool-only-cooling",
role_bind_status="bound",
role_change_available_at=self.now + timedelta(days=2),
ck_expected_expires_at=self.now + timedelta(days=3),
)
expired = self.make_account(
"pool-only-expired",
role_bind_status="bound",
role_change_available_at=self.now - timedelta(hours=1),
ck_expected_expires_at=self.now - timedelta(hours=1),
)
invalid = self.make_account(
"pool-only-invalid",
ck_check_status="invalid",
ck_expected_expires_at=self.now - timedelta(days=1),
)
assert self.names(bind_change_status="cooldown") == [cooling.username]
assert self.names(ck_expiry_status="expired") == [expired.username]
assert self.names(ck_expiry_status="invalid") == [invalid.username]
def test_occupancy_filter_excludes_lease_and_collab(self):
free = self.make_account("pool-free")
leased = self.make_account("pool-leased")