Unit tests for sandbox pass / fail scenarios

Big Wave of appreciation to xmatthias for the guidence on how
Mocker works
This commit is contained in:
creslinux 2018-07-29 08:02:04 +00:00
parent 0a059662b3
commit fc06d028b8

View File

@ -63,24 +63,33 @@ def test_set_sandbox(default_conf, mocker):
type(api_mock).urls = url_mock type(api_mock).urls = url_mock
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock)) mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes', MagicMock()) mocker.patch('freqtrade.exchange.Exchange.validate_timeframes', MagicMock())
Exchange(default_conf)
# def test_set_sandbox_exception(default_conf, mocker): exchange = Exchange(default_conf)
# """ liveurl = exchange._api.urls['api']
# Test Fail scenario default_conf['exchange']['sandbox'] = True
# """ exchange.set_sandbox(exchange._api, default_conf['exchange'], 'Logname')
# api_mock = MagicMock() assert exchange._api.urls['api'] != liveurl
# api_mock.load_markets = MagicMock(return_value={
# 'ETH/BTC': '', 'LTC/BTC': '', 'XRP/BTC': '', 'NEO/BTC': '' def test_set_sandbox_exception(default_conf, mocker):
# }) """
# url_mock = PropertyMock(return_value={'api': 'https://api.gdax.com'}) Test Fail scenario
# type(api_mock).urls = url_mock """
# api_mock = MagicMock()
# mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock)) api_mock.load_markets = MagicMock(return_value={
# mocker.patch('freqtrade.exchange.Exchange.validate_timeframes', MagicMock()) 'ETH/BTC': '', 'LTC/BTC': '', 'XRP/BTC': '', 'NEO/BTC': ''
# })
# with pytest.raises(OperationalException, match=r'does not provide a sandbox api'): url_mock = PropertyMock(return_value={'api': 'https://api.gdax.com'})
# Exchange(default_conf) type(api_mock).urls = url_mock
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
mocker.patch('freqtrade.exchange.Exchange.validate_timeframes', MagicMock())
with pytest.raises(OperationalException, match=r'does not provide a sandbox api'):
exchange = Exchange(default_conf)
default_conf['exchange']['sandbox'] = True
exchange.set_sandbox(exchange._api, default_conf['exchange'], 'Logname')
assert exchange._api.urls.get('test') == False
def test_validate_pairs(default_conf, mocker): def test_validate_pairs(default_conf, mocker):
api_mock = MagicMock() api_mock = MagicMock()