|
|
@@ -293,3 +293,60 @@ def test_capture_account_balance_snapshot_uses_crypto_price(temp_db, monkeypatch
|
|
|
|
|
|
stored = json.loads(row["snapshot_json"])
|
|
|
assert stored["balances"][0]["price_usd"] == 1.4109
|
|
|
+
|
|
|
+
|
|
|
+def test_get_account_info_stays_available_when_crypto_price_is_unavailable(temp_db, monkeypatch):
|
|
|
+ account_id = _create_account()
|
|
|
+
|
|
|
+ monkeypatch.setattr(
|
|
|
+ services_bitstamp,
|
|
|
+ "fetch_account_balance",
|
|
|
+ lambda _account_id: {
|
|
|
+ "source": "bitstamp",
|
|
|
+ "cached": False,
|
|
|
+ "balances": [
|
|
|
+ {
|
|
|
+ "account_id": _account_id,
|
|
|
+ "asset_code": "XRP",
|
|
|
+ "available": 1.5,
|
|
|
+ "reserved": 0.5,
|
|
|
+ "total": 2.0,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "account_id": _account_id,
|
|
|
+ "asset_code": "USD",
|
|
|
+ "available": 10.0,
|
|
|
+ "reserved": 5.0,
|
|
|
+ "total": 15.0,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ "payload": [],
|
|
|
+ },
|
|
|
+ )
|
|
|
+ monkeypatch.setattr(services_bitstamp, "get_crypto_price", lambda symbol: {"error": "TIMEOUT", "symbol": symbol})
|
|
|
+
|
|
|
+ result = services_bitstamp.fetch_account_info(account_id)
|
|
|
+
|
|
|
+ assert result["id"] == account_id
|
|
|
+ assert result["total_value_usd"] == 15.0
|
|
|
+ assert result["balances"][0]["asset_code"] == "XRP"
|
|
|
+ assert result["balances"][0]["price_usd"] is None
|
|
|
+ assert result["balances"][0]["value_usd"] is None
|
|
|
+ assert result["balances"][1]["asset_code"] == "USD"
|
|
|
+ assert result["balances"][1]["price_usd"] == 1.0
|
|
|
+ assert result["balances"][1]["value_usd"] == 15.0
|
|
|
+
|
|
|
+
|
|
|
+def test_get_account_info_falls_back_when_balance_fetch_fails(temp_db, monkeypatch):
|
|
|
+ account_id = _create_account()
|
|
|
+
|
|
|
+ monkeypatch.setattr(services_bitstamp, "fetch_account_balance", lambda _account_id: (_ for _ in ()).throw(RuntimeError("bitstamp unavailable")))
|
|
|
+ monkeypatch.setattr(services_bitstamp, "get_crypto_price", lambda symbol: {"symbol": symbol.upper(), "price": 1.4109, "timestamp": 1779039021})
|
|
|
+
|
|
|
+ result = services_bitstamp.fetch_account_info(account_id)
|
|
|
+
|
|
|
+ assert result["id"] == account_id
|
|
|
+ assert result["balances"] == []
|
|
|
+ assert result["total_value_usd"] == 0.0
|
|
|
+ assert result["raw_balance"] is None
|
|
|
+ assert "balance_error" in result
|