To better align with multiple client protocols, this PR

Refactors the existing RPC directory, classes, defs as below.
This is to better reflect the nature of the files/classes/defs to support other clients - such as rest

The code is functional, ive tested every RPC button in Telegram.
1 unit test is failing ( they all were till find_replace) in test_rpc_telegram.

Can I ask for anothers opinion on why this 1 test fails, im at loss to debug
- mocker is stretching my working knowledge of python -

Ive renamed common methods from RPC_method_name to server_method_name
e.g rpc_stop becomes server_stop, the super class is CLIENTS not RPC as it is agnostic to RPC

freqtrade/rcp/ - rpc.py
......................- rpc_manager.py
......................- telegram.py

to:

freqtrade/clients/client_manager.py (was rpc_manager
......................-common/client.py (was rpc.py - but is agnostic to what client calls)
......................-rpc/telegram.py
......................-rpc/*discord.py (example future RPC client
......................-rest/*cmd line.py (example future rest cmdline rest client
......................-rest/*web.py (example future rest web client
This commit is contained in:
creslinux 2018-06-09 09:03:22 +00:00
parent 8db3dfa8c6
commit 631df64c68
14 changed files with 200 additions and 200 deletions

View File

@ -1,18 +1,18 @@
"""
This module contains class to manage RPC communications (Telegram, Slack, ...)
This module contains class to manage CLIENT communications (Telegram, Slack, ...)
"""
from typing import Any, List
import logging
from freqtrade.rpc.telegram import Telegram
from freqtrade.clients.rpc.telegram import Telegram
logger = logging.getLogger(__name__)
class RPCManager(object):
class ClientManager(object):
"""
Class to manage RPC objects (Telegram, Slack, ...)
Class to manage CLIENT objects (Telegram, Slack, ...)
"""
def __init__(self, freqtrade) -> None:
"""
@ -28,7 +28,7 @@ class RPCManager(object):
def _init(self) -> None:
"""
Init RPC modules
Init CLIENT modules
:return:
"""
if self.freqtrade.config['telegram'].get('enabled', False):

View File

@ -1,5 +1,5 @@
"""
This module contains class to define a RPC communications
This module contains class to define a CLIENT communications
"""
import logging
from datetime import datetime, timedelta, date
@ -20,9 +20,9 @@ from freqtrade.state import State
logger = logging.getLogger(__name__)
class RPC(object):
class CLIENT(object):
"""
RPC class can be used to have extra feature, like bot data, and access to DB data
CLIENT class can be used to have extra feature, like bot data, and access to DB data
"""
def __init__(self, freqtrade) -> None:
"""
@ -32,9 +32,9 @@ class RPC(object):
"""
self.freqtrade = freqtrade
def rpc_trade_status(self) -> Tuple[bool, Any]:
def server_trade_status(self) -> Tuple[bool, Any]:
"""
Below follows the RPC backend it is prefixed with rpc_ to raise awareness that it is
Below follows the CLIENT backend it is prefixed with rpc_ to raise awareness that it is
a remotely exposed function
:return:
"""
@ -84,7 +84,7 @@ class RPC(object):
result.append(message)
return False, result
def rpc_status_table(self) -> Tuple[bool, Any]:
def server_status_table(self) -> Tuple[bool, Any]:
trades = Trade.query.filter(Trade.is_open.is_(True)).all()
if self.freqtrade.state != State.RUNNING:
return True, '*Status:* `trader is not running`'
@ -111,7 +111,7 @@ class RPC(object):
# result, or raise error
return False, df_statuses
def rpc_daily_profit(
def server_daily_profit(
self, timescale: int,
stake_currency: str, fiat_display_currency: str) -> Tuple[bool, Any]:
today = datetime.utcnow().date()
@ -159,7 +159,7 @@ class RPC(object):
]
return False, stats
def rpc_trade_statistics(
def server_trade_statistics(
self, stake_currency: str, fiat_display_currency: str) -> Tuple[bool, Any]:
"""
:return: cumulative profit statistics.
@ -242,7 +242,7 @@ class RPC(object):
}
)
def rpc_balance(self, fiat_display_currency: str) -> Tuple[bool, Any]:
def server_balance(self, fiat_display_currency: str) -> Tuple[bool, Any]:
"""
:return: current account balance per crypto
"""
@ -279,7 +279,7 @@ class RPC(object):
value = fiat.convert_amount(total, 'BTC', symbol)
return False, (output, total, symbol, value)
def rpc_start(self) -> Tuple[bool, str]:
def server_start(self) -> Tuple[bool, str]:
"""
Handler for start.
"""
@ -289,7 +289,7 @@ class RPC(object):
self.freqtrade.state = State.RUNNING
return False, '`Starting trader ...`'
def rpc_stop(self) -> Tuple[bool, str]:
def server_stop(self) -> Tuple[bool, str]:
"""
Handler for stop.
"""
@ -300,7 +300,7 @@ class RPC(object):
return True, '*Status:* `already stopped`'
# FIX: no test for this!!!!
def rpc_forcesell(self, trade_id) -> Tuple[bool, Any]:
def server_forcesell(self, trade_id) -> Tuple[bool, Any]:
"""
Handler for forcesell <id>.
Sells the given trade at current price
@ -357,7 +357,7 @@ class RPC(object):
Trade.session.flush()
return False, ''
def rpc_performance(self) -> Tuple[bool, Any]:
def server_performance(self) -> Tuple[bool, Any]:
"""
Handler for performance.
Shows a performance statistic from finished trades
@ -378,7 +378,7 @@ class RPC(object):
return False, trades
def rpc_count(self) -> Tuple[bool, Any]:
def server_count(self) -> Tuple[bool, Any]:
"""
Returns the number of trades running
:return: None

View File

View File

@ -12,7 +12,7 @@ from telegram.error import NetworkError, TelegramError
from telegram.ext import CommandHandler, Updater
from freqtrade.__init__ import __version__
from freqtrade.rpc.rpc import RPC
from freqtrade.clients.common_client import CLIENT
logger = logging.getLogger(__name__)
@ -53,13 +53,13 @@ def authorized_only(command_handler: Callable[[Any, Bot, Update], None]) -> Call
return wrapper
class Telegram(RPC):
class Telegram(CLIENT):
"""
Telegram, this class send messages to Telegram
"""
def __init__(self, freqtrade) -> None:
"""
Init the Telegram call, and init the super class RPC
Init the Telegram call, and init the super class CLIENT
:param freqtrade: Instance of a freqtrade bot
:return: None
"""
@ -143,7 +143,7 @@ class Telegram(RPC):
return
# Fetch open trade
(error, trades) = self.rpc_trade_status()
(error, trades) = self.server_trade_status()
if error:
self.send_msg(trades, bot=bot)
else:
@ -160,7 +160,7 @@ class Telegram(RPC):
:return: None
"""
# Fetch open trade
(err, df_statuses) = self.rpc_status_table()
(err, df_statuses) = self.server_status_table()
if err:
self.send_msg(df_statuses, bot=bot)
else:
@ -182,7 +182,7 @@ class Telegram(RPC):
timescale = int(update.message.text.replace('/daily', '').strip())
except (TypeError, ValueError):
timescale = 7
(error, stats) = self.rpc_daily_profit(
(error, stats) = self.server_daily_profit(
timescale,
self._config['stake_currency'],
self._config['fiat_display_currency']
@ -213,7 +213,7 @@ class Telegram(RPC):
:param update: message update
:return: None
"""
(error, stats) = self.rpc_trade_statistics(
(error, stats) = self.server_trade_statistics(
self._config['stake_currency'],
self._config['fiat_display_currency']
)
@ -256,7 +256,7 @@ class Telegram(RPC):
"""
Handler for /balance
"""
(error, result) = self.rpc_balance(self._config['fiat_display_currency'])
(error, result) = self.server_balance(self._config['fiat_display_currency'])
if error:
self.send_msg('`All balances are zero.`')
return
@ -284,7 +284,7 @@ class Telegram(RPC):
:param update: message update
:return: None
"""
(error, msg) = self.rpc_start()
(error, msg) = self.server_start()
if error:
self.send_msg(msg, bot=bot)
@ -297,7 +297,7 @@ class Telegram(RPC):
:param update: message update
:return: None
"""
(error, msg) = self.rpc_stop()
(error, msg) = self.server_stop()
self.send_msg(msg, bot=bot)
@authorized_only
@ -311,7 +311,7 @@ class Telegram(RPC):
"""
trade_id = update.message.text.replace('/forcesell', '').strip()
(error, message) = self.rpc_forcesell(trade_id)
(error, message) = self.server_forcesell(trade_id)
if error:
self.send_msg(message, bot=bot)
return
@ -325,7 +325,7 @@ class Telegram(RPC):
:param update: message update
:return: None
"""
(error, trades) = self.rpc_performance()
(error, trades) = self.server_performance()
if error:
self.send_msg(trades, bot=bot)
return
@ -348,7 +348,7 @@ class Telegram(RPC):
:param update: message update
:return: None
"""
(error, trades) = self.rpc_count()
(error, trades) = self.server_count()
if error:
self.send_msg(trades, bot=bot)
return

View File

@ -21,7 +21,7 @@ from freqtrade import constants
from freqtrade.analyze import Analyze
from freqtrade.fiat_convert import CryptoToFiatConverter
from freqtrade.persistence import Trade
from freqtrade.rpc.rpc_manager import RPCManager
from freqtrade.clients.client_manager import ClientManager
from freqtrade.state import State
logger = logging.getLogger(__name__)
@ -52,7 +52,7 @@ class FreqtradeBot(object):
self.config = config
self.analyze = Analyze(self.config)
self.fiat_converter = CryptoToFiatConverter()
self.rpc: RPCManager = RPCManager(self)
self.rpc: ClientManager = ClientManager(self)
self.persistence = None
self.exchange = None

View File

View File

View File

@ -17,8 +17,8 @@ from telegram.error import NetworkError
from freqtrade import __version__
from freqtrade.freqtradebot import FreqtradeBot
from freqtrade.persistence import Trade
from freqtrade.rpc.telegram import Telegram
from freqtrade.rpc.telegram import authorized_only
from freqtrade.clients.rpc.telegram import Telegram
from freqtrade.clients.rpc.telegram import authorized_only
from freqtrade.state import State
from freqtrade.tests.conftest import get_patched_freqtradebot, log_has
from freqtrade.tests.test_freqtradebot import patch_get_signal, patch_coinmarketcap
@ -51,8 +51,8 @@ def test__init__(default_conf, mocker) -> None:
"""
Test __init__() method
"""
mocker.patch('freqtrade.rpc.telegram.Updater', MagicMock())
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
mocker.patch('freqtrade.clients.rpc.telegram.Updater', MagicMock())
mocker.patch('freqtrade.clients.rpc.telegram.Telegram._init', MagicMock())
telegram = Telegram(get_patched_freqtradebot(mocker, default_conf))
assert telegram._updater is None
@ -64,7 +64,7 @@ def test_init(default_conf, mocker, caplog) -> None:
Test _init() method
"""
start_polling = MagicMock()
mocker.patch('freqtrade.rpc.telegram.Updater', MagicMock(return_value=start_polling))
mocker.patch('freqtrade.clients.rpc.telegram.Updater', MagicMock(return_value=start_polling))
Telegram(get_patched_freqtradebot(mocker, default_conf))
assert start_polling.call_count == 0
@ -101,7 +101,7 @@ def test_cleanup(default_conf, mocker) -> None:
"""
updater_mock = MagicMock()
updater_mock.stop = MagicMock()
mocker.patch('freqtrade.rpc.telegram.Updater', updater_mock)
mocker.patch('freqtrade.clients.rpc.telegram.Updater', updater_mock)
# not enabled
conf = deepcopy(default_conf)
@ -124,7 +124,7 @@ def test_is_enabled(default_conf, mocker) -> None:
"""
Test is_enabled() method
"""
mocker.patch('freqtrade.rpc.telegram.Updater', MagicMock())
mocker.patch('freqtrade.clients.rpc.telegram.Updater', MagicMock())
telegram = Telegram(get_patched_freqtradebot(mocker, default_conf))
assert telegram.is_enabled()
@ -254,13 +254,13 @@ def test_status(default_conf, update, mocker, fee, ticker) -> None:
msg_mock = MagicMock()
status_table = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
'freqtrade.clients.rpc.telegram.Telegram',
_init=MagicMock(),
rpc_trade_status=MagicMock(return_value=(False, [1, 2, 3])),
_status_table=status_table,
send_msg=msg_mock
)
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
mocker.patch('freqtrade.freqtradebot.ClientManager', MagicMock())
freqtradebot = FreqtradeBot(conf)
telegram = Telegram(freqtradebot)
@ -293,12 +293,12 @@ def test_status_handle(default_conf, update, ticker, fee, mocker) -> None:
msg_mock = MagicMock()
status_table = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
'freqtrade.clients.rpc.telegram.Telegram',
_init=MagicMock(),
_status_table=status_table,
send_msg=msg_mock
)
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
mocker.patch('freqtrade.freqtradebot.ClientManager', MagicMock())
freqtradebot = FreqtradeBot(default_conf)
telegram = Telegram(freqtradebot)
@ -339,11 +339,11 @@ def test_status_table_handle(default_conf, update, ticker, fee, mocker) -> None:
)
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
'freqtrade.clients.rpc.telegram.Telegram',
_init=MagicMock(),
send_msg=msg_mock
)
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
mocker.patch('freqtrade.freqtradebot.ClientManager', MagicMock())
conf = deepcopy(default_conf)
conf['stake_amount'] = 15.0
@ -395,11 +395,11 @@ def test_daily_handle(default_conf, update, ticker, limit_buy_order, fee,
)
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
'freqtrade.clients.rpc.telegram.Telegram',
_init=MagicMock(),
send_msg=msg_mock
)
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
mocker.patch('freqtrade.freqtradebot.ClientManager', MagicMock())
freqtradebot = FreqtradeBot(default_conf)
telegram = Telegram(freqtradebot)
@ -463,11 +463,11 @@ def test_daily_wrong_input(default_conf, update, ticker, mocker) -> None:
)
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
'freqtrade.clients.rpc.telegram.Telegram',
_init=MagicMock(),
send_msg=msg_mock
)
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
mocker.patch('freqtrade.freqtradebot.ClientManager', MagicMock())
freqtradebot = FreqtradeBot(default_conf)
telegram = Telegram(freqtradebot)
@ -504,11 +504,11 @@ def test_profit_handle(default_conf, update, ticker, ticker_sell_up, fee,
)
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
'freqtrade.clients.rpc.telegram.Telegram',
_init=MagicMock(),
send_msg=msg_mock
)
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
mocker.patch('freqtrade.freqtradebot.ClientManager', MagicMock())
freqtradebot = FreqtradeBot(default_conf)
telegram = Telegram(freqtradebot)
@ -602,7 +602,7 @@ def test_telegram_balance_handle(default_conf, update, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
'freqtrade.clients.rpc.telegram.Telegram',
_init=MagicMock(),
send_msg=msg_mock
)
@ -632,7 +632,7 @@ def test_zero_balance_handle(default_conf, update, mocker) -> None:
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
'freqtrade.clients.rpc.telegram.Telegram',
_init=MagicMock(),
send_msg=msg_mock
)
@ -654,11 +654,11 @@ def test_start_handle(default_conf, update, mocker) -> None:
mocker.patch('freqtrade.freqtradebot.exchange.init', MagicMock())
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
'freqtrade.clients.rpc.telegram.Telegram',
_init=MagicMock(),
send_msg=msg_mock
)
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
mocker.patch('freqtrade.freqtradebot.ClientManager', MagicMock())
freqtradebot = FreqtradeBot(default_conf)
telegram = Telegram(freqtradebot)
@ -678,11 +678,11 @@ def test_start_handle_already_running(default_conf, update, mocker) -> None:
mocker.patch('freqtrade.freqtradebot.exchange.init', MagicMock())
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
'freqtrade.clients.rpc.telegram.Telegram',
_init=MagicMock(),
send_msg=msg_mock
)
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
mocker.patch('freqtrade.freqtradebot.ClientManager', MagicMock())
freqtradebot = FreqtradeBot(default_conf)
telegram = Telegram(freqtradebot)
@ -703,11 +703,11 @@ def test_stop_handle(default_conf, update, mocker) -> None:
mocker.patch('freqtrade.freqtradebot.exchange.init', MagicMock())
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
'freqtrade.clients.rpc.telegram.Telegram',
_init=MagicMock(),
send_msg=msg_mock
)
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
mocker.patch('freqtrade.freqtradebot.ClientManager', MagicMock())
freqtradebot = FreqtradeBot(default_conf)
telegram = Telegram(freqtradebot)
@ -728,11 +728,11 @@ def test_stop_handle_already_stopped(default_conf, update, mocker) -> None:
mocker.patch('freqtrade.freqtradebot.exchange.init', MagicMock())
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
'freqtrade.clients.rpc.telegram.Telegram',
_init=MagicMock(),
send_msg=msg_mock
)
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
mocker.patch('freqtrade.freqtradebot.ClientManager', MagicMock())
freqtradebot = FreqtradeBot(default_conf)
telegram = Telegram(freqtradebot)
@ -752,8 +752,8 @@ def test_forcesell_handle(default_conf, update, ticker, fee, ticker_sell_up, moc
patch_get_signal(mocker, (True, False))
patch_coinmarketcap(mocker, value={'price_usd': 15000.0})
mocker.patch('freqtrade.fiat_convert.CryptoToFiatConverter._find_price', return_value=15000.0)
rpc_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.send_msg', MagicMock())
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
rpc_mock = mocker.patch('freqtrade.clients.rpc.telegram.Telegram.send_msg', MagicMock())
mocker.patch('freqtrade.clients.rpc.telegram.Telegram._init', MagicMock())
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
@ -792,8 +792,8 @@ def test_forcesell_down_handle(default_conf, update, ticker, fee, ticker_sell_do
patch_get_signal(mocker, (True, False))
patch_coinmarketcap(mocker, value={'price_usd': 15000.0})
mocker.patch('freqtrade.fiat_convert.CryptoToFiatConverter._find_price', return_value=15000.0)
rpc_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.send_msg', MagicMock())
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
rpc_mock = mocker.patch('freqtrade.clients.rpc.telegram.Telegram.send_msg', MagicMock())
mocker.patch('freqtrade.clients.rpc.telegram.Telegram._init', MagicMock())
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
@ -836,8 +836,8 @@ def test_forcesell_all_handle(default_conf, update, ticker, fee, mocker) -> None
patch_get_signal(mocker, (True, False))
patch_coinmarketcap(mocker, value={'price_usd': 15000.0})
mocker.patch('freqtrade.fiat_convert.CryptoToFiatConverter._find_price', return_value=15000.0)
rpc_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.send_msg', MagicMock())
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
rpc_mock = mocker.patch('freqtrade.clients.rpc.telegram.Telegram.send_msg', MagicMock())
mocker.patch('freqtrade.clients.rpc.telegram.Telegram._init', MagicMock())
mocker.patch('freqtrade.exchange.get_pair_detail_url', MagicMock())
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
@ -873,7 +873,7 @@ def test_forcesell_handle_invalid(default_conf, update, mocker) -> None:
mocker.patch('freqtrade.fiat_convert.CryptoToFiatConverter._find_price', return_value=15000.0)
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
'freqtrade.clients.rpc.telegram.Telegram',
_init=MagicMock(),
send_msg=msg_mock
)
@ -915,7 +915,7 @@ def test_performance_handle(default_conf, update, ticker, fee,
patch_coinmarketcap(mocker)
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
'freqtrade.clients.rpc.telegram.Telegram',
_init=MagicMock(),
send_msg=msg_mock
)
@ -925,7 +925,7 @@ def test_performance_handle(default_conf, update, ticker, fee,
get_ticker=ticker,
get_fee=fee
)
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
mocker.patch('freqtrade.freqtradebot.ClientManager', MagicMock())
freqtradebot = FreqtradeBot(default_conf)
telegram = Telegram(freqtradebot)
@ -956,7 +956,7 @@ def test_performance_handle_invalid(default_conf, update, mocker) -> None:
patch_coinmarketcap(mocker)
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
'freqtrade.clients.rpc.telegram.Telegram',
_init=MagicMock(),
send_msg=msg_mock
)
@ -979,7 +979,7 @@ def test_count_handle(default_conf, update, ticker, fee, mocker) -> None:
patch_coinmarketcap(mocker)
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
'freqtrade.clients.rpc.telegram.Telegram',
_init=MagicMock(),
send_msg=msg_mock
)
@ -1022,7 +1022,7 @@ def test_help_handle(default_conf, update, mocker) -> None:
mocker.patch('freqtrade.freqtradebot.exchange.init', MagicMock())
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
'freqtrade.clients.rpc.telegram.Telegram',
_init=MagicMock(),
send_msg=msg_mock
)
@ -1042,7 +1042,7 @@ def test_version_handle(default_conf, update, mocker) -> None:
mocker.patch('freqtrade.freqtradebot.exchange.init', MagicMock())
msg_mock = MagicMock()
mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram',
'freqtrade.clients.rpc.telegram.Telegram',
_init=MagicMock(),
send_msg=msg_mock
)
@ -1060,7 +1060,7 @@ def test_send_msg(default_conf, mocker) -> None:
"""
patch_coinmarketcap(mocker)
mocker.patch('freqtrade.freqtradebot.exchange.init', MagicMock())
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
mocker.patch('freqtrade.clients.rpc.telegram.Telegram._init', MagicMock())
conf = deepcopy(default_conf)
bot = MagicMock()
freqtradebot = FreqtradeBot(conf)
@ -1082,7 +1082,7 @@ def test_send_msg_network_error(default_conf, mocker, caplog) -> None:
"""
patch_coinmarketcap(mocker)
mocker.patch('freqtrade.freqtradebot.exchange.init', MagicMock())
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
mocker.patch('freqtrade.clients.rpc.telegram.Telegram._init', MagicMock())
conf = deepcopy(default_conf)
bot = MagicMock()
bot.send_message = MagicMock(side_effect=NetworkError('Oh snap'))

View File

@ -9,7 +9,7 @@ from unittest.mock import MagicMock
from freqtrade.freqtradebot import FreqtradeBot
from freqtrade.persistence import Trade
from freqtrade.rpc.rpc import RPC
from freqtrade.clients.common_client import CLIENT
from freqtrade.state import State
from freqtrade.tests.test_freqtradebot import patch_get_signal, patch_coinmarketcap
@ -23,13 +23,13 @@ def prec_satoshi(a, b) -> float:
# Unit tests
def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
def test_server_trade_status(default_conf, ticker, fee, mocker) -> None:
"""
Test rpc_trade_status() method
Test server_trade_status() method
"""
patch_get_signal(mocker, (True, False))
patch_coinmarketcap(mocker)
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
mocker.patch('freqtrade.clients.client_manager.Telegram', MagicMock())
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
@ -38,20 +38,20 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
)
freqtradebot = FreqtradeBot(default_conf)
rpc = RPC(freqtradebot)
client = CLIENT(freqtradebot)
freqtradebot.state = State.STOPPED
(error, result) = rpc.rpc_trade_status()
(error, result) = client.server_trade_status()
assert error
assert 'trader is not running' in result
freqtradebot.state = State.RUNNING
(error, result) = rpc.rpc_trade_status()
(error, result) = client.server_trade_status()
assert error
assert 'no active trade' in result
freqtradebot.create_trade()
(error, result) = rpc.rpc_trade_status()
(error, result) = client.server_trade_status()
assert not error
trade = result[0]
@ -72,13 +72,13 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
assert trade.find('[ETH/BTC]') >= 0
def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None:
def test_server_status_table(default_conf, ticker, fee, mocker) -> None:
"""
Test rpc_status_table() method
Test server_status_table() method
"""
patch_get_signal(mocker, (True, False))
patch_coinmarketcap(mocker)
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
mocker.patch('freqtrade.clients.client_manager.Telegram', MagicMock())
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
@ -87,33 +87,33 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None:
)
freqtradebot = FreqtradeBot(default_conf)
rpc = RPC(freqtradebot)
client = CLIENT(freqtradebot)
freqtradebot.state = State.STOPPED
(error, result) = rpc.rpc_status_table()
(error, result) = client.server_status_table()
assert error
assert '*Status:* `trader is not running`' in result
freqtradebot.state = State.RUNNING
(error, result) = rpc.rpc_status_table()
(error, result) = client.server_status_table()
assert error
assert '*Status:* `no active order`' in result
freqtradebot.create_trade()
(error, result) = rpc.rpc_status_table()
(error, result) = client.server_status_table()
assert 'just now' in result['Since'].all()
assert 'ETH/BTC' in result['Pair'].all()
assert '-0.59%' in result['Profit'].all()
def test_rpc_daily_profit(default_conf, update, ticker, fee,
def test_server_daily_profit(default_conf, update, ticker, fee,
limit_buy_order, limit_sell_order, mocker) -> None:
"""
Test rpc_daily_profit() method
Test server_daily_profit() method
"""
patch_get_signal(mocker, (True, False))
patch_coinmarketcap(mocker, value={'price_usd': 15000.0})
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
mocker.patch('freqtrade.clients.client_manager.Telegram', MagicMock())
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
@ -125,7 +125,7 @@ def test_rpc_daily_profit(default_conf, update, ticker, fee,
stake_currency = default_conf['stake_currency']
fiat_display_currency = default_conf['fiat_display_currency']
rpc = RPC(freqtradebot)
rpc = CLIENT(freqtradebot)
# Create some test data
freqtradebot.create_trade()
@ -140,7 +140,7 @@ def test_rpc_daily_profit(default_conf, update, ticker, fee,
# Try valid data
update.message.text = '/daily 2'
(error, days) = rpc.rpc_daily_profit(7, stake_currency, fiat_display_currency)
(error, days) = rpc.server_daily_profit(7, stake_currency, fiat_display_currency)
assert not error
assert len(days) == 7
for day in days:
@ -154,15 +154,15 @@ def test_rpc_daily_profit(default_conf, update, ticker, fee,
assert str(days[0][0]) == str(datetime.utcnow().date())
# Try invalid data
(error, days) = rpc.rpc_daily_profit(0, stake_currency, fiat_display_currency)
(error, days) = rpc.server_daily_profit(0, stake_currency, fiat_display_currency)
assert error
assert days.find('must be an integer greater than 0') >= 0
def test_rpc_trade_statistics(default_conf, ticker, ticker_sell_up, fee,
def test_server_trade_statistics(default_conf, ticker, ticker_sell_up, fee,
limit_buy_order, limit_sell_order, mocker) -> None:
"""
Test rpc_trade_statistics() method
Test server_trade_statistics() method
"""
patch_get_signal(mocker, (True, False))
mocker.patch.multiple(
@ -170,7 +170,7 @@ def test_rpc_trade_statistics(default_conf, ticker, ticker_sell_up, fee,
ticker=MagicMock(return_value={'price_usd': 15000.0}),
)
mocker.patch('freqtrade.fiat_convert.CryptoToFiatConverter._find_price', return_value=15000.0)
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
mocker.patch('freqtrade.clients.client_manager.Telegram', MagicMock())
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
@ -182,9 +182,9 @@ def test_rpc_trade_statistics(default_conf, ticker, ticker_sell_up, fee,
stake_currency = default_conf['stake_currency']
fiat_display_currency = default_conf['fiat_display_currency']
rpc = RPC(freqtradebot)
rpc = CLIENT(freqtradebot)
(error, stats) = rpc.rpc_trade_statistics(stake_currency, fiat_display_currency)
(error, stats) = rpc.server_trade_statistics(stake_currency, fiat_display_currency)
assert error
assert stats.find('no closed trade') >= 0
@ -219,7 +219,7 @@ def test_rpc_trade_statistics(default_conf, ticker, ticker_sell_up, fee,
trade.close_date = datetime.utcnow()
trade.is_open = False
(error, stats) = rpc.rpc_trade_statistics(stake_currency, fiat_display_currency)
(error, stats) = rpc.server_trade_statistics(stake_currency, fiat_display_currency)
assert not error
assert prec_satoshi(stats['profit_closed_coin'], 6.217e-05)
assert prec_satoshi(stats['profit_closed_percent'], 6.2)
@ -235,12 +235,12 @@ def test_rpc_trade_statistics(default_conf, ticker, ticker_sell_up, fee,
assert prec_satoshi(stats['best_rate'], 6.2)
# Test that rpc_trade_statistics can handle trades that lacks
# Test that server_trade_statistics can handle trades that lacks
# trade.open_rate (it is set to None)
def test_rpc_trade_statistics_closed(mocker, default_conf, ticker, fee,
def test_server_trade_statistics_closed(mocker, default_conf, ticker, fee,
ticker_sell_up, limit_buy_order, limit_sell_order):
"""
Test rpc_trade_statistics() method
Test server_trade_statistics() method
"""
patch_get_signal(mocker, (True, False))
mocker.patch.multiple(
@ -248,7 +248,7 @@ def test_rpc_trade_statistics_closed(mocker, default_conf, ticker, fee,
ticker=MagicMock(return_value={'price_usd': 15000.0}),
)
mocker.patch('freqtrade.fiat_convert.CryptoToFiatConverter._find_price', return_value=15000.0)
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
mocker.patch('freqtrade.clients.client_manager.Telegram', MagicMock())
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
@ -260,7 +260,7 @@ def test_rpc_trade_statistics_closed(mocker, default_conf, ticker, fee,
stake_currency = default_conf['stake_currency']
fiat_display_currency = default_conf['fiat_display_currency']
rpc = RPC(freqtradebot)
rpc = CLIENT(freqtradebot)
# Create some test data
freqtradebot.create_trade()
@ -281,7 +281,7 @@ def test_rpc_trade_statistics_closed(mocker, default_conf, ticker, fee,
for trade in Trade.query.order_by(Trade.id).all():
trade.open_rate = None
(error, stats) = rpc.rpc_trade_statistics(stake_currency, fiat_display_currency)
(error, stats) = rpc.server_trade_statistics(stake_currency, fiat_display_currency)
assert not error
assert prec_satoshi(stats['profit_closed_coin'], 0)
assert prec_satoshi(stats['profit_closed_percent'], 0)
@ -297,9 +297,9 @@ def test_rpc_trade_statistics_closed(mocker, default_conf, ticker, fee,
assert prec_satoshi(stats['best_rate'], 6.2)
def test_rpc_balance_handle(default_conf, mocker):
def test_server_balance_handle(default_conf, mocker):
"""
Test rpc_balance() method
Test server_balance() method
"""
mock_balance = {
'BTC': {
@ -320,7 +320,7 @@ def test_rpc_balance_handle(default_conf, mocker):
ticker=MagicMock(return_value={'price_usd': 15000.0}),
)
mocker.patch('freqtrade.fiat_convert.CryptoToFiatConverter._find_price', return_value=15000.0)
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
mocker.patch('freqtrade.clients.client_manager.Telegram', MagicMock())
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
@ -328,9 +328,9 @@ def test_rpc_balance_handle(default_conf, mocker):
)
freqtradebot = FreqtradeBot(default_conf)
rpc = RPC(freqtradebot)
rpc = CLIENT(freqtradebot)
(error, res) = rpc.rpc_balance(default_conf['fiat_display_currency'])
(error, res) = rpc.server_balance(default_conf['fiat_display_currency'])
assert not error
(trade, x, y, z) = res
assert prec_satoshi(x, 12)
@ -344,13 +344,13 @@ def test_rpc_balance_handle(default_conf, mocker):
assert prec_satoshi(trade[0]['est_btc'], 12)
def test_rpc_start(mocker, default_conf) -> None:
def test_server_start(mocker, default_conf) -> None:
"""
Test rpc_start() method
Test server_start() method
"""
patch_get_signal(mocker, (True, False))
patch_coinmarketcap(mocker)
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
mocker.patch('freqtrade.clients.client_manager.Telegram', MagicMock())
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
@ -358,27 +358,27 @@ def test_rpc_start(mocker, default_conf) -> None:
)
freqtradebot = FreqtradeBot(default_conf)
rpc = RPC(freqtradebot)
rpc = CLIENT(freqtradebot)
freqtradebot.state = State.STOPPED
(error, result) = rpc.rpc_start()
(error, result) = rpc.server_start()
assert not error
assert '`Starting trader ...`' in result
assert freqtradebot.state == State.RUNNING
(error, result) = rpc.rpc_start()
(error, result) = rpc.server_start()
assert error
assert '*Status:* `already running`' in result
assert freqtradebot.state == State.RUNNING
def test_rpc_stop(mocker, default_conf) -> None:
def test_server_stop(mocker, default_conf) -> None:
"""
Test rpc_stop() method
Test server_stop() method
"""
patch_get_signal(mocker, (True, False))
patch_coinmarketcap(mocker)
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
mocker.patch('freqtrade.clients.client_manager.Telegram', MagicMock())
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
@ -386,27 +386,27 @@ def test_rpc_stop(mocker, default_conf) -> None:
)
freqtradebot = FreqtradeBot(default_conf)
rpc = RPC(freqtradebot)
rpc = CLIENT(freqtradebot)
freqtradebot.state = State.RUNNING
(error, result) = rpc.rpc_stop()
(error, result) = rpc.server_stop()
assert not error
assert '`Stopping trader ...`' in result
assert freqtradebot.state == State.STOPPED
(error, result) = rpc.rpc_stop()
(error, result) = rpc.server_stop()
assert error
assert '*Status:* `already stopped`' in result
assert freqtradebot.state == State.STOPPED
def test_rpc_forcesell(default_conf, ticker, fee, mocker) -> None:
def test_server_forcesell(default_conf, ticker, fee, mocker) -> None:
"""
Test rpc_forcesell() method
Test server_forcesell() method
"""
patch_get_signal(mocker, (True, False))
patch_coinmarketcap(mocker)
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
mocker.patch('freqtrade.clients.client_manager.Telegram', MagicMock())
cancel_order_mock = MagicMock()
mocker.patch.multiple(
@ -425,37 +425,37 @@ def test_rpc_forcesell(default_conf, ticker, fee, mocker) -> None:
)
freqtradebot = FreqtradeBot(default_conf)
rpc = RPC(freqtradebot)
rpc = CLIENT(freqtradebot)
freqtradebot.state = State.STOPPED
(error, res) = rpc.rpc_forcesell(None)
(error, res) = rpc.server_forcesell(None)
assert error
assert res == '`trader is not running`'
freqtradebot.state = State.RUNNING
(error, res) = rpc.rpc_forcesell(None)
(error, res) = rpc.server_forcesell(None)
assert error
assert res == 'Invalid argument.'
(error, res) = rpc.rpc_forcesell('all')
(error, res) = rpc.server_forcesell('all')
assert not error
assert res == ''
freqtradebot.create_trade()
(error, res) = rpc.rpc_forcesell('all')
(error, res) = rpc.server_forcesell('all')
assert not error
assert res == ''
(error, res) = rpc.rpc_forcesell('1')
(error, res) = rpc.server_forcesell('1')
assert not error
assert res == ''
freqtradebot.state = State.STOPPED
(error, res) = rpc.rpc_forcesell(None)
(error, res) = rpc.server_forcesell(None)
assert error
assert res == '`trader is not running`'
(error, res) = rpc.rpc_forcesell('all')
(error, res) = rpc.server_forcesell('all')
assert error
assert res == '`trader is not running`'
@ -475,7 +475,7 @@ def test_rpc_forcesell(default_conf, ticker, fee, mocker) -> None:
)
# check that the trade is called, which is done by ensuring exchange.cancel_order is called
# and trade amount is updated
(error, res) = rpc.rpc_forcesell('1')
(error, res) = rpc.server_forcesell('1')
assert not error
assert res == ''
assert cancel_order_mock.call_count == 1
@ -495,7 +495,7 @@ def test_rpc_forcesell(default_conf, ticker, fee, mocker) -> None:
}
)
# check that the trade is called, which is done by ensuring exchange.cancel_order is called
(error, res) = rpc.rpc_forcesell('2')
(error, res) = rpc.server_forcesell('2')
assert not error
assert res == ''
assert cancel_order_mock.call_count == 2
@ -511,7 +511,7 @@ def test_rpc_forcesell(default_conf, ticker, fee, mocker) -> None:
'side': 'sell'
}
)
(error, res) = rpc.rpc_forcesell('3')
(error, res) = rpc.server_forcesell('3')
assert not error
assert res == ''
# status quo, no exchange calls
@ -521,11 +521,11 @@ def test_rpc_forcesell(default_conf, ticker, fee, mocker) -> None:
def test_performance_handle(default_conf, ticker, limit_buy_order, fee,
limit_sell_order, mocker) -> None:
"""
Test rpc_performance() method
Test server_performance() method
"""
patch_get_signal(mocker, (True, False))
patch_coinmarketcap(mocker)
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
mocker.patch('freqtrade.clients.client_manager.Telegram', MagicMock())
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
@ -535,7 +535,7 @@ def test_performance_handle(default_conf, ticker, limit_buy_order, fee,
)
freqtradebot = FreqtradeBot(default_conf)
rpc = RPC(freqtradebot)
rpc = CLIENT(freqtradebot)
# Create some test data
freqtradebot.create_trade()
@ -550,7 +550,7 @@ def test_performance_handle(default_conf, ticker, limit_buy_order, fee,
trade.close_date = datetime.utcnow()
trade.is_open = False
(error, res) = rpc.rpc_performance()
(error, res) = rpc.server_performance()
assert not error
assert len(res) == 1
assert res[0]['pair'] == 'ETH/BTC'
@ -558,13 +558,13 @@ def test_performance_handle(default_conf, ticker, limit_buy_order, fee,
assert prec_satoshi(res[0]['profit'], 6.2)
def test_rpc_count(mocker, default_conf, ticker, fee) -> None:
def test_server_count(mocker, default_conf, ticker, fee) -> None:
"""
Test rpc_count() method
Test server_count() method
"""
patch_get_signal(mocker, (True, False))
patch_coinmarketcap(mocker)
mocker.patch('freqtrade.rpc.rpc_manager.Telegram', MagicMock())
mocker.patch('freqtrade.clients.client_manager.Telegram', MagicMock())
mocker.patch.multiple(
'freqtrade.freqtradebot.exchange',
validate_pairs=MagicMock(),
@ -574,16 +574,16 @@ def test_rpc_count(mocker, default_conf, ticker, fee) -> None:
)
freqtradebot = FreqtradeBot(default_conf)
rpc = RPC(freqtradebot)
rpc = CLIENT(freqtradebot)
(error, trades) = rpc.rpc_count()
(error, trades) = rpc.server_count()
nb_trades = len(trades)
assert not error
assert nb_trades == 0
# Create some test data
freqtradebot.create_trade()
(error, trades) = rpc.rpc_count()
(error, trades) = rpc.server_count()
nb_trades = len(trades)
assert not error
assert nb_trades == 1

View File

@ -1,37 +1,37 @@
"""
Unit test file for rpc/rpc_manager.py
Unit test file for rpc/client_manager.py
"""
import logging
from copy import deepcopy
from unittest.mock import MagicMock
from freqtrade.rpc.rpc_manager import RPCManager
from freqtrade.rpc.telegram import Telegram
from freqtrade.clients.client_manager import ClientManager
from freqtrade.clients.rpc.telegram import Telegram
from freqtrade.tests.conftest import log_has, get_patched_freqtradebot
def test_rpc_manager_object() -> None:
def test_client_manager_object() -> None:
"""
Test the Arguments object has the mandatory methods
:return: None
"""
assert hasattr(RPCManager, '_init')
assert hasattr(RPCManager, 'send_msg')
assert hasattr(RPCManager, 'cleanup')
assert hasattr(ClientManager, '_init')
assert hasattr(ClientManager, 'send_msg')
assert hasattr(ClientManager, 'cleanup')
def test__init__(mocker, default_conf) -> None:
"""
Test __init__() method
"""
init_mock = mocker.patch('freqtrade.rpc.rpc_manager.RPCManager._init', MagicMock())
init_mock = mocker.patch('freqtrade.clients.client_manager.ClientManager._init', MagicMock())
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
rpc_manager = RPCManager(freqtradebot)
assert rpc_manager.freqtrade == freqtradebot
assert rpc_manager.registered_modules == []
assert rpc_manager.telegram is None
client_manager = ClientManager(freqtradebot)
assert client_manager.freqtrade == freqtradebot
assert client_manager.registered_modules == []
assert client_manager.telegram is None
assert init_mock.call_count == 1
@ -45,11 +45,11 @@ def test_init_telegram_disabled(mocker, default_conf, caplog) -> None:
conf['telegram']['enabled'] = False
freqtradebot = get_patched_freqtradebot(mocker, conf)
rpc_manager = RPCManager(freqtradebot)
client_manager = ClientManager(freqtradebot)
assert not log_has('Enabling rpc.telegram ...', caplog.record_tuples)
assert rpc_manager.registered_modules == []
assert rpc_manager.telegram is None
assert client_manager.registered_modules == []
assert client_manager.telegram is None
def test_init_telegram_enabled(mocker, default_conf, caplog) -> None:
@ -57,16 +57,16 @@ def test_init_telegram_enabled(mocker, default_conf, caplog) -> None:
Test _init() method with Telegram enabled
"""
caplog.set_level(logging.DEBUG)
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
mocker.patch('freqtrade.clients.rpc.telegram.Telegram._init', MagicMock())
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
rpc_manager = RPCManager(freqtradebot)
client_manager = ClientManager(freqtradebot)
assert log_has('Enabling rpc.telegram ...', caplog.record_tuples)
len_modules = len(rpc_manager.registered_modules)
len_modules = len(client_manager.registered_modules)
assert len_modules == 1
assert 'telegram' in rpc_manager.registered_modules
assert isinstance(rpc_manager.telegram, Telegram)
assert 'telegram' in client_manager.registered_modules
assert isinstance(client_manager.telegram, Telegram)
def test_cleanup_telegram_disabled(mocker, default_conf, caplog) -> None:
@ -74,14 +74,14 @@ def test_cleanup_telegram_disabled(mocker, default_conf, caplog) -> None:
Test cleanup() method with Telegram disabled
"""
caplog.set_level(logging.DEBUG)
telegram_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.cleanup', MagicMock())
telegram_mock = mocker.patch('freqtrade.clients.rpc.telegram.Telegram.cleanup', MagicMock())
conf = deepcopy(default_conf)
conf['telegram']['enabled'] = False
freqtradebot = get_patched_freqtradebot(mocker, conf)
rpc_manager = RPCManager(freqtradebot)
rpc_manager.cleanup()
client_manager = ClientManager(freqtradebot)
client_manager.cleanup()
assert not log_has('Cleaning up rpc.telegram ...', caplog.record_tuples)
assert telegram_mock.call_count == 0
@ -92,18 +92,18 @@ def test_cleanup_telegram_enabled(mocker, default_conf, caplog) -> None:
Test cleanup() method with Telegram enabled
"""
caplog.set_level(logging.DEBUG)
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
telegram_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.cleanup', MagicMock())
mocker.patch('freqtrade.clients.rpc.telegram.Telegram._init', MagicMock())
telegram_mock = mocker.patch('freqtrade.clients.rpc.telegram.Telegram.cleanup', MagicMock())
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
rpc_manager = RPCManager(freqtradebot)
client_manager = ClientManager(freqtradebot)
# Check we have Telegram as a registered modules
assert 'telegram' in rpc_manager.registered_modules
assert 'telegram' in client_manager.registered_modules
rpc_manager.cleanup()
client_manager.cleanup()
assert log_has('Cleaning up rpc.telegram ...', caplog.record_tuples)
assert 'telegram' not in rpc_manager.registered_modules
assert 'telegram' not in client_manager.registered_modules
assert telegram_mock.call_count == 1
@ -111,14 +111,14 @@ def test_send_msg_telegram_disabled(mocker, default_conf, caplog) -> None:
"""
Test send_msg() method with Telegram disabled
"""
telegram_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.send_msg', MagicMock())
telegram_mock = mocker.patch('freqtrade.clients.rpc.telegram.Telegram.send_msg', MagicMock())
conf = deepcopy(default_conf)
conf['telegram']['enabled'] = False
freqtradebot = get_patched_freqtradebot(mocker, conf)
rpc_manager = RPCManager(freqtradebot)
rpc_manager.send_msg('test')
client_manager = ClientManager(freqtradebot)
client_manager.send_msg('test')
assert log_has('test', caplog.record_tuples)
assert telegram_mock.call_count == 0
@ -128,12 +128,12 @@ def test_send_msg_telegram_enabled(mocker, default_conf, caplog) -> None:
"""
Test send_msg() method with Telegram disabled
"""
telegram_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.send_msg', MagicMock())
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
telegram_mock = mocker.patch('freqtrade.clients.rpc.telegram.Telegram.send_msg', MagicMock())
mocker.patch('freqtrade.clients.rpc.telegram.Telegram._init', MagicMock())
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
rpc_manager = RPCManager(freqtradebot)
rpc_manager.send_msg('test')
client_manager = ClientManager(freqtradebot)
client_manager.send_msg('test')
assert log_has('test', caplog.record_tuples)
assert telegram_mock.call_count == 1

View File

@ -37,11 +37,11 @@ def get_patched_freqtradebot(mocker, config) -> FreqtradeBot:
# mocker.patch('freqtrade.fiat_convert.Market', {'price_usd': 12345.0})
patch_coinmarketcap(mocker, {'price_usd': 12345.0})
mocker.patch('freqtrade.freqtradebot.Analyze', MagicMock())
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
mocker.patch('freqtrade.freqtradebot.ClientManager', MagicMock())
mocker.patch('freqtrade.freqtradebot.persistence.init', MagicMock())
mocker.patch('freqtrade.freqtradebot.exchange.init', MagicMock())
mocker.patch('freqtrade.freqtradebot.RPCManager._init', MagicMock())
mocker.patch('freqtrade.freqtradebot.RPCManager.send_msg', MagicMock())
mocker.patch('freqtrade.freqtradebot.ClientManager._init', MagicMock())
mocker.patch('freqtrade.freqtradebot.ClientManager.send_msg', MagicMock())
mocker.patch('freqtrade.freqtradebot.Analyze.get_signal', MagicMock())
return FreqtradeBot(config)

View File

@ -30,7 +30,7 @@ def get_patched_freqtradebot(mocker, config) -> FreqtradeBot:
:return: None
"""
mocker.patch('freqtrade.freqtradebot.Analyze', MagicMock())
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
mocker.patch('freqtrade.freqtradebot.ClientManager', MagicMock())
mocker.patch('freqtrade.freqtradebot.persistence.init', MagicMock())
mocker.patch('freqtrade.freqtradebot.exchange.init', MagicMock())
patch_coinmarketcap(mocker)
@ -53,12 +53,12 @@ def patch_get_signal(mocker, value=(True, False)) -> None:
def patch_RPCManager(mocker) -> MagicMock:
"""
This function mock RPC manager to avoid repeating this code in almost every tests
:param mocker: mocker to patch RPCManager class
:return: RPCManager.send_msg MagicMock to track if this method is called
This function mock CLIENT manager to avoid repeating this code in almost every tests
:param mocker: mocker to patch ClientManager class
:return: ClientManager.send_msg MagicMock to track if this method is called
"""
mocker.patch('freqtrade.freqtradebot.RPCManager._init', MagicMock())
rpc_mock = mocker.patch('freqtrade.freqtradebot.RPCManager.send_msg', MagicMock())
mocker.patch('freqtrade.freqtradebot.ClientManager._init', MagicMock())
rpc_mock = mocker.patch('freqtrade.freqtradebot.ClientManager.send_msg', MagicMock())
return rpc_mock

View File

@ -77,7 +77,7 @@ def test_main_fatal_exception(mocker, default_conf, caplog) -> None:
lambda *args, **kwargs: default_conf
)
mocker.patch('freqtrade.freqtradebot.CryptoToFiatConverter', MagicMock())
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
mocker.patch('freqtrade.freqtradebot.ClientManager', MagicMock())
args = ['-c', 'config.json.example']
@ -104,7 +104,7 @@ def test_main_keyboard_interrupt(mocker, default_conf, caplog) -> None:
lambda *args, **kwargs: default_conf
)
mocker.patch('freqtrade.freqtradebot.CryptoToFiatConverter', MagicMock())
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
mocker.patch('freqtrade.freqtradebot.ClientManager', MagicMock())
args = ['-c', 'config.json.example']
@ -131,7 +131,7 @@ def test_main_operational_exception(mocker, default_conf, caplog) -> None:
lambda *args, **kwargs: default_conf
)
mocker.patch('freqtrade.freqtradebot.CryptoToFiatConverter', MagicMock())
mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock())
mocker.patch('freqtrade.freqtradebot.ClientManager', MagicMock())
args = ['-c', 'config.json.example']