convert start, stop and reload_conf to return a dict

This commit is contained in:
gcarq 2018-06-22 03:32:45 +02:00
parent 5288e18f2f
commit df8ba28ce5
4 changed files with 29 additions and 19 deletions

View File

@ -26,7 +26,17 @@ class RPCException(Exception):
raise RPCException('*Status:* `no active trade`')
"""
pass
def __init__(self, message: str) -> None:
super().__init__(self)
self.message = message
def __str__(self):
return self.message
def __json__(self):
return {
'msg': self.message
}
class RPC(object):
@ -286,28 +296,27 @@ class RPC(object):
value = fiat.convert_amount(total, 'BTC', symbol)
return output, total, symbol, value
def _rpc_start(self) -> str:
def _rpc_start(self) -> Dict[str, str]:
""" Handler for start """
if self._freqtrade.state == State.RUNNING:
return '*Status:* `already running`'
return {'status': 'already running'}
self._freqtrade.state = State.RUNNING
return '`Starting trader ...`'
return {'status': 'starting trader ...'}
def _rpc_stop(self) -> str:
def _rpc_stop(self) -> Dict[str, str]:
""" Handler for stop """
if self._freqtrade.state == State.RUNNING:
self._freqtrade.state = State.STOPPED
return '`Stopping trader ...`'
return {'status': 'stopping trader ...'}
return '*Status:* `already stopped`'
return {'status': 'already stopped'}
def _rpc_reload_conf(self) -> str:
def _rpc_reload_conf(self) -> Dict[str, str]:
""" Handler for reload_conf. """
self._freqtrade.state = State.RELOAD_CONF
return '*Status:* `Reloading config ...`'
return {'status': 'reloading config ...'}
# FIX: no test for this!!!!
def _rpc_forcesell(self, trade_id) -> None:
"""
Handler for forcesell <id>.

View File

@ -266,7 +266,7 @@ class Telegram(RPC):
:return: None
"""
msg = self._rpc_start()
self._send_msg(msg, bot=bot)
self._send_msg('Status: `{status}`'.format(**msg), bot=bot)
@authorized_only
def _stop(self, bot: Bot, update: Update) -> None:
@ -278,7 +278,7 @@ class Telegram(RPC):
:return: None
"""
msg = self._rpc_stop()
self._send_msg(msg, bot=bot)
self._send_msg('Status: `{status}`'.format(**msg), bot=bot)
@authorized_only
def _reload_conf(self, bot: Bot, update: Update) -> None:
@ -290,7 +290,7 @@ class Telegram(RPC):
:return: None
"""
msg = self._rpc_reload_conf()
self._send_msg(msg, bot=bot)
self._send_msg('Status: `{status}`'.format(**msg), bot=bot)
@authorized_only
def _forcesell(self, bot: Bot, update: Update) -> None:

View File

@ -358,11 +358,11 @@ def test_rpc_start(mocker, default_conf) -> None:
freqtradebot.state = State.STOPPED
result = rpc._rpc_start()
assert '`Starting trader ...`' in result
assert {'status': 'starting trader ...'} == result
assert freqtradebot.state == State.RUNNING
result = rpc._rpc_start()
assert '*Status:* `already running`' in result
assert {'status': 'already running'} == result
assert freqtradebot.state == State.RUNNING
@ -384,11 +384,12 @@ def test_rpc_stop(mocker, default_conf) -> None:
freqtradebot.state = State.RUNNING
result = rpc._rpc_stop()
assert '`Stopping trader ...`' in result
assert {'status': 'stopping trader ...'} == result
assert freqtradebot.state == State.STOPPED
result = rpc._rpc_stop()
assert '*Status:* `already stopped`' in result
assert {'status': 'already stopped'} == result
assert freqtradebot.state == State.STOPPED

View File

@ -664,7 +664,7 @@ def test_stop_handle(default_conf, update, mocker) -> None:
telegram._stop(bot=MagicMock(), update=update)
assert freqtradebot.state == State.STOPPED
assert msg_mock.call_count == 1
assert 'Stopping trader' in msg_mock.call_args_list[0][0][0]
assert 'stopping trader' in msg_mock.call_args_list[0][0][0]
def test_stop_handle_already_stopped(default_conf, update, mocker) -> None:
@ -708,7 +708,7 @@ def test_reload_conf_handle(default_conf, update, mocker) -> None:
telegram._reload_conf(bot=MagicMock(), update=update)
assert freqtradebot.state == State.RELOAD_CONF
assert msg_mock.call_count == 1
assert 'Reloading config' in msg_mock.call_args_list[0][0][0]
assert 'reloading config' in msg_mock.call_args_list[0][0][0]
def test_forcesell_handle(default_conf, update, ticker, fee,