Further simplify test_telegram

This commit is contained in:
Matthias 2020-12-24 07:29:26 +01:00
parent 4cbbb80bc3
commit be4a4be7a3

View File

@ -54,18 +54,25 @@ class DummyCls(Telegram):
raise Exception('test')
def get_telegram_testobject(mocker, default_conf):
def get_telegram_testobject(mocker, default_conf, mock=True):
msg_mock = MagicMock()
if mock:
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
ftbot = get_patched_freqtradebot(mocker, default_conf)
telegram = Telegram(ftbot)
return telegram, ftbot
return telegram, ftbot, msg_mock
def test_telegram__init__(default_conf, mocker) -> None:
mocker.patch('freqtrade.rpc.telegram.Updater', MagicMock())
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, _ = get_telegram_testobject(mocker, default_conf)
assert telegram._config == default_conf
@ -73,7 +80,7 @@ def test_telegram_init(default_conf, mocker, caplog) -> None:
start_polling = MagicMock()
mocker.patch('freqtrade.rpc.telegram.Updater', MagicMock(return_value=start_polling))
get_telegram_testobject(mocker, default_conf)
get_telegram_testobject(mocker, default_conf, mock=False)
assert start_polling.call_count == 0
# number of handles registered
@ -95,7 +102,7 @@ def test_cleanup(default_conf, mocker, ) -> None:
updater_mock.stop = MagicMock()
mocker.patch('freqtrade.rpc.telegram.Updater', updater_mock)
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, _ = get_telegram_testobject(mocker, default_conf, mock=False)
telegram.cleanup()
assert telegram._updater.stop.call_count == 1
@ -152,11 +159,9 @@ def test_telegram_status(default_conf, update, mocker) -> None:
default_conf['telegram']['enabled'] = False
default_conf['telegram']['chat_id'] = "123"
msg_mock = MagicMock()
status_table = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_rpc_trade_status=MagicMock(return_value=[{
'trade_id': 1,
'pair': 'ETH/BTC',
@ -184,10 +189,9 @@ def test_telegram_status(default_conf, update, mocker) -> None:
'is_open': True
}]),
_status_table=status_table,
_send_msg=msg_mock
)
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
telegram._status(update=update, context=MagicMock())
assert msg_mock.call_count == 1
@ -205,16 +209,13 @@ def test_status_handle(default_conf, update, ticker, fee, mocker) -> None:
fetch_ticker=ticker,
get_fee=fee,
)
msg_mock = MagicMock()
status_table = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_status_table=status_table,
_send_msg=msg_mock
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot, (True, False))
@ -253,16 +254,10 @@ def test_status_table_handle(default_conf, update, ticker, fee, mocker) -> None:
fetch_ticker=ticker,
get_fee=fee,
)
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
default_conf['stake_amount'] = 15.0
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot, (True, False))
@ -305,14 +300,8 @@ def test_daily_handle(default_conf, update, ticker, limit_buy_order, fee,
fetch_ticker=ticker,
get_fee=fee,
)
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot, (True, False))
@ -383,14 +372,8 @@ def test_daily_wrong_input(default_conf, update, ticker, mocker) -> None:
'freqtrade.exchange.Exchange',
fetch_ticker=ticker
)
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot, (True, False))
# Try invalid data
@ -421,14 +404,8 @@ def test_profit_handle(default_conf, update, ticker, ticker_sell_up, fee,
fetch_ticker=ticker,
get_fee=fee,
)
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot, (True, False))
telegram._profit(update=update, context=MagicMock())
@ -480,16 +457,8 @@ def test_telegram_stats(default_conf, update, ticker, ticker_sell_up, fee,
fetch_ticker=ticker,
get_fee=fee,
)
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot, (True, False))
telegram = Telegram(freqtradebot)
telegram._stats(update=update, context=MagicMock())
assert msg_mock.call_count == 1
@ -514,14 +483,7 @@ def test_telegram_balance_handle(default_conf, update, mocker, rpc_balance, tick
mocker.patch('freqtrade.exchange.Exchange.get_valid_pair_combination',
side_effect=lambda a, b: f"{a}/{b}")
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot, (True, False))
telegram._balance(update=update, context=MagicMock())
@ -541,14 +503,7 @@ def test_balance_handle_empty_response(default_conf, update, mocker) -> None:
default_conf['dry_run'] = False
mocker.patch('freqtrade.exchange.Exchange.get_balances', return_value={})
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot, (True, False))
freqtradebot.config['dry_run'] = False
@ -561,14 +516,7 @@ def test_balance_handle_empty_response(default_conf, update, mocker) -> None:
def test_balance_handle_empty_response_dry(default_conf, update, mocker) -> None:
mocker.patch('freqtrade.exchange.Exchange.get_balances', return_value={})
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot, (True, False))
telegram._balance(update=update, context=MagicMock())
@ -597,14 +545,7 @@ def test_balance_handle_too_large_response(default_conf, update, mocker) -> None
'value': 1000.0,
})
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot, (True, False))
telegram._balance(update=update, context=MagicMock())
@ -617,14 +558,8 @@ def test_balance_handle_too_large_response(default_conf, update, mocker) -> None
def test_start_handle(default_conf, update, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
freqtradebot.state = State.STOPPED
assert freqtradebot.state == State.STOPPED
@ -634,14 +569,8 @@ def test_start_handle(default_conf, update, mocker) -> None:
def test_start_handle_already_running(default_conf, update, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
freqtradebot.state = State.RUNNING
assert freqtradebot.state == State.RUNNING
@ -652,14 +581,8 @@ def test_start_handle_already_running(default_conf, update, mocker) -> None:
def test_stop_handle(default_conf, update, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
freqtradebot.state = State.RUNNING
assert freqtradebot.state == State.RUNNING
@ -670,14 +593,8 @@ def test_stop_handle(default_conf, update, mocker) -> None:
def test_stop_handle_already_stopped(default_conf, update, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
freqtradebot.state = State.STOPPED
assert freqtradebot.state == State.STOPPED
@ -688,14 +605,8 @@ def test_stop_handle_already_stopped(default_conf, update, mocker) -> None:
def test_stopbuy_handle(default_conf, update, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
assert freqtradebot.config['max_open_trades'] != 0
telegram._stopbuy(update=update, context=MagicMock())
@ -706,14 +617,8 @@ def test_stopbuy_handle(default_conf, update, mocker) -> None:
def test_reload_config_handle(default_conf, update, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
freqtradebot.state = State.RUNNING
assert freqtradebot.state == State.RUNNING
@ -890,14 +795,8 @@ def test_forcesell_all_handle(default_conf, update, ticker, fee, mocker) -> None
def test_forcesell_handle_invalid(default_conf, update, mocker) -> None:
mocker.patch('freqtrade.rpc.fiat_convert.CryptoToFiatConverter._find_price',
return_value=15000.0)
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot, (True, False))
# Trader is not running
@ -990,18 +889,13 @@ def test_forcebuy_handle_exception(default_conf, update, markets, mocker) -> Non
def test_performance_handle(default_conf, update, ticker, fee,
limit_buy_order, limit_sell_order, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
mocker.patch.multiple(
'freqtrade.exchange.Exchange',
fetch_ticker=ticker,
get_fee=fee,
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot, (True, False))
# Create some test data
@ -1024,18 +918,12 @@ def test_performance_handle(default_conf, update, ticker, fee,
def test_count_handle(default_conf, update, ticker, fee, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
mocker.patch.multiple(
'freqtrade.exchange.Exchange',
fetch_ticker=ticker,
get_fee=fee,
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot, (True, False))
freqtradebot.state = State.STOPPED
@ -1059,18 +947,12 @@ def test_count_handle(default_conf, update, ticker, fee, mocker) -> None:
def test_telegram_lock_handle(default_conf, update, ticker, fee, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
mocker.patch.multiple(
'freqtrade.exchange.Exchange',
fetch_ticker=ticker,
get_fee=fee,
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot, (True, False))
PairLocks.lock_pair('ETH/BTC', arrow.utcnow().shift(minutes=4).datetime, 'randreason')
@ -1088,13 +970,8 @@ def test_telegram_lock_handle(default_conf, update, ticker, fee, mocker) -> None
def test_whitelist_static(default_conf, update, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
telegram._whitelist(update=update, context=MagicMock())
assert msg_mock.call_count == 1
@ -1103,17 +980,11 @@ def test_whitelist_static(default_conf, update, mocker) -> None:
def test_whitelist_dynamic(default_conf, update, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
default_conf['pairlists'] = [{'method': 'VolumePairList',
'number_assets': 4
}]
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
telegram._whitelist(update=update, context=MagicMock())
assert msg_mock.call_count == 1
@ -1122,13 +993,8 @@ def test_whitelist_dynamic(default_conf, update, mocker) -> None:
def test_blacklist_static(default_conf, update, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
telegram._blacklist(update=update, context=MagicMock())
assert msg_mock.call_count == 1
@ -1160,15 +1026,13 @@ def test_blacklist_static(default_conf, update, mocker) -> None:
def test_telegram_logs(default_conf, update, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
setup_logging(default_conf)
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
context = MagicMock()
context.args = []
@ -1193,14 +1057,8 @@ def test_telegram_logs(default_conf, update, mocker) -> None:
def test_edge_disabled(default_conf, update, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
telegram._edge(update=update, context=MagicMock())
assert msg_mock.call_count == 1
@ -1208,19 +1066,13 @@ def test_edge_disabled(default_conf, update, mocker) -> None:
def test_edge_enabled(edge_conf, update, mocker) -> None:
msg_mock = MagicMock()
mocker.patch('freqtrade.edge.Edge._cached_pairs', mocker.PropertyMock(
return_value={
'E/F': PairInfo(-0.01, 0.66, 3.71, 0.50, 1.71, 10, 60),
}
))
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, _ = get_telegram_testobject(mocker, edge_conf)
telegram, _, msg_mock = get_telegram_testobject(mocker, edge_conf)
telegram._edge(update=update, context=MagicMock())
assert msg_mock.call_count == 1
@ -1229,14 +1081,8 @@ def test_edge_enabled(edge_conf, update, mocker) -> None:
def test_telegram_trades(mocker, update, default_conf, fee):
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
context = MagicMock()
context.args = []
@ -1265,14 +1111,8 @@ def test_telegram_trades(mocker, update, default_conf, fee):
def test_telegram_delete_trade(mocker, update, default_conf, fee):
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
context = MagicMock()
context.args = []
@ -1291,13 +1131,7 @@ def test_telegram_delete_trade(mocker, update, default_conf, fee):
def test_help_handle(default_conf, update, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
telegram._help(update=update, context=MagicMock())
assert msg_mock.call_count == 1
@ -1305,13 +1139,8 @@ def test_help_handle(default_conf, update, mocker) -> None:
def test_version_handle(default_conf, update, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
telegram._version(update=update, context=MagicMock())
assert msg_mock.call_count == 1
@ -1319,15 +1148,10 @@ def test_version_handle(default_conf, update, mocker) -> None:
def test_show_config_handle(default_conf, update, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
default_conf['runmode'] = RunMode.DRY_RUN
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
telegram._show_config(update=update, context=MagicMock())
assert msg_mock.call_count == 1
@ -1347,12 +1171,7 @@ def test_show_config_handle(default_conf, update, mocker) -> None:
def test_send_msg_buy_notification(default_conf, mocker, caplog) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
msg = {
'type': RPCMessageType.BUY_NOTIFICATION,
'exchange': 'Bittrex',
@ -1367,7 +1186,7 @@ def test_send_msg_buy_notification(default_conf, mocker, caplog) -> None:
'amount': 1333.3333333333335,
'open_date': arrow.utcnow().shift(hours=-1)
}
telegram, freqtradebot = get_telegram_testobject(mocker, default_conf)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
telegram.send_msg(msg)
assert msg_mock.call_args[0][0] \
@ -1394,13 +1213,8 @@ def test_send_msg_buy_notification(default_conf, mocker, caplog) -> None:
def test_send_msg_buy_cancel_notification(default_conf, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
telegram.send_msg({
'type': RPCMessageType.BUY_CANCEL_NOTIFICATION,
@ -1413,13 +1227,8 @@ def test_send_msg_buy_cancel_notification(default_conf, mocker) -> None:
def test_send_msg_sell_notification(default_conf, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
old_convamount = telegram._fiat_converter.convert_amount
telegram._fiat_converter.convert_amount = lambda a, b, c: -24.812
@ -1483,13 +1292,8 @@ def test_send_msg_sell_notification(default_conf, mocker) -> None:
def test_send_msg_sell_cancel_notification(default_conf, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
old_convamount = telegram._fiat_converter.convert_amount
telegram._fiat_converter.convert_amount = lambda a, b, c: -24.812
@ -1517,13 +1321,8 @@ def test_send_msg_sell_cancel_notification(default_conf, mocker) -> None:
def test_send_msg_status_notification(default_conf, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
telegram.send_msg({
'type': RPCMessageType.STATUS_NOTIFICATION,
'status': 'running'
@ -1532,13 +1331,7 @@ def test_send_msg_status_notification(default_conf, mocker) -> None:
def test_warning_notification(default_conf, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
telegram.send_msg({
'type': RPCMessageType.WARNING_NOTIFICATION,
'status': 'message'
@ -1547,13 +1340,7 @@ def test_warning_notification(default_conf, mocker) -> None:
def test_startup_notification(default_conf, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
telegram.send_msg({
'type': RPCMessageType.STARTUP_NOTIFICATION,
'status': '*Custom:* `Hello World`'
@ -1562,13 +1349,7 @@ def test_startup_notification(default_conf, mocker) -> None:
def test_send_msg_unknown_type(default_conf, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, _ = get_telegram_testobject(mocker, default_conf)
with pytest.raises(NotImplementedError, match=r'Unknown message type: None'):
telegram.send_msg({
'type': None,
@ -1577,13 +1358,7 @@ def test_send_msg_unknown_type(default_conf, mocker) -> None:
def test_send_msg_buy_notification_no_fiat(default_conf, mocker) -> None:
del default_conf['fiat_display_currency']
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
telegram.send_msg({
'type': RPCMessageType.BUY_NOTIFICATION,
@ -1608,13 +1383,8 @@ def test_send_msg_buy_notification_no_fiat(default_conf, mocker) -> None:
def test_send_msg_sell_notification_no_fiat(default_conf, mocker) -> None:
del default_conf['fiat_display_currency']
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
telegram.send_msg({
'type': RPCMessageType.SELL_NOTIFICATION,
'exchange': 'Binance',
@ -1654,13 +1424,8 @@ def test_send_msg_sell_notification_no_fiat(default_conf, mocker) -> None:
])
def test__sell_emoji(default_conf, mocker, msg, expected):
del default_conf['fiat_display_currency']
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
_init=MagicMock(),
_send_msg=msg_mock
)
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, _ = get_telegram_testobject(mocker, default_conf)
assert telegram._get_sell_emoji(msg) == expected
@ -1668,7 +1433,7 @@ def test__sell_emoji(default_conf, mocker, msg, expected):
def test__send_msg(default_conf, mocker) -> None:
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
bot = MagicMock()
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, _ = get_telegram_testobject(mocker, default_conf, mock=False)
telegram._updater = MagicMock()
telegram._updater.bot = bot
@ -1681,7 +1446,7 @@ def test__send_msg_network_error(default_conf, mocker, caplog) -> None:
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
bot = MagicMock()
bot.send_message = MagicMock(side_effect=NetworkError('Oh snap'))
telegram, _ = get_telegram_testobject(mocker, default_conf)
telegram, _, _ = get_telegram_testobject(mocker, default_conf, mock=False)
telegram._updater = MagicMock()
telegram._updater.bot = bot