add tests for telegram.send_msg
This commit is contained in:
parent
a559e22f16
commit
cb8cd21e22
@ -12,6 +12,7 @@ from random import randint
|
|||||||
from unittest.mock import MagicMock, ANY
|
from unittest.mock import MagicMock, ANY
|
||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
|
import pytest
|
||||||
from telegram import Chat, Message, Update
|
from telegram import Chat, Message, Update
|
||||||
from telegram.error import NetworkError
|
from telegram.error import NetworkError
|
||||||
|
|
||||||
@ -1077,19 +1078,120 @@ def test_version_handle(default_conf, update, mocker) -> None:
|
|||||||
assert '*Version:* `{}`'.format(__version__) in msg_mock.call_args_list[0][0][0]
|
assert '*Version:* `{}`'.format(__version__) in msg_mock.call_args_list[0][0][0]
|
||||||
|
|
||||||
|
|
||||||
def test_send_msg_buy_notification() -> None:
|
def test_send_msg_buy_notification(default_conf, mocker) -> None:
|
||||||
# TODO: implement me
|
msg_mock = MagicMock()
|
||||||
pass
|
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({
|
||||||
|
'type': RPCMessageType.BUY_NOTIFICATION,
|
||||||
|
'exchange': 'Bittrex',
|
||||||
|
'pair': 'ETH/BTC',
|
||||||
|
'market_url': 'https://bittrex.com/Market/Index?MarketName=BTC-ETH',
|
||||||
|
'limit': 1.099e-05,
|
||||||
|
'stake_amount': 0.001,
|
||||||
|
'stake_amount_fiat': 0.0,
|
||||||
|
'stake_currency': 'BTC',
|
||||||
|
'fiat_currency': 'USD'
|
||||||
|
})
|
||||||
|
assert msg_mock.call_args[0][0] \
|
||||||
|
== '*Bittrex:* Buying [ETH/BTC](https://bittrex.com/Market/Index?MarketName=BTC-ETH)\n' \
|
||||||
|
'with limit `0.00001099\n' \
|
||||||
|
'(0.001000 BTC,0.000 USD)`'
|
||||||
|
|
||||||
|
|
||||||
def test_send_msg_sell_notification() -> None:
|
def test_send_msg_sell_notification(default_conf, mocker) -> None:
|
||||||
# TODO: implement me
|
msg_mock = MagicMock()
|
||||||
pass
|
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({
|
||||||
|
'type': RPCMessageType.SELL_NOTIFICATION,
|
||||||
|
'exchange': 'Binance',
|
||||||
|
'pair': 'KEY/ETH',
|
||||||
|
'gain': 'loss',
|
||||||
|
'market_url': 'https://www.binance.com/tradeDetail.html?symbol=KEY_ETH',
|
||||||
|
'limit': 3.201e-05,
|
||||||
|
'amount': 1333.3333333333335,
|
||||||
|
'open_rate': 7.5e-05,
|
||||||
|
'current_rate': 3.201e-05,
|
||||||
|
'profit_amount': -0.05746268,
|
||||||
|
'profit_percent': -0.57405275,
|
||||||
|
'profit_fiat': -24.81204044792,
|
||||||
|
'stake_currency': 'ETH',
|
||||||
|
'fiat_currency': 'USD'
|
||||||
|
})
|
||||||
|
assert msg_mock.call_args[0][0] \
|
||||||
|
== '*Binance:* Selling [KEY/ETH]' \
|
||||||
|
'(https://www.binance.com/tradeDetail.html?symbol=KEY_ETH)\n' \
|
||||||
|
'*Limit:* `0.00003201`\n' \
|
||||||
|
'*Amount:* `1333.33333333`\n' \
|
||||||
|
'*Open Rate:* `0.00007500`\n' \
|
||||||
|
'*Current Rate:* `0.00003201`\n' \
|
||||||
|
'*Profit:* `-57.41%`` (loss: -0.05746268 ETH`` / -24.812 USD)`'
|
||||||
|
|
||||||
|
msg_mock.reset_mock()
|
||||||
|
telegram.send_msg({
|
||||||
|
'type': RPCMessageType.SELL_NOTIFICATION,
|
||||||
|
'exchange': 'Binance',
|
||||||
|
'pair': 'KEY/ETH',
|
||||||
|
'gain': 'loss',
|
||||||
|
'market_url': 'https://www.binance.com/tradeDetail.html?symbol=KEY_ETH',
|
||||||
|
'limit': 3.201e-05,
|
||||||
|
'amount': 1333.3333333333335,
|
||||||
|
'open_rate': 7.5e-05,
|
||||||
|
'current_rate': 3.201e-05,
|
||||||
|
'profit_amount': -0.05746268,
|
||||||
|
'profit_percent': -0.57405275,
|
||||||
|
'stake_currency': 'ETH',
|
||||||
|
})
|
||||||
|
assert msg_mock.call_args[0][0] \
|
||||||
|
== '*Binance:* Selling [KEY/ETH]' \
|
||||||
|
'(https://www.binance.com/tradeDetail.html?symbol=KEY_ETH)\n' \
|
||||||
|
'*Limit:* `0.00003201`\n' \
|
||||||
|
'*Amount:* `1333.33333333`\n' \
|
||||||
|
'*Open Rate:* `0.00007500`\n' \
|
||||||
|
'*Current Rate:* `0.00003201`\n' \
|
||||||
|
'*Profit:* `-57.41%`'
|
||||||
|
|
||||||
|
|
||||||
def test_send_msg_status_notification() -> None:
|
def test_send_msg_status_notification(default_conf, mocker) -> None:
|
||||||
# TODO: implement me
|
msg_mock = MagicMock()
|
||||||
pass
|
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({
|
||||||
|
'type': RPCMessageType.STATUS_NOTIFICATION,
|
||||||
|
'status': 'running'
|
||||||
|
})
|
||||||
|
assert msg_mock.call_args[0][0] == '*Status:* `running`'
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
)
|
||||||
|
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
|
||||||
|
telegram = Telegram(freqtradebot)
|
||||||
|
with pytest.raises(NotImplementedError, match=r'Unknown message type: None'):
|
||||||
|
telegram.send_msg({
|
||||||
|
'type': None,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def test__send_msg(default_conf, mocker) -> None:
|
def test__send_msg(default_conf, mocker) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user