Add test case for interactive telegram exit

This commit is contained in:
Matthias 2022-04-09 09:41:01 +02:00
parent 9cd92ed48c
commit ddfc68d533
2 changed files with 51 additions and 3 deletions

View File

@ -975,7 +975,7 @@ class Telegram(RPCHandler):
trade_id = query.data.split("__")[1].split(' ')[0]
if trade_id == 'cancel':
query.answer()
query.edit_message_text(text="Forcesell canceled")
query.edit_message_text(text="Force exit canceled.")
return
trade: Trade = Trade.get_trades(trade_filter=Trade.id == trade_id).first()
query.answer()

View File

@ -1067,8 +1067,8 @@ def test_telegram_forcesell_handle(default_conf, update, ticker, fee,
} == last_msg
def test_telegram_forcesell_down_handle(default_conf, update, ticker, fee,
ticker_sell_down, mocker) -> None:
def test_telegram_force_exit_down_handle(default_conf, update, ticker, fee,
ticker_sell_down, mocker) -> None:
mocker.patch('freqtrade.rpc.fiat_convert.CryptoToFiatConverter._find_price',
return_value=15000.0)
msg_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.send_msg', MagicMock())
@ -1222,6 +1222,54 @@ def test_forcesell_handle_invalid(default_conf, update, mocker) -> None:
assert 'invalid argument' in msg_mock.call_args_list[0][0][0]
def test_force_exit_no_pair(default_conf, update, ticker, fee, mocker) -> None:
default_conf['max_open_trades'] = 4
mocker.patch.multiple(
'freqtrade.exchange.Exchange',
fetch_ticker=ticker,
get_fee=fee,
_is_dry_limit_order_filled=MagicMock(return_value=True),
)
femock = mocker.patch('freqtrade.rpc.rpc.RPC._rpc_force_exit')
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot)
# Create some test data
freqtradebot.enter_positions()
msg_mock.reset_mock()
# /forcesell all
context = MagicMock()
context.args = []
telegram._force_exit(update=update, context=context)
keyboard = msg_mock.call_args_list[0][1]['keyboard']
# 4 pairs + cancel
assert reduce(lambda acc, x: acc + len(x), keyboard, 0) == 5
assert keyboard[-1][0].text == "Cancel"
assert keyboard[1][0].callback_data == 'force_exit__2 L'
update = MagicMock()
update.callback_query = MagicMock()
update.callback_query.data = keyboard[1][0].callback_data
telegram._force_exit_inline(update, None)
assert update.callback_query.answer.call_count == 1
assert update.callback_query.edit_message_text.call_count == 1
assert femock.call_count == 1
assert femock.call_args_list[0][0][0] == '2'
# Retry selling - but cancel instead
update.callback_query.reset_mock()
telegram._force_exit(update=update, context=context)
# Use cancel button
update.callback_query.data = keyboard[-1][0].callback_data
telegram._force_exit_inline(update, None)
query = update.callback_query
assert query.answer.call_count == 1
assert query.edit_message_text.call_count == 1
assert query.edit_message_text.call_args_list[-1][1]['text'] == "Force exit canceled."
def test_force_enter_handle(default_conf, update, mocker) -> None:
mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0)