Merge commit '4dca84817eb1b62047a9e4d282254392ea978e44' into feature/objectify

This commit is contained in:
Gerald Lonlas
2018-03-04 02:06:40 -08:00
16 changed files with 133 additions and 153 deletions

View File

@@ -8,7 +8,7 @@ from unittest.mock import MagicMock
from freqtrade.rpc.rpc_manager import RPCManager
from freqtrade.rpc.telegram import Telegram
import freqtrade.tests.conftest as tt # test tools
from freqtrade.tests.conftest import log_has, get_patched_freqtradebot
def test_rpc_manager_object() -> None:
@@ -26,7 +26,7 @@ def test__init__(mocker, default_conf) -> None:
Test __init__() method
"""
init_mock = mocker.patch('freqtrade.rpc.rpc_manager.RPCManager._init', MagicMock())
freqtradebot = tt.get_patched_freqtradebot(mocker, default_conf)
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
rpc_manager = RPCManager(freqtradebot)
assert rpc_manager.freqtrade == freqtradebot
@@ -44,10 +44,10 @@ def test_init_telegram_disabled(mocker, default_conf, caplog) -> None:
conf = deepcopy(default_conf)
conf['telegram']['enabled'] = False
freqtradebot = tt.get_patched_freqtradebot(mocker, conf)
freqtradebot = get_patched_freqtradebot(mocker, conf)
rpc_manager = RPCManager(freqtradebot)
assert not tt.log_has('Enabling rpc.telegram ...', caplog.record_tuples)
assert not log_has('Enabling rpc.telegram ...', caplog.record_tuples)
assert rpc_manager.registered_modules == []
assert rpc_manager.telegram is None
@@ -59,10 +59,10 @@ def test_init_telegram_enabled(mocker, default_conf, caplog) -> None:
caplog.set_level(logging.DEBUG)
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
freqtradebot = tt.get_patched_freqtradebot(mocker, default_conf)
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
rpc_manager = RPCManager(freqtradebot)
assert tt.log_has('Enabling rpc.telegram ...', caplog.record_tuples)
assert log_has('Enabling rpc.telegram ...', caplog.record_tuples)
len_modules = len(rpc_manager.registered_modules)
assert len_modules == 1
assert 'telegram' in rpc_manager.registered_modules
@@ -79,11 +79,11 @@ def test_cleanup_telegram_disabled(mocker, default_conf, caplog) -> None:
conf = deepcopy(default_conf)
conf['telegram']['enabled'] = False
freqtradebot = tt.get_patched_freqtradebot(mocker, conf)
freqtradebot = get_patched_freqtradebot(mocker, conf)
rpc_manager = RPCManager(freqtradebot)
rpc_manager.cleanup()
assert not tt.log_has('Cleaning up rpc.telegram ...', caplog.record_tuples)
assert not log_has('Cleaning up rpc.telegram ...', caplog.record_tuples)
assert telegram_mock.call_count == 0
@@ -95,14 +95,14 @@ def test_cleanup_telegram_enabled(mocker, default_conf, caplog) -> None:
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
telegram_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.cleanup', MagicMock())
freqtradebot = tt.get_patched_freqtradebot(mocker, default_conf)
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
rpc_manager = RPCManager(freqtradebot)
# Check we have Telegram as a registered modules
assert 'telegram' in rpc_manager.registered_modules
rpc_manager.cleanup()
assert tt.log_has('Cleaning up rpc.telegram ...', caplog.record_tuples)
assert log_has('Cleaning up rpc.telegram ...', caplog.record_tuples)
assert 'telegram' not in rpc_manager.registered_modules
assert telegram_mock.call_count == 1
@@ -116,11 +116,11 @@ def test_send_msg_telegram_disabled(mocker, default_conf, caplog) -> None:
conf = deepcopy(default_conf)
conf['telegram']['enabled'] = False
freqtradebot = tt.get_patched_freqtradebot(mocker, conf)
freqtradebot = get_patched_freqtradebot(mocker, conf)
rpc_manager = RPCManager(freqtradebot)
rpc_manager.send_msg('test')
assert tt.log_has('test', caplog.record_tuples)
assert log_has('test', caplog.record_tuples)
assert telegram_mock.call_count == 0
@@ -131,9 +131,9 @@ def test_send_msg_telegram_enabled(mocker, default_conf, caplog) -> None:
telegram_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.send_msg', MagicMock())
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
freqtradebot = tt.get_patched_freqtradebot(mocker, default_conf)
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
rpc_manager = RPCManager(freqtradebot)
rpc_manager.send_msg('test')
assert tt.log_has('test', caplog.record_tuples)
assert log_has('test', caplog.record_tuples)
assert telegram_mock.call_count == 1

View File

@@ -23,7 +23,6 @@ from freqtrade.persistence import Trade
from freqtrade.state import State
from freqtrade.tests.test_freqtradebot import patch_get_signal, patch_pymarketcap
from freqtrade.tests.conftest import get_patched_freqtradebot, log_has
import freqtrade.tests.conftest as tt # test tools
class DummyCls(Telegram):
@@ -160,15 +159,15 @@ def test_authorized_only(default_conf, mocker, caplog) -> None:
dummy = DummyCls(FreqtradeBot(conf, create_engine('sqlite://')))
dummy.dummy_handler(bot=MagicMock(), update=update)
assert dummy.state['called'] is True
assert tt.log_has(
assert log_has(
'Executing handler: dummy_handler for chat_id: 0',
caplog.record_tuples
)
assert not tt.log_has(
assert not log_has(
'Rejected unauthorized message from: 0',
caplog.record_tuples
)
assert not tt.log_has(
assert not log_has(
'Exception occurred within Telegram module',
caplog.record_tuples
)
@@ -191,15 +190,15 @@ def test_authorized_only_unauthorized(default_conf, mocker, caplog) -> None:
dummy = DummyCls(FreqtradeBot(conf, create_engine('sqlite://')))
dummy.dummy_handler(bot=MagicMock(), update=update)
assert dummy.state['called'] is False
assert not tt.log_has(
assert not log_has(
'Executing handler: dummy_handler for chat_id: 3735928559',
caplog.record_tuples
)
assert tt.log_has(
assert log_has(
'Rejected unauthorized message from: 3735928559',
caplog.record_tuples
)
assert not tt.log_has(
assert not log_has(
'Exception occurred within Telegram module',
caplog.record_tuples
)
@@ -221,15 +220,15 @@ def test_authorized_only_exception(default_conf, mocker, caplog) -> None:
dummy = DummyCls(FreqtradeBot(conf, create_engine('sqlite://')))
dummy.dummy_exception(bot=MagicMock(), update=update)
assert dummy.state['called'] is False
assert not tt.log_has(
assert not log_has(
'Executing handler: dummy_handler for chat_id: 0',
caplog.record_tuples
)
assert not tt.log_has(
assert not log_has(
'Rejected unauthorized message from: 0',
caplog.record_tuples
)
assert tt.log_has(
assert log_has(
'Exception occurred within Telegram module',
caplog.record_tuples
)
@@ -1086,7 +1085,7 @@ def test_send_msg_network_error(default_conf, mocker, caplog) -> None:
# Bot should've tried to send it twice
assert len(bot.method_calls) == 2
assert tt.log_has(
'Got TelegramError: Oh snap! Giving up on that message.',
assert log_has(
'Telegram NetworkError: Oh snap! Trying one more time.',
caplog.record_tuples
)