Merge remote-tracking branch 'origin/main' into main
This commit is contained in:
@@ -15,7 +15,10 @@ class CLITestCase(unittest.TestCase):
|
||||
help_text = parser.format_help()
|
||||
self.assertIn("init", help_text)
|
||||
self.assertIn("account", help_text)
|
||||
self.assertIn("buy", help_text)
|
||||
self.assertIn("sell", help_text)
|
||||
self.assertIn("opportunity", help_text)
|
||||
self.assertIn("--doc", help_text)
|
||||
|
||||
def test_init_dispatches(self):
|
||||
captured = {}
|
||||
@@ -46,6 +49,48 @@ class CLITestCase(unittest.TestCase):
|
||||
self.assertEqual(result, 1)
|
||||
self.assertIn("error: boom", stderr.getvalue())
|
||||
|
||||
def test_buy_dispatches(self):
|
||||
captured = {}
|
||||
with patch.object(cli, "load_config", return_value={"binance": {"spot_base_url": "https://test", "recv_window": 5000}, "trading": {"dry_run_default": True}}), patch.object(
|
||||
cli, "get_binance_credentials", return_value={"api_key": "k", "api_secret": "s"}
|
||||
), patch.object(
|
||||
cli, "SpotBinanceClient"
|
||||
), patch.object(
|
||||
cli.trade_service, "execute_spot_trade", return_value={"trade": {"status": "DRY_RUN"}}
|
||||
), patch.object(
|
||||
cli, "print_output", side_effect=lambda payload, **kwargs: captured.setdefault("payload", payload)
|
||||
):
|
||||
result = cli.main(["buy", "BTCUSDT", "-Q", "100"])
|
||||
self.assertEqual(result, 0)
|
||||
self.assertEqual(captured["payload"]["trade"]["status"], "DRY_RUN")
|
||||
|
||||
def test_sell_dispatches(self):
|
||||
captured = {}
|
||||
with patch.object(cli, "load_config", return_value={"binance": {"spot_base_url": "https://test", "recv_window": 5000}, "trading": {"dry_run_default": True}}), patch.object(
|
||||
cli, "get_binance_credentials", return_value={"api_key": "k", "api_secret": "s"}
|
||||
), patch.object(
|
||||
cli, "SpotBinanceClient"
|
||||
), patch.object(
|
||||
cli.trade_service, "execute_spot_trade", return_value={"trade": {"status": "DRY_RUN"}}
|
||||
), patch.object(
|
||||
cli, "print_output", side_effect=lambda payload, **kwargs: captured.setdefault("payload", payload)
|
||||
):
|
||||
result = cli.main(["sell", "BTCUSDT", "-q", "0.01"])
|
||||
self.assertEqual(result, 0)
|
||||
self.assertEqual(captured["payload"]["trade"]["status"], "DRY_RUN")
|
||||
|
||||
def test_doc_flag_prints_documentation(self):
|
||||
import io
|
||||
from unittest.mock import patch
|
||||
|
||||
stdout = io.StringIO()
|
||||
with patch("sys.stdout", stdout):
|
||||
result = cli.main(["market", "tickers", "--doc"])
|
||||
self.assertEqual(result, 0)
|
||||
output = stdout.getvalue()
|
||||
self.assertIn("lastPrice", output)
|
||||
self.assertIn("BTCUSDT", output)
|
||||
|
||||
def test_upgrade_dispatches(self):
|
||||
captured = {}
|
||||
with (
|
||||
|
||||
Reference in New Issue
Block a user