Add SmartUp account pool parameter configuration
This commit is contained in:
@@ -233,6 +233,94 @@ def test_set_website_accounts_concurrency_fallback(db_session, monkeypatch):
|
||||
assert closed_count == 1
|
||||
|
||||
|
||||
def test_set_website_accounts_concurrency_pool_mode_merges_credentials(db_session, monkeypatch):
|
||||
w = Website(
|
||||
id=1,
|
||||
name="Sub2Api site",
|
||||
site_type="sub2api",
|
||||
base_url="http://sub2api",
|
||||
api_prefix="api/v1",
|
||||
auth_type="bearer",
|
||||
auth_config_json='{"token": "tok1"}'
|
||||
)
|
||||
db_session.add(w)
|
||||
|
||||
up = Upstream(id=10, name="Upstream A", base_url="http://upstream-a")
|
||||
db_session.add(up)
|
||||
db_session.commit()
|
||||
|
||||
k1 = UpstreamGeneratedKey(
|
||||
id=101,
|
||||
upstream_id=up.id,
|
||||
group_id="g1",
|
||||
key_name="key-101",
|
||||
key_value="val-101",
|
||||
status="active",
|
||||
imported_website_id=w.id,
|
||||
imported_account_id="1001",
|
||||
)
|
||||
db_session.add(k1)
|
||||
db_session.commit()
|
||||
|
||||
bulk_calls = []
|
||||
update_calls = []
|
||||
|
||||
class MockClient:
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc, tb):
|
||||
return False
|
||||
|
||||
def list_accounts(self):
|
||||
return [{
|
||||
"id": 1001,
|
||||
"name": "acc-1001",
|
||||
"concurrency": 10,
|
||||
"credentials": {
|
||||
"base_url": "https://relay.example.com",
|
||||
"api_key": "sk-old",
|
||||
"pool_mode": False,
|
||||
},
|
||||
}]
|
||||
|
||||
def extract_id(self, val):
|
||||
return str(val.get("id"))
|
||||
|
||||
def bulk_update_accounts(self, account_ids, body):
|
||||
bulk_calls.append((account_ids, body))
|
||||
|
||||
def update_account(self, account_id, body):
|
||||
update_calls.append((account_id, body))
|
||||
|
||||
monkeypatch.setattr("app.routers.websites._client", lambda row: MockClient())
|
||||
|
||||
req = SetConcurrencyRequest(
|
||||
concurrency=80,
|
||||
configure_pool_mode=True,
|
||||
pool_mode=True,
|
||||
pool_mode_retry_count=1,
|
||||
pool_mode_retry_status_codes=[529, 429, 999, 502, 429],
|
||||
)
|
||||
res = set_website_accounts_concurrency(wid=w.id, body=req, db=db_session)
|
||||
|
||||
assert res.success is True
|
||||
assert "设置账号参数执行完毕" in res.message
|
||||
assert bulk_calls == []
|
||||
assert update_calls == [("1001", {
|
||||
"concurrency": 80,
|
||||
"credentials": {
|
||||
"base_url": "https://relay.example.com",
|
||||
"api_key": "sk-old",
|
||||
"pool_mode": True,
|
||||
"pool_mode_retry_count": 1,
|
||||
"pool_mode_retry_status_codes": [429, 502, 529],
|
||||
},
|
||||
})]
|
||||
assert res.items[0].old_pool_mode is False
|
||||
assert res.items[0].target_pool_mode is True
|
||||
|
||||
|
||||
def test_set_website_accounts_concurrency_list_accounts_none(db_session, monkeypatch):
|
||||
w = Website(
|
||||
id=1,
|
||||
|
||||
Reference in New Issue
Block a user