Update a few tests ...

This commit is contained in:
Matthias
2023-04-15 14:15:38 +02:00
parent 914d7350fa
commit fb56889b43
2 changed files with 101 additions and 102 deletions

View File

@@ -177,7 +177,7 @@ class Telegram(RPCHandler):
self._loop = asyncio.get_running_loop() self._loop = asyncio.get_running_loop()
except RuntimeError: except RuntimeError:
self._loop = asyncio.new_event_loop() self._loop = asyncio.new_event_loop()
asyncio.set_event_loop(self._loop) asyncio.set_event_loop(self._loop)
self._app = Application.builder().token(self._config['telegram']['token']).build() self._app = Application.builder().token(self._config['telegram']['token']).build()

View File

@@ -8,7 +8,7 @@ from datetime import datetime, timedelta, timezone
from functools import reduce from functools import reduce
from random import choice, randint from random import choice, randint
from string import ascii_uppercase from string import ascii_uppercase
from unittest.mock import ANY, MagicMock from unittest.mock import ANY, AsyncMock, MagicMock
import arrow import arrow
import pytest import pytest
@@ -79,12 +79,13 @@ class DummyCls(Telegram):
def get_telegram_testobject(mocker, default_conf, mock=True, ftbot=None): def get_telegram_testobject(mocker, default_conf, mock=True, ftbot=None):
msg_mock = MagicMock() msg_mock = AsyncMock()
if mock: if mock:
mocker.patch.multiple( mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram', 'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(), _init=MagicMock(),
_send_msg=msg_mock _send_msg=msg_mock,
_start_thread=MagicMock(),
) )
if not ftbot: if not ftbot:
ftbot = get_patched_freqtradebot(mocker, default_conf) ftbot = get_patched_freqtradebot(mocker, default_conf)
@@ -95,7 +96,6 @@ def get_telegram_testobject(mocker, default_conf, mock=True, ftbot=None):
def test_telegram__init__(default_conf, mocker) -> None: def test_telegram__init__(default_conf, mocker) -> None:
mocker.patch('freqtrade.rpc.telegram.Updater', MagicMock())
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock()) mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
telegram, _, _ = get_telegram_testobject(mocker, default_conf) telegram, _, _ = get_telegram_testobject(mocker, default_conf)
@@ -192,7 +192,7 @@ def test_authorized_only_exception(default_conf, mocker, caplog, update) -> None
assert log_has('Exception occurred within Telegram module', caplog) assert log_has('Exception occurred within Telegram module', caplog)
def test_telegram_status(default_conf, update, mocker) -> None: async def test_telegram_status(default_conf, update, mocker) -> None:
default_conf['telegram']['enabled'] = False default_conf['telegram']['enabled'] = False
status_table = MagicMock() status_table = MagicMock()
@@ -238,18 +238,18 @@ def test_telegram_status(default_conf, update, mocker) -> None:
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf) telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
telegram._status(update=update, context=MagicMock()) await telegram._status(update=update, context=MagicMock())
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
context = MagicMock() context = MagicMock()
# /status table # /status table
context.args = ["table"] context.args = ["table"]
telegram._status(update=update, context=context) await telegram._status(update=update, context=context)
assert status_table.call_count == 1 assert status_table.call_count == 1
@pytest.mark.usefixtures("init_persistence") @pytest.mark.usefixtures("init_persistence")
def test_telegram_status_multi_entry(default_conf, update, mocker, fee) -> None: async def test_telegram_status_multi_entry(default_conf, update, mocker, fee) -> None:
default_conf['telegram']['enabled'] = False default_conf['telegram']['enabled'] = False
default_conf['position_adjustment_enable'] = True default_conf['position_adjustment_enable'] = True
mocker.patch.multiple( mocker.patch.multiple(
@@ -288,7 +288,7 @@ def test_telegram_status_multi_entry(default_conf, update, mocker, fee) -> None:
trade.recalc_trade_from_orders() trade.recalc_trade_from_orders()
Trade.commit() Trade.commit()
telegram._status(update=update, context=MagicMock()) await telegram._status(update=update, context=MagicMock())
assert msg_mock.call_count == 4 assert msg_mock.call_count == 4
msg = msg_mock.call_args_list[0][0][0] msg = msg_mock.call_args_list[0][0][0]
assert re.search(r'Number of Entries.*2', msg) assert re.search(r'Number of Entries.*2', msg)
@@ -300,8 +300,7 @@ def test_telegram_status_multi_entry(default_conf, update, mocker, fee) -> None:
@pytest.mark.usefixtures("init_persistence") @pytest.mark.usefixtures("init_persistence")
def test_telegram_status_closed_trade(default_conf, update, mocker, fee) -> None: async def test_telegram_status_closed_trade(default_conf, update, mocker, fee) -> None:
default_conf['telegram']['enabled'] = False
default_conf['position_adjustment_enable'] = True default_conf['position_adjustment_enable'] = True
mocker.patch.multiple( mocker.patch.multiple(
EXMS, EXMS,
@@ -315,7 +314,7 @@ def test_telegram_status_closed_trade(default_conf, update, mocker, fee) -> None
trade = Trade.get_trades([Trade.is_open.is_(False)]).first() trade = Trade.get_trades([Trade.is_open.is_(False)]).first()
context = MagicMock() context = MagicMock()
context.args = [str(trade.id)] context.args = [str(trade.id)]
telegram._status(update=update, context=context) await telegram._status(update=update, context=context)
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
msg = msg_mock.call_args_list[0][0][0] msg = msg_mock.call_args_list[0][0][0]
assert re.search(r'Close Date:', msg) assert re.search(r'Close Date:', msg)
@@ -749,7 +748,7 @@ def test_telegram_profit_handle(
@pytest.mark.parametrize('is_short', [True, False]) @pytest.mark.parametrize('is_short', [True, False])
def test_telegram_stats(default_conf, update, ticker, fee, mocker, is_short) -> None: async def test_telegram_stats(default_conf, update, ticker, fee, mocker, is_short) -> None:
mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0) mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0)
mocker.patch.multiple( mocker.patch.multiple(
EXMS, EXMS,
@@ -759,7 +758,7 @@ def test_telegram_stats(default_conf, update, ticker, fee, mocker, is_short) ->
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot) patch_get_signal(freqtradebot)
telegram._stats(update=update, context=MagicMock()) await telegram._stats(update=update, context=MagicMock())
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert 'No trades yet.' in msg_mock.call_args_list[0][0][0] assert 'No trades yet.' in msg_mock.call_args_list[0][0][0]
msg_mock.reset_mock() msg_mock.reset_mock()
@@ -767,7 +766,7 @@ def test_telegram_stats(default_conf, update, ticker, fee, mocker, is_short) ->
# Create some test data # Create some test data
create_mock_trades(fee, is_short=is_short) create_mock_trades(fee, is_short=is_short)
telegram._stats(update=update, context=MagicMock()) await telegram._stats(update=update, context=MagicMock())
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert 'Exit Reason' in msg_mock.call_args_list[-1][0][0] assert 'Exit Reason' in msg_mock.call_args_list[-1][0][0]
assert 'ROI' in msg_mock.call_args_list[-1][0][0] assert 'ROI' in msg_mock.call_args_list[-1][0][0]
@@ -775,7 +774,7 @@ def test_telegram_stats(default_conf, update, ticker, fee, mocker, is_short) ->
msg_mock.reset_mock() msg_mock.reset_mock()
def test_telegram_balance_handle(default_conf, update, mocker, rpc_balance, tickers) -> None: async def test_telegram_balance_handle(default_conf, update, mocker, rpc_balance, tickers) -> None:
default_conf['dry_run'] = False default_conf['dry_run'] = False
mocker.patch(f'{EXMS}.get_balances', return_value=rpc_balance) mocker.patch(f'{EXMS}.get_balances', return_value=rpc_balance)
mocker.patch(f'{EXMS}.get_tickers', tickers) mocker.patch(f'{EXMS}.get_tickers', tickers)
@@ -784,10 +783,10 @@ def test_telegram_balance_handle(default_conf, update, mocker, rpc_balance, tick
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot) patch_get_signal(freqtradebot)
telegram._balance(update=update, context=MagicMock()) await telegram._balance(update=update, context=MagicMock())
context = MagicMock() context = MagicMock()
context.args = ["full"] context.args = ["full"]
telegram._balance(update=update, context=context) await telegram._balance(update=update, context=context)
result = msg_mock.call_args_list[0][0][0] result = msg_mock.call_args_list[0][0][0]
result_full = msg_mock.call_args_list[1][0][0] result_full = msg_mock.call_args_list[1][0][0]
assert msg_mock.call_count == 2 assert msg_mock.call_count == 2
@@ -809,7 +808,7 @@ def test_telegram_balance_handle(default_conf, update, mocker, rpc_balance, tick
assert '*Estimated Value (Bot managed assets only)*:' in result assert '*Estimated Value (Bot managed assets only)*:' in result
def test_balance_handle_empty_response(default_conf, update, mocker) -> None: async def test_balance_handle_empty_response(default_conf, update, mocker) -> None:
default_conf['dry_run'] = False default_conf['dry_run'] = False
mocker.patch(f'{EXMS}.get_balances', return_value={}) mocker.patch(f'{EXMS}.get_balances', return_value={})
@@ -817,26 +816,26 @@ def test_balance_handle_empty_response(default_conf, update, mocker) -> None:
patch_get_signal(freqtradebot) patch_get_signal(freqtradebot)
freqtradebot.config['dry_run'] = False freqtradebot.config['dry_run'] = False
telegram._balance(update=update, context=MagicMock()) await telegram._balance(update=update, context=MagicMock())
result = msg_mock.call_args_list[0][0][0] result = msg_mock.call_args_list[0][0][0]
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert 'Starting capital: `0 BTC' in result assert 'Starting capital: `0 BTC' in result
def test_balance_handle_empty_response_dry(default_conf, update, mocker) -> None: async def test_balance_handle_empty_response_dry(default_conf, update, mocker) -> None:
mocker.patch(f'{EXMS}.get_balances', return_value={}) mocker.patch(f'{EXMS}.get_balances', return_value={})
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot) patch_get_signal(freqtradebot)
telegram._balance(update=update, context=MagicMock()) await telegram._balance(update=update, context=MagicMock())
result = msg_mock.call_args_list[0][0][0] result = msg_mock.call_args_list[0][0][0]
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert "*Warning:* Simulated balances in Dry Mode." in result assert "*Warning:* Simulated balances in Dry Mode." in result
assert "Starting capital: `1000 BTC`" in result assert "Starting capital: `1000 BTC`" in result
def test_balance_handle_too_large_response(default_conf, update, mocker) -> None: async def test_balance_handle_too_large_response(default_conf, update, mocker) -> None:
balances = [] balances = []
for i in range(100): for i in range(100):
curr = choice(ascii_uppercase) + choice(ascii_uppercase) + choice(ascii_uppercase) curr = choice(ascii_uppercase) + choice(ascii_uppercase) + choice(ascii_uppercase)
@@ -869,7 +868,7 @@ def test_balance_handle_too_large_response(default_conf, update, mocker) -> None
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot) patch_get_signal(freqtradebot)
telegram._balance(update=update, context=MagicMock()) await telegram._balance(update=update, context=MagicMock())
assert msg_mock.call_count > 1 assert msg_mock.call_count > 1
# Test if wrap happens around 4000 - # Test if wrap happens around 4000 -
# and each single currency-output is around 120 characters long so we need # and each single currency-output is around 120 characters long so we need
@@ -878,78 +877,78 @@ def test_balance_handle_too_large_response(default_conf, update, mocker) -> None
assert len(msg_mock.call_args_list[0][0][0]) > (4096 - 120) assert len(msg_mock.call_args_list[0][0][0]) > (4096 - 120)
def test_start_handle(default_conf, update, mocker) -> None: async def test_start_handle(default_conf, update, mocker) -> None:
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
freqtradebot.state = State.STOPPED freqtradebot.state = State.STOPPED
assert freqtradebot.state == State.STOPPED assert freqtradebot.state == State.STOPPED
telegram._start(update=update, context=MagicMock()) await telegram._start(update=update, context=MagicMock())
assert freqtradebot.state == State.RUNNING assert freqtradebot.state == State.RUNNING
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
def test_start_handle_already_running(default_conf, update, mocker) -> None: async def test_start_handle_already_running(default_conf, update, mocker) -> None:
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
freqtradebot.state = State.RUNNING freqtradebot.state = State.RUNNING
assert freqtradebot.state == State.RUNNING assert freqtradebot.state == State.RUNNING
telegram._start(update=update, context=MagicMock()) await telegram._start(update=update, context=MagicMock())
assert freqtradebot.state == State.RUNNING assert freqtradebot.state == State.RUNNING
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert 'already running' in msg_mock.call_args_list[0][0][0] assert 'already running' in msg_mock.call_args_list[0][0][0]
def test_stop_handle(default_conf, update, mocker) -> None: async def test_stop_handle(default_conf, update, mocker) -> None:
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
freqtradebot.state = State.RUNNING freqtradebot.state = State.RUNNING
assert freqtradebot.state == State.RUNNING assert freqtradebot.state == State.RUNNING
telegram._stop(update=update, context=MagicMock()) await telegram._stop(update=update, context=MagicMock())
assert freqtradebot.state == State.STOPPED assert freqtradebot.state == State.STOPPED
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert 'stopping trader' in msg_mock.call_args_list[0][0][0] assert 'stopping trader' in msg_mock.call_args_list[0][0][0]
def test_stop_handle_already_stopped(default_conf, update, mocker) -> None: async def test_stop_handle_already_stopped(default_conf, update, mocker) -> None:
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
freqtradebot.state = State.STOPPED freqtradebot.state = State.STOPPED
assert freqtradebot.state == State.STOPPED assert freqtradebot.state == State.STOPPED
telegram._stop(update=update, context=MagicMock()) await telegram._stop(update=update, context=MagicMock())
assert freqtradebot.state == State.STOPPED assert freqtradebot.state == State.STOPPED
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert 'already stopped' in msg_mock.call_args_list[0][0][0] assert 'already stopped' in msg_mock.call_args_list[0][0][0]
def test_stopbuy_handle(default_conf, update, mocker) -> None: async def test_stopbuy_handle(default_conf, update, mocker) -> None:
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
assert freqtradebot.config['max_open_trades'] != 0 assert freqtradebot.config['max_open_trades'] != 0
telegram._stopentry(update=update, context=MagicMock()) await telegram._stopentry(update=update, context=MagicMock())
assert freqtradebot.config['max_open_trades'] == 0 assert freqtradebot.config['max_open_trades'] == 0
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert 'No more entries will occur from now. Run /reload_config to reset.' \ assert 'No more entries will occur from now. Run /reload_config to reset.' \
in msg_mock.call_args_list[0][0][0] in msg_mock.call_args_list[0][0][0]
def test_reload_config_handle(default_conf, update, mocker) -> None: async def test_reload_config_handle(default_conf, update, mocker) -> None:
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
freqtradebot.state = State.RUNNING freqtradebot.state = State.RUNNING
assert freqtradebot.state == State.RUNNING assert freqtradebot.state == State.RUNNING
telegram._reload_config(update=update, context=MagicMock()) await telegram._reload_config(update=update, context=MagicMock())
assert freqtradebot.state == State.RELOAD_CONFIG assert freqtradebot.state == State.RELOAD_CONFIG
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert 'Reloading config' in msg_mock.call_args_list[0][0][0] assert 'Reloading config' in msg_mock.call_args_list[0][0][0]
def test_telegram_forceexit_handle(default_conf, update, ticker, fee, async def test_telegram_forceexit_handle(default_conf, update, ticker, fee,
ticker_sell_up, mocker) -> None: ticker_sell_up, mocker) -> None:
mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0) mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0)
msg_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.send_msg', MagicMock()) msg_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.send_msg', MagicMock())
@@ -980,7 +979,7 @@ def test_telegram_forceexit_handle(default_conf, update, ticker, fee,
# /forceexit 1 # /forceexit 1
context = MagicMock() context = MagicMock()
context.args = ["1"] context.args = ["1"]
telegram._force_exit(update=update, context=context) await telegram._force_exit(update=update, context=context)
assert msg_mock.call_count == 4 assert msg_mock.call_count == 4
last_msg = msg_mock.call_args_list[-2][0][0] last_msg = msg_mock.call_args_list[-2][0][0]
@@ -1016,8 +1015,8 @@ def test_telegram_forceexit_handle(default_conf, update, ticker, fee,
} == last_msg } == last_msg
def test_telegram_force_exit_down_handle(default_conf, update, ticker, fee, async def test_telegram_force_exit_down_handle(default_conf, update, ticker, fee,
ticker_sell_down, mocker) -> None: ticker_sell_down, mocker) -> None:
mocker.patch('freqtrade.rpc.fiat_convert.CryptoToFiatConverter._find_price', mocker.patch('freqtrade.rpc.fiat_convert.CryptoToFiatConverter._find_price',
return_value=15000.0) return_value=15000.0)
msg_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.send_msg', MagicMock()) msg_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.send_msg', MagicMock())
@@ -1052,7 +1051,7 @@ def test_telegram_force_exit_down_handle(default_conf, update, ticker, fee,
# /forceexit 1 # /forceexit 1
context = MagicMock() context = MagicMock()
context.args = ["1"] context.args = ["1"]
telegram._force_exit(update=update, context=context) await telegram._force_exit(update=update, context=context)
assert msg_mock.call_count == 4 assert msg_mock.call_count == 4
@@ -1089,7 +1088,7 @@ def test_telegram_force_exit_down_handle(default_conf, update, ticker, fee,
} == last_msg } == last_msg
def test_forceexit_all_handle(default_conf, update, ticker, fee, mocker) -> None: async def test_forceexit_all_handle(default_conf, update, ticker, fee, mocker) -> None:
patch_exchange(mocker) patch_exchange(mocker)
mocker.patch('freqtrade.rpc.fiat_convert.CryptoToFiatConverter._find_price', mocker.patch('freqtrade.rpc.fiat_convert.CryptoToFiatConverter._find_price',
return_value=15000.0) return_value=15000.0)
@@ -1115,7 +1114,7 @@ def test_forceexit_all_handle(default_conf, update, ticker, fee, mocker) -> None
# /forceexit all # /forceexit all
context = MagicMock() context = MagicMock()
context.args = ["all"] context.args = ["all"]
telegram._force_exit(update=update, context=context) await telegram._force_exit(update=update, context=context)
# Called for each trade 2 times # Called for each trade 2 times
assert msg_mock.call_count == 8 assert msg_mock.call_count == 8
@@ -1152,7 +1151,7 @@ def test_forceexit_all_handle(default_conf, update, ticker, fee, mocker) -> None
} == msg } == msg
def test_forceexit_handle_invalid(default_conf, update, mocker) -> None: async def test_forceexit_handle_invalid(default_conf, update, mocker) -> None:
mocker.patch('freqtrade.rpc.fiat_convert.CryptoToFiatConverter._find_price', mocker.patch('freqtrade.rpc.fiat_convert.CryptoToFiatConverter._find_price',
return_value=15000.0) return_value=15000.0)
@@ -1164,7 +1163,7 @@ def test_forceexit_handle_invalid(default_conf, update, mocker) -> None:
# /forceexit 1 # /forceexit 1
context = MagicMock() context = MagicMock()
context.args = ["1"] context.args = ["1"]
telegram._force_exit(update=update, context=context) await telegram._force_exit(update=update, context=context)
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert 'not running' in msg_mock.call_args_list[0][0][0] assert 'not running' in msg_mock.call_args_list[0][0][0]
@@ -1174,12 +1173,12 @@ def test_forceexit_handle_invalid(default_conf, update, mocker) -> None:
# /forceexit 123456 # /forceexit 123456
context = MagicMock() context = MagicMock()
context.args = ["123456"] context.args = ["123456"]
telegram._force_exit(update=update, context=context) await telegram._force_exit(update=update, context=context)
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert 'invalid argument' in msg_mock.call_args_list[0][0][0] 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: async def test_force_exit_no_pair(default_conf, update, ticker, fee, mocker) -> None:
default_conf['max_open_trades'] = 4 default_conf['max_open_trades'] = 4
mocker.patch.multiple( mocker.patch.multiple(
EXMS, EXMS,
@@ -1195,7 +1194,7 @@ def test_force_exit_no_pair(default_conf, update, ticker, fee, mocker) -> None:
# /forceexit # /forceexit
context = MagicMock() context = MagicMock()
context.args = [] context.args = []
telegram._force_exit(update=update, context=context) await telegram._force_exit(update=update, context=context)
# No pair # No pair
assert msg_mock.call_args_list[0][1]['msg'] == 'No open trade found.' assert msg_mock.call_args_list[0][1]['msg'] == 'No open trade found.'
@@ -1204,7 +1203,7 @@ def test_force_exit_no_pair(default_conf, update, ticker, fee, mocker) -> None:
msg_mock.reset_mock() msg_mock.reset_mock()
# /forceexit # /forceexit
telegram._force_exit(update=update, context=context) await telegram._force_exit(update=update, context=context)
keyboard = msg_mock.call_args_list[0][1]['keyboard'] keyboard = msg_mock.call_args_list[0][1]['keyboard']
# 4 pairs + cancel # 4 pairs + cancel
assert reduce(lambda acc, x: acc + len(x), keyboard, 0) == 5 assert reduce(lambda acc, x: acc + len(x), keyboard, 0) == 5
@@ -1214,7 +1213,7 @@ def test_force_exit_no_pair(default_conf, update, ticker, fee, mocker) -> None:
update = MagicMock() update = MagicMock()
update.callback_query = MagicMock() update.callback_query = MagicMock()
update.callback_query.data = keyboard[1][0].callback_data update.callback_query.data = keyboard[1][0].callback_data
telegram._force_exit_inline(update, None) await telegram._force_exit_inline(update, None)
assert update.callback_query.answer.call_count == 1 assert update.callback_query.answer.call_count == 1
assert update.callback_query.edit_message_text.call_count == 1 assert update.callback_query.edit_message_text.call_count == 1
assert femock.call_count == 1 assert femock.call_count == 1
@@ -1222,17 +1221,17 @@ def test_force_exit_no_pair(default_conf, update, ticker, fee, mocker) -> None:
# Retry exiting - but cancel instead # Retry exiting - but cancel instead
update.callback_query.reset_mock() update.callback_query.reset_mock()
telegram._force_exit(update=update, context=context) await telegram._force_exit(update=update, context=context)
# Use cancel button # Use cancel button
update.callback_query.data = keyboard[-1][0].callback_data update.callback_query.data = keyboard[-1][0].callback_data
telegram._force_exit_inline(update, None) await telegram._force_exit_inline(update, None)
query = update.callback_query query = update.callback_query
assert query.answer.call_count == 1 assert query.answer.call_count == 1
assert query.edit_message_text.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." assert query.edit_message_text.call_args_list[-1][1]['text'] == "Force exit canceled."
def test_force_enter_handle(default_conf, update, mocker) -> None: async def test_force_enter_handle(default_conf, update, mocker) -> None:
mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0) mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0)
fbuy_mock = MagicMock(return_value=None) fbuy_mock = MagicMock(return_value=None)
@@ -1244,7 +1243,7 @@ def test_force_enter_handle(default_conf, update, mocker) -> None:
# /forcelong ETH/BTC # /forcelong ETH/BTC
context = MagicMock() context = MagicMock()
context.args = ["ETH/BTC"] context.args = ["ETH/BTC"]
telegram._force_enter(update=update, context=context, order_side=SignalDirection.LONG) await telegram._force_enter(update=update, context=context, order_side=SignalDirection.LONG)
assert fbuy_mock.call_count == 1 assert fbuy_mock.call_count == 1
assert fbuy_mock.call_args_list[0][0][0] == 'ETH/BTC' assert fbuy_mock.call_args_list[0][0][0] == 'ETH/BTC'
@@ -1257,7 +1256,7 @@ def test_force_enter_handle(default_conf, update, mocker) -> None:
# /forcelong ETH/BTC 0.055 # /forcelong ETH/BTC 0.055
context = MagicMock() context = MagicMock()
context.args = ["ETH/BTC", "0.055"] context.args = ["ETH/BTC", "0.055"]
telegram._force_enter(update=update, context=context, order_side=SignalDirection.LONG) await telegram._force_enter(update=update, context=context, order_side=SignalDirection.LONG)
assert fbuy_mock.call_count == 1 assert fbuy_mock.call_count == 1
assert fbuy_mock.call_args_list[0][0][0] == 'ETH/BTC' assert fbuy_mock.call_args_list[0][0][0] == 'ETH/BTC'
@@ -1265,19 +1264,19 @@ def test_force_enter_handle(default_conf, update, mocker) -> None:
assert fbuy_mock.call_args_list[0][0][1] == 0.055 assert fbuy_mock.call_args_list[0][0][1] == 0.055
def test_force_enter_handle_exception(default_conf, update, mocker) -> None: async def test_force_enter_handle_exception(default_conf, update, mocker) -> None:
mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0) mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot) patch_get_signal(freqtradebot)
telegram._force_enter(update=update, context=MagicMock(), order_side=SignalDirection.LONG) await telegram._force_enter(update=update, context=MagicMock(), order_side=SignalDirection.LONG)
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert msg_mock.call_args_list[0][0][0] == 'Force_entry not enabled.' assert msg_mock.call_args_list[0][0][0] == 'Force_entry not enabled.'
def test_force_enter_no_pair(default_conf, update, mocker) -> None: async def test_force_enter_no_pair(default_conf, update, mocker) -> None:
mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0) mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0)
fbuy_mock = MagicMock(return_value=None) fbuy_mock = MagicMock(return_value=None)
@@ -1289,7 +1288,7 @@ def test_force_enter_no_pair(default_conf, update, mocker) -> None:
context = MagicMock() context = MagicMock()
context.args = [] context.args = []
telegram._force_enter(update=update, context=context, order_side=SignalDirection.LONG) await telegram._force_enter(update=update, context=context, order_side=SignalDirection.LONG)
assert fbuy_mock.call_count == 0 assert fbuy_mock.call_count == 0
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
@@ -1301,11 +1300,11 @@ def test_force_enter_no_pair(default_conf, update, mocker) -> None:
update = MagicMock() update = MagicMock()
update.callback_query = MagicMock() update.callback_query = MagicMock()
update.callback_query.data = 'XRP/USDT_||_long' update.callback_query.data = 'XRP/USDT_||_long'
telegram._force_enter_inline(update, None) await telegram._force_enter_inline(update, None)
assert fbuy_mock.call_count == 1 assert fbuy_mock.call_count == 1
def test_telegram_performance_handle(default_conf_usdt, update, ticker, fee, mocker) -> None: async def test_telegram_performance_handle(default_conf_usdt, update, ticker, fee, mocker) -> None:
mocker.patch.multiple( mocker.patch.multiple(
EXMS, EXMS,
@@ -1317,13 +1316,13 @@ def test_telegram_performance_handle(default_conf_usdt, update, ticker, fee, moc
# Create some test data # Create some test data
create_mock_trades_usdt(fee) create_mock_trades_usdt(fee)
telegram._performance(update=update, context=MagicMock()) await telegram._performance(update=update, context=MagicMock())
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert 'Performance' in msg_mock.call_args_list[0][0][0] assert 'Performance' in msg_mock.call_args_list[0][0][0]
assert '<code>XRP/USDT\t2.842 USDT (10.00%) (1)</code>' in msg_mock.call_args_list[0][0][0] assert '<code>XRP/USDT\t2.842 USDT (10.00%) (1)</code>' in msg_mock.call_args_list[0][0][0]
def test_telegram_entry_tag_performance_handle( async def test_telegram_entry_tag_performance_handle(
default_conf_usdt, update, ticker, fee, mocker) -> None: default_conf_usdt, update, ticker, fee, mocker) -> None:
mocker.patch.multiple( mocker.patch.multiple(
EXMS, EXMS,
@@ -1336,26 +1335,26 @@ def test_telegram_entry_tag_performance_handle(
create_mock_trades_usdt(fee) create_mock_trades_usdt(fee)
context = MagicMock() context = MagicMock()
telegram._enter_tag_performance(update=update, context=context) await telegram._enter_tag_performance(update=update, context=context)
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert 'Entry Tag Performance' in msg_mock.call_args_list[0][0][0] assert 'Entry Tag Performance' in msg_mock.call_args_list[0][0][0]
assert '<code>TEST1\t3.987 USDT (5.00%) (1)</code>' in msg_mock.call_args_list[0][0][0] assert '<code>TEST1\t3.987 USDT (5.00%) (1)</code>' in msg_mock.call_args_list[0][0][0]
context.args = ['XRP/USDT'] context.args = ['XRP/USDT']
telegram._enter_tag_performance(update=update, context=context) await telegram._enter_tag_performance(update=update, context=context)
assert msg_mock.call_count == 2 assert msg_mock.call_count == 2
msg_mock.reset_mock() msg_mock.reset_mock()
mocker.patch('freqtrade.rpc.rpc.RPC._rpc_enter_tag_performance', mocker.patch('freqtrade.rpc.rpc.RPC._rpc_enter_tag_performance',
side_effect=RPCException('Error')) side_effect=RPCException('Error'))
telegram._enter_tag_performance(update=update, context=MagicMock()) await telegram._enter_tag_performance(update=update, context=MagicMock())
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert "Error" in msg_mock.call_args_list[0][0][0] assert "Error" in msg_mock.call_args_list[0][0][0]
def test_telegram_exit_reason_performance_handle(default_conf_usdt, update, ticker, fee, async def test_telegram_exit_reason_performance_handle(
mocker) -> None: default_conf_usdt, update, ticker, fee, mocker) -> None:
mocker.patch.multiple( mocker.patch.multiple(
EXMS, EXMS,
fetch_ticker=ticker, fetch_ticker=ticker,
@@ -1367,26 +1366,26 @@ def test_telegram_exit_reason_performance_handle(default_conf_usdt, update, tick
create_mock_trades_usdt(fee) create_mock_trades_usdt(fee)
context = MagicMock() context = MagicMock()
telegram._exit_reason_performance(update=update, context=context) await telegram._exit_reason_performance(update=update, context=context)
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert 'Exit Reason Performance' in msg_mock.call_args_list[0][0][0] assert 'Exit Reason Performance' in msg_mock.call_args_list[0][0][0]
assert '<code>roi\t2.842 USDT (10.00%) (1)</code>' in msg_mock.call_args_list[0][0][0] assert '<code>roi\t2.842 USDT (10.00%) (1)</code>' in msg_mock.call_args_list[0][0][0]
context.args = ['XRP/USDT'] context.args = ['XRP/USDT']
telegram._exit_reason_performance(update=update, context=context) await telegram._exit_reason_performance(update=update, context=context)
assert msg_mock.call_count == 2 assert msg_mock.call_count == 2
msg_mock.reset_mock() msg_mock.reset_mock()
mocker.patch('freqtrade.rpc.rpc.RPC._rpc_exit_reason_performance', mocker.patch('freqtrade.rpc.rpc.RPC._rpc_exit_reason_performance',
side_effect=RPCException('Error')) side_effect=RPCException('Error'))
telegram._exit_reason_performance(update=update, context=MagicMock()) await telegram._exit_reason_performance(update=update, context=MagicMock())
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert "Error" in msg_mock.call_args_list[0][0][0] assert "Error" in msg_mock.call_args_list[0][0][0]
def test_telegram_mix_tag_performance_handle(default_conf_usdt, update, ticker, fee, async def test_telegram_mix_tag_performance_handle(default_conf_usdt, update, ticker, fee,
mocker) -> None: mocker) -> None:
mocker.patch.multiple( mocker.patch.multiple(
EXMS, EXMS,
fetch_ticker=ticker, fetch_ticker=ticker,
@@ -1399,26 +1398,26 @@ def test_telegram_mix_tag_performance_handle(default_conf_usdt, update, ticker,
create_mock_trades_usdt(fee) create_mock_trades_usdt(fee)
context = MagicMock() context = MagicMock()
telegram._mix_tag_performance(update=update, context=context) await telegram._mix_tag_performance(update=update, context=context)
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert 'Mix Tag Performance' in msg_mock.call_args_list[0][0][0] assert 'Mix Tag Performance' in msg_mock.call_args_list[0][0][0]
assert ('<code>TEST3 roi\t2.842 USDT (10.00%) (1)</code>' assert ('<code>TEST3 roi\t2.842 USDT (10.00%) (1)</code>'
in msg_mock.call_args_list[0][0][0]) in msg_mock.call_args_list[0][0][0])
context.args = ['XRP/USDT'] context.args = ['XRP/USDT']
telegram._mix_tag_performance(update=update, context=context) await telegram._mix_tag_performance(update=update, context=context)
assert msg_mock.call_count == 2 assert msg_mock.call_count == 2
msg_mock.reset_mock() msg_mock.reset_mock()
mocker.patch('freqtrade.rpc.rpc.RPC._rpc_mix_tag_performance', mocker.patch('freqtrade.rpc.rpc.RPC._rpc_mix_tag_performance',
side_effect=RPCException('Error')) side_effect=RPCException('Error'))
telegram._mix_tag_performance(update=update, context=MagicMock()) await telegram._mix_tag_performance(update=update, context=MagicMock())
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert "Error" in msg_mock.call_args_list[0][0][0] assert "Error" in msg_mock.call_args_list[0][0][0]
def test_count_handle(default_conf, update, ticker, fee, mocker) -> None: async def test_count_handle(default_conf, update, ticker, fee, mocker) -> None:
mocker.patch.multiple( mocker.patch.multiple(
EXMS, EXMS,
fetch_ticker=ticker, fetch_ticker=ticker,
@@ -1428,7 +1427,7 @@ def test_count_handle(default_conf, update, ticker, fee, mocker) -> None:
patch_get_signal(freqtradebot) patch_get_signal(freqtradebot)
freqtradebot.state = State.STOPPED freqtradebot.state = State.STOPPED
telegram._count(update=update, context=MagicMock()) await telegram._count(update=update, context=MagicMock())
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert 'not running' in msg_mock.call_args_list[0][0][0] assert 'not running' in msg_mock.call_args_list[0][0][0]
msg_mock.reset_mock() msg_mock.reset_mock()
@@ -1437,7 +1436,7 @@ def test_count_handle(default_conf, update, ticker, fee, mocker) -> None:
# Create some test data # Create some test data
freqtradebot.enter_positions() freqtradebot.enter_positions()
msg_mock.reset_mock() msg_mock.reset_mock()
telegram._count(update=update, context=MagicMock()) await telegram._count(update=update, context=MagicMock())
msg = ('<pre> current max total stake\n--------- ----- -------------\n' msg = ('<pre> current max total stake\n--------- ----- -------------\n'
' 1 {} {}</pre>').format( ' 1 {} {}</pre>').format(
@@ -1447,7 +1446,7 @@ def test_count_handle(default_conf, update, ticker, fee, mocker) -> None:
assert msg in msg_mock.call_args_list[0][0][0] assert msg in msg_mock.call_args_list[0][0][0]
def test_telegram_lock_handle(default_conf, update, ticker, fee, mocker) -> None: async def test_telegram_lock_handle(default_conf, update, ticker, fee, mocker) -> None:
mocker.patch.multiple( mocker.patch.multiple(
EXMS, EXMS,
fetch_ticker=ticker, fetch_ticker=ticker,
@@ -1455,7 +1454,7 @@ def test_telegram_lock_handle(default_conf, update, ticker, fee, mocker) -> None
) )
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot) patch_get_signal(freqtradebot)
telegram._locks(update=update, context=MagicMock()) await telegram._locks(update=update, context=MagicMock())
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert 'No active locks.' in msg_mock.call_args_list[0][0][0] assert 'No active locks.' in msg_mock.call_args_list[0][0][0]
@@ -1464,7 +1463,7 @@ def test_telegram_lock_handle(default_conf, update, ticker, fee, mocker) -> None
PairLocks.lock_pair('ETH/BTC', arrow.utcnow().shift(minutes=4).datetime, 'randreason') PairLocks.lock_pair('ETH/BTC', arrow.utcnow().shift(minutes=4).datetime, 'randreason')
PairLocks.lock_pair('XRP/BTC', arrow.utcnow().shift(minutes=20).datetime, 'deadbeef') PairLocks.lock_pair('XRP/BTC', arrow.utcnow().shift(minutes=20).datetime, 'deadbeef')
telegram._locks(update=update, context=MagicMock()) await telegram._locks(update=update, context=MagicMock())
assert 'Pair' in msg_mock.call_args_list[0][0][0] assert 'Pair' in msg_mock.call_args_list[0][0][0]
assert 'Until' in msg_mock.call_args_list[0][0][0] assert 'Until' in msg_mock.call_args_list[0][0][0]
@@ -1477,7 +1476,7 @@ def test_telegram_lock_handle(default_conf, update, ticker, fee, mocker) -> None
context = MagicMock() context = MagicMock()
context.args = ['XRP/BTC'] context.args = ['XRP/BTC']
msg_mock.reset_mock() msg_mock.reset_mock()
telegram._delete_locks(update=update, context=context) await telegram._delete_locks(update=update, context=context)
assert 'ETH/BTC' in msg_mock.call_args_list[0][0][0] assert 'ETH/BTC' in msg_mock.call_args_list[0][0][0]
assert 'randreason' in msg_mock.call_args_list[0][0][0] assert 'randreason' in msg_mock.call_args_list[0][0][0]
@@ -1485,11 +1484,11 @@ def test_telegram_lock_handle(default_conf, update, ticker, fee, mocker) -> None
assert 'deadbeef' not in msg_mock.call_args_list[0][0][0] assert 'deadbeef' not in msg_mock.call_args_list[0][0][0]
def test_whitelist_static(default_conf, update, mocker) -> None: async def test_whitelist_static(default_conf, update, mocker) -> None:
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
telegram._whitelist(update=update, context=MagicMock()) await telegram._whitelist(update=update, context=MagicMock())
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" assert ("Using whitelist `['StaticPairList']` with 4 pairs\n"
"`ETH/BTC, LTC/BTC, XRP/BTC, NEO/BTC`" in msg_mock.call_args_list[0][0][0]) "`ETH/BTC, LTC/BTC, XRP/BTC, NEO/BTC`" in msg_mock.call_args_list[0][0][0])
@@ -1497,33 +1496,33 @@ def test_whitelist_static(default_conf, update, mocker) -> None:
context = MagicMock() context = MagicMock()
context.args = ['sorted'] context.args = ['sorted']
msg_mock.reset_mock() msg_mock.reset_mock()
telegram._whitelist(update=update, context=context) await telegram._whitelist(update=update, context=context)
assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" assert ("Using whitelist `['StaticPairList']` with 4 pairs\n"
"`ETH/BTC, LTC/BTC, NEO/BTC, XRP/BTC`" in msg_mock.call_args_list[0][0][0]) "`ETH/BTC, LTC/BTC, NEO/BTC, XRP/BTC`" in msg_mock.call_args_list[0][0][0])
context = MagicMock() context = MagicMock()
context.args = ['baseonly'] context.args = ['baseonly']
msg_mock.reset_mock() msg_mock.reset_mock()
telegram._whitelist(update=update, context=context) await telegram._whitelist(update=update, context=context)
assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" assert ("Using whitelist `['StaticPairList']` with 4 pairs\n"
"`ETH, LTC, XRP, NEO`" in msg_mock.call_args_list[0][0][0]) "`ETH, LTC, XRP, NEO`" in msg_mock.call_args_list[0][0][0])
context = MagicMock() context = MagicMock()
context.args = ['baseonly', 'sorted'] context.args = ['baseonly', 'sorted']
msg_mock.reset_mock() msg_mock.reset_mock()
telegram._whitelist(update=update, context=context) await telegram._whitelist(update=update, context=context)
assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" assert ("Using whitelist `['StaticPairList']` with 4 pairs\n"
"`ETH, LTC, NEO, XRP`" in msg_mock.call_args_list[0][0][0]) "`ETH, LTC, NEO, XRP`" in msg_mock.call_args_list[0][0][0])
def test_whitelist_dynamic(default_conf, update, mocker) -> None: async def test_whitelist_dynamic(default_conf, update, mocker) -> None:
mocker.patch(f'{EXMS}.exchange_has', return_value=True) mocker.patch(f'{EXMS}.exchange_has', return_value=True)
default_conf['pairlists'] = [{'method': 'VolumePairList', default_conf['pairlists'] = [{'method': 'VolumePairList',
'number_assets': 4 'number_assets': 4
}] }]
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf) telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
telegram._whitelist(update=update, context=MagicMock()) await telegram._whitelist(update=update, context=MagicMock())
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert ("Using whitelist `['VolumePairList']` with 4 pairs\n" assert ("Using whitelist `['VolumePairList']` with 4 pairs\n"
"`ETH/BTC, LTC/BTC, XRP/BTC, NEO/BTC`" in msg_mock.call_args_list[0][0][0]) "`ETH/BTC, LTC/BTC, XRP/BTC, NEO/BTC`" in msg_mock.call_args_list[0][0][0])
@@ -1531,30 +1530,30 @@ def test_whitelist_dynamic(default_conf, update, mocker) -> None:
context = MagicMock() context = MagicMock()
context.args = ['sorted'] context.args = ['sorted']
msg_mock.reset_mock() msg_mock.reset_mock()
telegram._whitelist(update=update, context=context) await telegram._whitelist(update=update, context=context)
assert ("Using whitelist `['VolumePairList']` with 4 pairs\n" assert ("Using whitelist `['VolumePairList']` with 4 pairs\n"
"`ETH/BTC, LTC/BTC, NEO/BTC, XRP/BTC`" in msg_mock.call_args_list[0][0][0]) "`ETH/BTC, LTC/BTC, NEO/BTC, XRP/BTC`" in msg_mock.call_args_list[0][0][0])
context = MagicMock() context = MagicMock()
context.args = ['baseonly'] context.args = ['baseonly']
msg_mock.reset_mock() msg_mock.reset_mock()
telegram._whitelist(update=update, context=context) await telegram._whitelist(update=update, context=context)
assert ("Using whitelist `['VolumePairList']` with 4 pairs\n" assert ("Using whitelist `['VolumePairList']` with 4 pairs\n"
"`ETH, LTC, XRP, NEO`" in msg_mock.call_args_list[0][0][0]) "`ETH, LTC, XRP, NEO`" in msg_mock.call_args_list[0][0][0])
context = MagicMock() context = MagicMock()
context.args = ['baseonly', 'sorted'] context.args = ['baseonly', 'sorted']
msg_mock.reset_mock() msg_mock.reset_mock()
telegram._whitelist(update=update, context=context) await telegram._whitelist(update=update, context=context)
assert ("Using whitelist `['VolumePairList']` with 4 pairs\n" assert ("Using whitelist `['VolumePairList']` with 4 pairs\n"
"`ETH, LTC, NEO, XRP`" in msg_mock.call_args_list[0][0][0]) "`ETH, LTC, NEO, XRP`" in msg_mock.call_args_list[0][0][0])
def test_blacklist_static(default_conf, update, mocker) -> None: async def test_blacklist_static(default_conf, update, mocker) -> None:
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
telegram._blacklist(update=update, context=MagicMock()) await telegram._blacklist(update=update, context=MagicMock())
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert ("Blacklist contains 2 pairs\n`DOGE/BTC, HOT/BTC`" assert ("Blacklist contains 2 pairs\n`DOGE/BTC, HOT/BTC`"
in msg_mock.call_args_list[0][0][0]) in msg_mock.call_args_list[0][0][0])
@@ -1564,7 +1563,7 @@ def test_blacklist_static(default_conf, update, mocker) -> None:
# /blacklist ETH/BTC # /blacklist ETH/BTC
context = MagicMock() context = MagicMock()
context.args = ["ETH/BTC"] context.args = ["ETH/BTC"]
telegram._blacklist(update=update, context=context) await telegram._blacklist(update=update, context=context)
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert ("Blacklist contains 3 pairs\n`DOGE/BTC, HOT/BTC, ETH/BTC`" assert ("Blacklist contains 3 pairs\n`DOGE/BTC, HOT/BTC, ETH/BTC`"
in msg_mock.call_args_list[0][0][0]) in msg_mock.call_args_list[0][0][0])
@@ -1573,7 +1572,7 @@ def test_blacklist_static(default_conf, update, mocker) -> None:
msg_mock.reset_mock() msg_mock.reset_mock()
context = MagicMock() context = MagicMock()
context.args = ["XRP/.*"] context.args = ["XRP/.*"]
telegram._blacklist(update=update, context=context) await telegram._blacklist(update=update, context=context)
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert ("Blacklist contains 4 pairs\n`DOGE/BTC, HOT/BTC, ETH/BTC, XRP/.*`" assert ("Blacklist contains 4 pairs\n`DOGE/BTC, HOT/BTC, ETH/BTC, XRP/.*`"
@@ -1582,7 +1581,7 @@ def test_blacklist_static(default_conf, update, mocker) -> None:
msg_mock.reset_mock() msg_mock.reset_mock()
context.args = ["DOGE/BTC"] context.args = ["DOGE/BTC"]
telegram._blacklist_delete(update=update, context=context) await telegram._blacklist_delete(update=update, context=context)
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert ("Blacklist contains 3 pairs\n`HOT/BTC, ETH/BTC, XRP/.*`" assert ("Blacklist contains 3 pairs\n`HOT/BTC, ETH/BTC, XRP/.*`"
in msg_mock.call_args_list[0][0][0]) in msg_mock.call_args_list[0][0][0])
@@ -2374,7 +2373,7 @@ def test__send_msg_network_error(default_conf, mocker, caplog) -> None:
assert log_has('Telegram NetworkError: Oh snap! Trying one more time.', caplog) assert log_has('Telegram NetworkError: Oh snap! Trying one more time.', caplog)
def test__send_msg_keyboard(default_conf, mocker, caplog) -> None: async def test__send_msg_keyboard(default_conf, mocker, caplog) -> None:
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock()) mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
bot = MagicMock() bot = MagicMock()
bot.send_message = MagicMock() bot.send_message = MagicMock()
@@ -2400,7 +2399,7 @@ def test__send_msg_keyboard(default_conf, mocker, caplog) -> None:
# no keyboard in config -> default keyboard # no keyboard in config -> default keyboard
freqtradebot.config['telegram']['enabled'] = True freqtradebot.config['telegram']['enabled'] = True
telegram = init_telegram(freqtradebot) telegram = init_telegram(freqtradebot)
telegram._send_msg('test') await telegram._send_msg('test')
used_keyboard = bot.send_message.call_args[1]['reply_markup'] used_keyboard = bot.send_message.call_args[1]['reply_markup']
assert used_keyboard == default_keyboard assert used_keyboard == default_keyboard
@@ -2417,7 +2416,7 @@ def test__send_msg_keyboard(default_conf, mocker, caplog) -> None:
freqtradebot.config['telegram']['enabled'] = True freqtradebot.config['telegram']['enabled'] = True
freqtradebot.config['telegram']['keyboard'] = custom_keys_list freqtradebot.config['telegram']['keyboard'] = custom_keys_list
telegram = init_telegram(freqtradebot) telegram = init_telegram(freqtradebot)
telegram._send_msg('test') await telegram._send_msg('test')
used_keyboard = bot.send_message.call_args[1]['reply_markup'] used_keyboard = bot.send_message.call_args[1]['reply_markup']
assert used_keyboard == custom_keyboard assert used_keyboard == custom_keyboard
assert log_has("using custom keyboard from config.json: " assert log_has("using custom keyboard from config.json: "