Enhance Selectel balance handling and error messaging in GPU rental system
- Updated Selectel documentation to clarify error responses related to balance issues. - Introduced `peek_balance_rub` function for best-effort balance checks, handling API failures gracefully. - Improved error messages for insufficient funds and quota issues, specifying Selectel's 403 policy response. - Added balance checks in the doctor command to ensure users are informed about their balance status before attempting GPU creation. - Refactored exception handling in cloud operations to provide clearer feedback on balance-related errors. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
from gpu_rent.balance import (
|
||||
BalanceWatchState,
|
||||
balance_rub_from_payload,
|
||||
peek_balance_rub,
|
||||
plan_balance_notices,
|
||||
spend_steps,
|
||||
)
|
||||
from gpu_rent.errors import CloudError
|
||||
|
||||
|
||||
def test_balance_kopecks():
|
||||
@@ -54,3 +56,17 @@ def test_plan_low_once():
|
||||
assert any("низкий" in m for m in msgs)
|
||||
state, msgs2 = plan_balance_notices(state, 100.0, step_rub=200.0, low_rub=200.0)
|
||||
assert not any("низкий" in m for m in msgs2)
|
||||
|
||||
|
||||
def test_peek_balance_rub_empty_token():
|
||||
assert peek_balance_rub("") is None
|
||||
assert peek_balance_rub(None) is None
|
||||
|
||||
|
||||
def test_peek_balance_rub_swallows_errors(monkeypatch):
|
||||
def boom(*_a, **_k):
|
||||
raise CloudError("сеть")
|
||||
|
||||
monkeypatch.setattr("gpu_rent.balance.fetch_balance_rub", boom)
|
||||
assert peek_balance_rub("tok") is None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user