From 3ed7f3f2df9f459917a008844ff758d561a90c0d Mon Sep 17 00:00:00 2001 From: Ron Klinkien Date: Wed, 30 Mar 2022 12:28:30 +0200 Subject: [PATCH] Display all trade info in buttons First step to fix tests for changed forcesell code --- freqtrade/rpc/telegram.py | 4 ++-- tests/rpc/test_rpc_telegram.py | 36 +++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index ac74232aa..b2448708a 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -919,7 +919,7 @@ class Telegram(RPCHandler): trades = [] for trade in statlist: - trades.append(f"{trade[0]} {trade[1]} {trade[3]}") + trades.append(f"{trade[0]} {trade[1]} {trade[2]} {trade[3]}") trade_buttons = [ InlineKeyboardButton(text=trade, callback_data=trade) for trade in trades] @@ -994,7 +994,7 @@ class Telegram(RPCHandler): buttons_aligned.append([InlineKeyboardButton(text='Cancel', callback_data='cancel')]) self._send_msg(msg="Which pair?", - keyboard=buttons_aligned) + keyboard=buttons_aligned) @authorized_only def _trades(self, update: Update, context: CallbackContext) -> None: diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index f53f48cc2..f99328c0f 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -1188,15 +1188,6 @@ def test_forcesell_handle_invalid(default_conf, update, mocker) -> None: assert msg_mock.call_count == 1 assert 'not running' in msg_mock.call_args_list[0][0][0] - # No argument - msg_mock.reset_mock() - freqtradebot.state = State.RUNNING - context = MagicMock() - context.args = [] - telegram._forcesell(update=update, context=context) - assert msg_mock.call_count == 1 - assert "You must specify a trade-id or 'all'." in msg_mock.call_args_list[0][0][0] - # Invalid argument msg_mock.reset_mock() freqtradebot.state = State.RUNNING @@ -1208,6 +1199,33 @@ def test_forcesell_handle_invalid(default_conf, update, mocker) -> None: assert 'invalid argument' in msg_mock.call_args_list[0][0][0] +def test_forcesell_no_tradeid(default_conf, update, mocker) -> None: + + fsell_mock = MagicMock(return_value=None) + mocker.patch('freqtrade.rpc.RPC._rpc_forcesell', fsell_mock) + + telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) + + patch_get_signal(freqtradebot) + + context = MagicMock() + context.args = [] + telegram._forcesell(update=update, context=context) + + assert fsell_mock.call_count == 0 + assert msg_mock.call_count == 1 + assert msg_mock.call_args_list[0][1]['msg'] == 'Which trade?' + # assert msg_mock.call_args_list[0][1]['callback_query_handler'] == 'forcesell' + keyboard = msg_mock.call_args_list[0][1]['keyboard'] + # One additional button - cancel + assert reduce(lambda acc, x: acc + len(x), keyboard, 0) == 5 + update = MagicMock() + update.callback_query = MagicMock() + update.callback_query.data = '1 XRP/USDT 1h 2.20% (1.20)' + telegram._forcsell_inline(update, None) + assert fsell_mock.call_count == 1 + + def test_forcebuy_handle(default_conf, update, mocker) -> None: mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0)