feat(douyu): 增加账号供给看板与阈值告警
This commit is contained in:
@@ -19,6 +19,7 @@ from web.backend.services.account_observability import account_platform_status
|
||||
from web.backend.services.account_supply_service import (
|
||||
VALUE_HIGH,
|
||||
enqueue_supply_replenishment,
|
||||
ensure_default_supply_targets,
|
||||
evaluate_supply_target,
|
||||
upsert_supply_target,
|
||||
)
|
||||
@@ -165,6 +166,29 @@ def test_supply_target_configuration_is_idempotent(db):
|
||||
assert second.enabled is False
|
||||
|
||||
|
||||
def test_default_supply_targets_are_seeded_once(db, monkeypatch):
|
||||
monkeypatch.setenv("DOUYU_DEFAULT_SUPPLY_TARGETS_ENABLED", "true")
|
||||
|
||||
assert ensure_default_supply_targets(db) == 2
|
||||
assert ensure_default_supply_targets(db) == 0
|
||||
|
||||
targets = (
|
||||
db.query(AccountSupplyTarget)
|
||||
.order_by(AccountSupplyTarget.value_class.asc())
|
||||
.all()
|
||||
)
|
||||
assert [row.value_class for row in targets] == ["high_value", "ordinary"]
|
||||
assert all(row.scope == "elite" for row in targets)
|
||||
assert all(row.enabled for row in targets)
|
||||
|
||||
|
||||
def test_default_supply_targets_can_be_disabled(db, monkeypatch):
|
||||
monkeypatch.setenv("DOUYU_DEFAULT_SUPPLY_TARGETS_ENABLED", "false")
|
||||
|
||||
assert ensure_default_supply_targets(db) == 0
|
||||
assert db.query(AccountSupplyTarget).count() == 0
|
||||
|
||||
|
||||
def test_supply_target_configuration_route_returns_inventory(db):
|
||||
user = User(
|
||||
username="supply-config-admin",
|
||||
@@ -238,3 +262,7 @@ def test_account_platform_status_aggregates_queue_sync_and_supply(db):
|
||||
assert status["sync_domains"]["storehome"]["fresh"] == 1
|
||||
assert status["commodities"]["fresh_available"] == 1
|
||||
assert status["supply_targets"][0]["covered_shortage"] == 1
|
||||
assert status["supply_targets"][0]["target_available"] == 2
|
||||
assert {
|
||||
alert["code"] for alert in status["alerts"]
|
||||
} >= {"supply_shortage", "ck_expiring_24h"}
|
||||
|
||||
Reference in New Issue
Block a user