Add test for notification settings
This commit is contained in:
parent
413d7ddf70
commit
2554dc48e4
@ -36,6 +36,9 @@ class RPCMessageType(Enum):
|
||||
def __repr__(self):
|
||||
return self.value
|
||||
|
||||
def __str__(self):
|
||||
return self.value
|
||||
|
||||
|
||||
class RPCException(Exception):
|
||||
"""
|
||||
|
@ -59,7 +59,7 @@ class RPCManager:
|
||||
try:
|
||||
mod.send_msg(msg)
|
||||
except NotImplementedError:
|
||||
logger.error(f"Message type {msg['type']} not implemented by handler {mod.name}.")
|
||||
logger.error(f"Message type '{msg['type']}' not implemented by handler {mod.name}.")
|
||||
|
||||
def startup_messages(self, config: Dict[str, Any], pairlist) -> None:
|
||||
if config['dry_run']:
|
||||
|
@ -133,9 +133,9 @@ class Telegram(RPC):
|
||||
""" Send a message to telegram channel """
|
||||
|
||||
noti = self._config['telegram'].get('notification_settings', {}
|
||||
).get(msg['type'].value, 'on')
|
||||
).get(msg['type'], 'on')
|
||||
if noti == 'off':
|
||||
logger.info(f"Notification {msg['type']} not sent.")
|
||||
logger.info(f"Notification '{msg['type']}' not sent.")
|
||||
# Notification disabled
|
||||
return
|
||||
|
||||
|
@ -54,7 +54,7 @@ class Webhook(RPC):
|
||||
else:
|
||||
raise NotImplementedError('Unknown message type: {}'.format(msg['type']))
|
||||
if not valuedict:
|
||||
logger.info("Message type %s not configured for webhooks", msg['type'])
|
||||
logger.info("Message type '%s' not configured for webhooks", msg['type'])
|
||||
return
|
||||
|
||||
payload = {key: value.format(**msg) for (key, value) in valuedict.items()}
|
||||
|
@ -127,7 +127,7 @@ def test_send_msg_webhook_CustomMessagetype(mocker, default_conf, caplog) -> Non
|
||||
rpc_manager.send_msg({'type': RPCMessageType.STARTUP_NOTIFICATION,
|
||||
'status': 'TestMessage'})
|
||||
assert log_has(
|
||||
"Message type RPCMessageType.STARTUP_NOTIFICATION not implemented by handler webhook.",
|
||||
"Message type 'startup' not implemented by handler webhook.",
|
||||
caplog)
|
||||
|
||||
|
||||
|
@ -1299,16 +1299,14 @@ def test_show_config_handle(default_conf, update, mocker) -> None:
|
||||
assert '*Initial Stoploss:* `-0.1`' in msg_mock.call_args_list[0][0][0]
|
||||
|
||||
|
||||
def test_send_msg_buy_notification(default_conf, 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
|
||||
)
|
||||
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
|
||||
telegram = Telegram(freqtradebot)
|
||||
telegram.send_msg({
|
||||
msg = {
|
||||
'type': RPCMessageType.BUY_NOTIFICATION,
|
||||
'exchange': 'Bittrex',
|
||||
'pair': 'ETH/BTC',
|
||||
@ -1321,7 +1319,10 @@ def test_send_msg_buy_notification(default_conf, mocker) -> None:
|
||||
'current_rate': 1.099e-05,
|
||||
'amount': 1333.3333333333335,
|
||||
'open_date': arrow.utcnow().shift(hours=-1)
|
||||
})
|
||||
}
|
||||
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
|
||||
telegram = Telegram(freqtradebot)
|
||||
telegram.send_msg(msg)
|
||||
assert msg_mock.call_args[0][0] \
|
||||
== '\N{LARGE BLUE CIRCLE} *Bittrex:* Buying ETH/BTC\n' \
|
||||
'*Amount:* `1333.33333333`\n' \
|
||||
@ -1329,6 +1330,21 @@ def test_send_msg_buy_notification(default_conf, mocker) -> None:
|
||||
'*Current Rate:* `0.00001099`\n' \
|
||||
'*Total:* `(0.001000 BTC, 12.345 USD)`'
|
||||
|
||||
freqtradebot.config['telegram']['notification_settings'] = {'buy': 'off'}
|
||||
caplog.clear()
|
||||
msg_mock.reset_mock()
|
||||
telegram.send_msg(msg)
|
||||
msg_mock.call_count == 0
|
||||
log_has("Notification 'buy' not sent.", caplog)
|
||||
|
||||
freqtradebot.config['telegram']['notification_settings'] = {'buy': 'silent'}
|
||||
caplog.clear()
|
||||
msg_mock.reset_mock()
|
||||
|
||||
telegram.send_msg(msg)
|
||||
msg_mock.call_count == 1
|
||||
msg_mock.call_args_list[0][1]['disable_notification'] is True
|
||||
|
||||
|
||||
def test_send_msg_buy_cancel_notification(default_conf, mocker) -> None:
|
||||
msg_mock = MagicMock()
|
||||
|
@ -174,7 +174,7 @@ def test_exception_send_msg(default_conf, mocker, caplog):
|
||||
|
||||
webhook = Webhook(get_patched_freqtradebot(mocker, default_conf))
|
||||
webhook.send_msg({'type': RPCMessageType.BUY_NOTIFICATION})
|
||||
assert log_has(f"Message type {RPCMessageType.BUY_NOTIFICATION} not configured for webhooks",
|
||||
assert log_has(f"Message type '{RPCMessageType.BUY_NOTIFICATION}' not configured for webhooks",
|
||||
caplog)
|
||||
|
||||
default_conf["webhook"] = get_webhook_dict()
|
||||
|
Loading…
Reference in New Issue
Block a user