优化(账号自动化): 履约保护登录配额与重登优先级
This commit is contained in:
@@ -4,7 +4,14 @@ from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from web.backend.models import Account, LoginAttempt, LoginQuotaSetting
|
||||
from web.backend.models import (
|
||||
Account,
|
||||
AutomationJob,
|
||||
LoginAttempt,
|
||||
LoginQuotaSetting,
|
||||
PlatformFulfillmentTask,
|
||||
)
|
||||
from web.backend.services.automation.jobs import ck_health
|
||||
from web.backend.services.login_budget_recommendation import recommend_login_budget
|
||||
|
||||
|
||||
@@ -121,3 +128,46 @@ def test_email_quota_failures_do_not_lower_success_rate(db):
|
||||
|
||||
assert recommendation["basis"]["recent_sample"] == 10
|
||||
assert recommendation["basis"]["recent_success_rate"] == 100.0
|
||||
|
||||
|
||||
def test_protected_inventory_is_allocated_once_within_daily_budget(db):
|
||||
now = datetime.now(UTC)
|
||||
protected = _account("budget-protected-valid")
|
||||
db.add(protected)
|
||||
db.flush()
|
||||
db.add_all(
|
||||
[
|
||||
PlatformFulfillmentTask(
|
||||
source_order_id="budget-protected-order",
|
||||
source_order_item_id="budget-protected-item",
|
||||
sale_mode="presale",
|
||||
account_id=protected.id,
|
||||
binding_status="bound",
|
||||
execution_status="bound",
|
||||
),
|
||||
AutomationJob(
|
||||
key=ck_health.JOB_KEY,
|
||||
interval_seconds=6 * 3600,
|
||||
batch_size=200,
|
||||
concurrency=3,
|
||||
),
|
||||
]
|
||||
)
|
||||
db.commit()
|
||||
|
||||
recommendation = recommend_login_budget(db, now=now)
|
||||
recommended = recommendation["recommended"]
|
||||
allocated = (
|
||||
recommended["relogin_protected_daily_limit"]
|
||||
+ recommended["lease_refresh_daily_limit"]
|
||||
+ recommended["relogin_high_value_daily_limit"]
|
||||
+ recommended["relogin_ordinary_daily_limit"]
|
||||
+ recommended["onboarding_daily_limit"]
|
||||
+ recommended["manual_daily_limit"]
|
||||
)
|
||||
|
||||
assert recommendation["basis"]["protected_valid_accounts"] == 1
|
||||
assert recommendation["basis"]["protected_invalid_backlog"] == 0
|
||||
assert recommended["relogin_protected_daily_limit"] >= 50
|
||||
assert recommended["lease_refresh_daily_limit"] >= 50
|
||||
assert allocated <= recommended["daily_attempt_limit"]
|
||||
|
||||
Reference in New Issue
Block a user