remove MagicBot
This commit is contained in:
parent
ed34d9f22f
commit
c81358c291
@ -5,7 +5,7 @@ from random import randint
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
from telegram import Bot, Update, Message, Chat
|
||||
from telegram import Update, Message, Chat
|
||||
from telegram.error import NetworkError
|
||||
|
||||
from freqtrade.main import init, create_trade
|
||||
@ -18,10 +18,6 @@ from freqtrade.rpc.telegram import (
|
||||
)
|
||||
|
||||
|
||||
class MagicBot(MagicMock, Bot):
|
||||
pass
|
||||
|
||||
|
||||
def test_is_enabled(default_conf, mocker):
|
||||
mocker.patch.dict('freqtrade.rpc.telegram._CONF', default_conf)
|
||||
default_conf['telegram']['enabled'] = False
|
||||
@ -93,13 +89,13 @@ def test_status_handle(default_conf, update, ticker, mocker):
|
||||
init(default_conf, 'sqlite://')
|
||||
|
||||
update_state(State.STOPPED)
|
||||
_status(bot=MagicBot(), update=update)
|
||||
_status(bot=MagicMock(), update=update)
|
||||
assert msg_mock.call_count == 1
|
||||
assert 'trader is not running' in msg_mock.call_args_list[0][0][0]
|
||||
msg_mock.reset_mock()
|
||||
|
||||
update_state(State.RUNNING)
|
||||
_status(bot=MagicBot(), update=update)
|
||||
_status(bot=MagicMock(), update=update)
|
||||
assert msg_mock.call_count == 1
|
||||
assert 'no active trade' in msg_mock.call_args_list[0][0][0]
|
||||
msg_mock.reset_mock()
|
||||
@ -111,7 +107,7 @@ def test_status_handle(default_conf, update, ticker, mocker):
|
||||
Trade.session.flush()
|
||||
|
||||
# Trigger status while we have a fulfilled order for the open trade
|
||||
_status(bot=MagicBot(), update=update)
|
||||
_status(bot=MagicMock(), update=update)
|
||||
|
||||
assert msg_mock.call_count == 2
|
||||
assert '[BTC_ETH]' in msg_mock.call_args_list[-1][0][0]
|
||||
@ -132,13 +128,13 @@ def test_status_table_handle(default_conf, update, ticker, mocker):
|
||||
buy=MagicMock(return_value='mocked_order_id'))
|
||||
init(default_conf, 'sqlite://')
|
||||
update_state(State.STOPPED)
|
||||
_status_table(bot=MagicBot(), update=update)
|
||||
_status_table(bot=MagicMock(), update=update)
|
||||
assert msg_mock.call_count == 1
|
||||
assert 'trader is not running' in msg_mock.call_args_list[0][0][0]
|
||||
msg_mock.reset_mock()
|
||||
|
||||
update_state(State.RUNNING)
|
||||
_status_table(bot=MagicBot(), update=update)
|
||||
_status_table(bot=MagicMock(), update=update)
|
||||
assert msg_mock.call_count == 1
|
||||
assert 'no active order' in msg_mock.call_args_list[0][0][0]
|
||||
msg_mock.reset_mock()
|
||||
@ -149,7 +145,7 @@ def test_status_table_handle(default_conf, update, ticker, mocker):
|
||||
Trade.session.add(trade)
|
||||
Trade.session.flush()
|
||||
|
||||
_status_table(bot=MagicBot(), update=update)
|
||||
_status_table(bot=MagicMock(), update=update)
|
||||
|
||||
text = re.sub('</?pre>', '', msg_mock.call_args_list[-1][0][0])
|
||||
line = text.split("\n")
|
||||
@ -173,7 +169,7 @@ def test_profit_handle(default_conf, update, ticker, limit_buy_order, limit_sell
|
||||
get_ticker=ticker)
|
||||
init(default_conf, 'sqlite://')
|
||||
|
||||
_profit(bot=MagicBot(), update=update)
|
||||
_profit(bot=MagicMock(), update=update)
|
||||
assert msg_mock.call_count == 1
|
||||
assert 'no closed trade' in msg_mock.call_args_list[0][0][0]
|
||||
msg_mock.reset_mock()
|
||||
@ -185,7 +181,7 @@ def test_profit_handle(default_conf, update, ticker, limit_buy_order, limit_sell
|
||||
# Simulate fulfilled LIMIT_BUY order for trade
|
||||
trade.update(limit_buy_order)
|
||||
|
||||
_profit(bot=MagicBot(), update=update)
|
||||
_profit(bot=MagicMock(), update=update)
|
||||
assert msg_mock.call_count == 2
|
||||
assert 'no closed trade' in msg_mock.call_args_list[-1][0][0]
|
||||
msg_mock.reset_mock()
|
||||
@ -198,7 +194,7 @@ def test_profit_handle(default_conf, update, ticker, limit_buy_order, limit_sell
|
||||
Trade.session.add(trade)
|
||||
Trade.session.flush()
|
||||
|
||||
_profit(bot=MagicBot(), update=update)
|
||||
_profit(bot=MagicMock(), update=update)
|
||||
assert msg_mock.call_count == 1
|
||||
assert '*ROI:* `1.50701325 (10.05%)`' in msg_mock.call_args_list[-1][0][0]
|
||||
assert 'Best Performing:* `BTC_ETH: 10.05%`' in msg_mock.call_args_list[-1][0][0]
|
||||
@ -225,7 +221,7 @@ def test_forcesell_handle(default_conf, update, ticker, mocker):
|
||||
Trade.session.flush()
|
||||
|
||||
update.message.text = '/forcesell 1'
|
||||
_forcesell(bot=MagicBot(), update=update)
|
||||
_forcesell(bot=MagicMock(), update=update)
|
||||
|
||||
assert msg_mock.call_count == 2
|
||||
assert 'Selling [BTC/ETH]' in msg_mock.call_args_list[-1][0][0]
|
||||
@ -253,7 +249,7 @@ def test_forcesell_all_handle(default_conf, update, ticker, mocker):
|
||||
msg_mock.reset_mock()
|
||||
|
||||
update.message.text = '/forcesell all'
|
||||
_forcesell(bot=MagicBot(), update=update)
|
||||
_forcesell(bot=MagicMock(), update=update)
|
||||
|
||||
assert msg_mock.call_count == 4
|
||||
for args in msg_mock.call_args_list:
|
||||
@ -275,7 +271,7 @@ def test_forcesell_handle_invalid(default_conf, update, mocker):
|
||||
# Trader is not running
|
||||
update_state(State.STOPPED)
|
||||
update.message.text = '/forcesell 1'
|
||||
_forcesell(bot=MagicBot(), update=update)
|
||||
_forcesell(bot=MagicMock(), update=update)
|
||||
assert msg_mock.call_count == 1
|
||||
assert 'not running' in msg_mock.call_args_list[0][0][0]
|
||||
|
||||
@ -283,7 +279,7 @@ def test_forcesell_handle_invalid(default_conf, update, mocker):
|
||||
msg_mock.reset_mock()
|
||||
update_state(State.RUNNING)
|
||||
update.message.text = '/forcesell'
|
||||
_forcesell(bot=MagicBot(), update=update)
|
||||
_forcesell(bot=MagicMock(), update=update)
|
||||
assert msg_mock.call_count == 1
|
||||
assert 'Invalid argument' in msg_mock.call_args_list[0][0][0]
|
||||
|
||||
@ -291,7 +287,7 @@ def test_forcesell_handle_invalid(default_conf, update, mocker):
|
||||
msg_mock.reset_mock()
|
||||
update_state(State.RUNNING)
|
||||
update.message.text = '/forcesell 123456'
|
||||
_forcesell(bot=MagicBot(), update=update)
|
||||
_forcesell(bot=MagicMock(), update=update)
|
||||
assert msg_mock.call_count == 1
|
||||
assert 'Invalid argument.' in msg_mock.call_args_list[0][0][0]
|
||||
|
||||
@ -325,7 +321,7 @@ def test_performance_handle(
|
||||
Trade.session.add(trade)
|
||||
Trade.session.flush()
|
||||
|
||||
_performance(bot=MagicBot(), update=update)
|
||||
_performance(bot=MagicMock(), update=update)
|
||||
assert msg_mock.call_count == 2
|
||||
assert 'Performance' in msg_mock.call_args_list[-1][0][0]
|
||||
assert '<code>BTC_ETH\t10.05%</code>' in msg_mock.call_args_list[-1][0][0]
|
||||
@ -346,7 +342,7 @@ def test_count_handle(default_conf, update, ticker, mocker):
|
||||
buy=MagicMock(return_value='mocked_order_id'))
|
||||
init(default_conf, 'sqlite://')
|
||||
update_state(State.STOPPED)
|
||||
_count(bot=MagicBot(), update=update)
|
||||
_count(bot=MagicMock(), update=update)
|
||||
assert msg_mock.call_count == 1
|
||||
assert 'not running' in msg_mock.call_args_list[0][0][0]
|
||||
msg_mock.reset_mock()
|
||||
@ -361,7 +357,7 @@ def test_count_handle(default_conf, update, ticker, mocker):
|
||||
Trade.session.add(trade2)
|
||||
Trade.session.flush()
|
||||
|
||||
_count(bot=MagicBot(), update=update)
|
||||
_count(bot=MagicMock(), update=update)
|
||||
line = msg_mock.call_args_list[-1][0][0].split("\n")
|
||||
assert line[2] == '{}/{}'.format(2, default_conf['max_open_trades'])
|
||||
|
||||
@ -380,7 +376,7 @@ def test_performance_handle_invalid(default_conf, update, mocker):
|
||||
|
||||
# Trader is not running
|
||||
update_state(State.STOPPED)
|
||||
_performance(bot=MagicBot(), update=update)
|
||||
_performance(bot=MagicMock(), update=update)
|
||||
assert msg_mock.call_count == 1
|
||||
assert 'not running' in msg_mock.call_args_list[0][0][0]
|
||||
|
||||
@ -398,7 +394,7 @@ def test_start_handle(default_conf, update, mocker):
|
||||
init(default_conf, 'sqlite://')
|
||||
update_state(State.STOPPED)
|
||||
assert get_state() == State.STOPPED
|
||||
_start(bot=MagicBot(), update=update)
|
||||
_start(bot=MagicMock(), update=update)
|
||||
assert get_state() == State.RUNNING
|
||||
assert msg_mock.call_count == 0
|
||||
|
||||
@ -416,7 +412,7 @@ def test_start_handle_already_running(default_conf, update, mocker):
|
||||
init(default_conf, 'sqlite://')
|
||||
update_state(State.RUNNING)
|
||||
assert get_state() == State.RUNNING
|
||||
_start(bot=MagicBot(), update=update)
|
||||
_start(bot=MagicMock(), update=update)
|
||||
assert get_state() == State.RUNNING
|
||||
assert msg_mock.call_count == 1
|
||||
assert 'already running' in msg_mock.call_args_list[0][0][0]
|
||||
@ -435,7 +431,7 @@ def test_stop_handle(default_conf, update, mocker):
|
||||
init(default_conf, 'sqlite://')
|
||||
update_state(State.RUNNING)
|
||||
assert get_state() == State.RUNNING
|
||||
_stop(bot=MagicBot(), update=update)
|
||||
_stop(bot=MagicMock(), update=update)
|
||||
assert get_state() == State.STOPPED
|
||||
assert msg_mock.call_count == 1
|
||||
assert 'Stopping trader' in msg_mock.call_args_list[0][0][0]
|
||||
@ -454,7 +450,7 @@ def test_stop_handle_already_stopped(default_conf, update, mocker):
|
||||
init(default_conf, 'sqlite://')
|
||||
update_state(State.STOPPED)
|
||||
assert get_state() == State.STOPPED
|
||||
_stop(bot=MagicBot(), update=update)
|
||||
_stop(bot=MagicMock(), update=update)
|
||||
assert get_state() == State.STOPPED
|
||||
assert msg_mock.call_count == 1
|
||||
assert 'already stopped' in msg_mock.call_args_list[0][0][0]
|
||||
@ -483,7 +479,7 @@ def test_balance_handle(default_conf, update, mocker):
|
||||
mocker.patch.multiple('freqtrade.main.exchange',
|
||||
get_balances=MagicMock(return_value=mock_balance))
|
||||
|
||||
_balance(bot=MagicBot(), update=update)
|
||||
_balance(bot=MagicMock(), update=update)
|
||||
assert msg_mock.call_count == 1
|
||||
assert '*Currency*: BTC' in msg_mock.call_args_list[0][0][0]
|
||||
assert 'Balance' in msg_mock.call_args_list[0][0][0]
|
||||
@ -497,7 +493,7 @@ def test_help_handle(default_conf, update, mocker):
|
||||
init=MagicMock(),
|
||||
send_msg=msg_mock)
|
||||
|
||||
_help(bot=MagicBot(), update=update)
|
||||
_help(bot=MagicMock(), update=update)
|
||||
assert msg_mock.call_count == 1
|
||||
assert '*/help:* `This help message`' in msg_mock.call_args_list[0][0][0]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user