Skip to content

Commit

Permalink
Unit tests for sandbox pass / fail scenarios
Browse files Browse the repository at this point in the history
Big Wave of appreciation to xmatthias for the guidence on how
Mocker works
  • Loading branch information
creslinux committed Jul 29, 2018
1 parent 0a05966 commit fc06d02
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions freqtrade/tests/exchange/test_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,33 @@ def test_set_sandbox(default_conf, mocker):
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())
Exchange(default_conf)

# def test_set_sandbox_exception(default_conf, mocker):
# """
# Test Fail scenario
# """
# api_mock = MagicMock()
# api_mock.load_markets = MagicMock(return_value={
# 'ETH/BTC': '', 'LTC/BTC': '', 'XRP/BTC': '', 'NEO/BTC': ''
# })
# url_mock = PropertyMock(return_value={'api': 'https://api.gdax.com'})
# 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(default_conf)
exchange = Exchange(default_conf)
liveurl = exchange._api.urls['api']
default_conf['exchange']['sandbox'] = True
exchange.set_sandbox(exchange._api, default_conf['exchange'], 'Logname')
assert exchange._api.urls['api'] != liveurl

def test_set_sandbox_exception(default_conf, mocker):
"""
Test Fail scenario
"""
api_mock = MagicMock()
api_mock.load_markets = MagicMock(return_value={
'ETH/BTC': '', 'LTC/BTC': '', 'XRP/BTC': '', 'NEO/BTC': ''
})
url_mock = PropertyMock(return_value={'api': 'https://api.gdax.com'})
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):
api_mock = MagicMock()
Expand Down

0 comments on commit fc06d02

Please sign in to comment.