add test
This commit is contained in:
parent
8741017819
commit
1a92bf9e8e
@ -222,9 +222,8 @@ class Exchange(object):
|
|||||||
self._last_markets_refresh + self.markets_refresh_interval
|
self._last_markets_refresh + self.markets_refresh_interval
|
||||||
> arrow.utcnow().timestamp):
|
> arrow.utcnow().timestamp):
|
||||||
return None
|
return None
|
||||||
else:
|
logger.debug("Performing scheduled market reload..")
|
||||||
logger.debug("Performing scheduled market reload..")
|
self._load_markets(reload=True)
|
||||||
self._load_markets(reload=True)
|
|
||||||
|
|
||||||
def validate_pairs(self, pairs: List[str]) -> None:
|
def validate_pairs(self, pairs: List[str]) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -245,12 +245,38 @@ def test__load_markets(default_conf, mocker, caplog):
|
|||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
api_mock.load_markets = MagicMock(return_value=expected_return)
|
api_mock.load_markets = MagicMock(return_value=expected_return)
|
||||||
type(api_mock).markets = expected_return
|
type(api_mock).markets = expected_return
|
||||||
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
|
|
||||||
default_conf['exchange']['pair_whitelist'] = ['ETH/BTC']
|
default_conf['exchange']['pair_whitelist'] = ['ETH/BTC']
|
||||||
ex = get_patched_exchange(mocker, default_conf, api_mock, id="binance")
|
ex = get_patched_exchange(mocker, default_conf, api_mock, id="binance")
|
||||||
assert ex.markets == expected_return
|
assert ex.markets == expected_return
|
||||||
|
|
||||||
|
|
||||||
|
def test__reload_markets(default_conf, mocker, caplog):
|
||||||
|
caplog.set_level(logging.DEBUG)
|
||||||
|
api_mock = MagicMock()
|
||||||
|
initial_markets = {'ETH/BTC': {}}
|
||||||
|
type(api_mock).markets = initial_markets
|
||||||
|
updated_markets = {'ETH/BTC': {}, "LTC/BTC": {}}
|
||||||
|
default_conf['exchange']['markets_refresh_interval'] = 10
|
||||||
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id="binance")
|
||||||
|
exchange._last_markets_refresh = arrow.utcnow().timestamp
|
||||||
|
|
||||||
|
def _load_markets(*args, **kwargs):
|
||||||
|
exchange._api.markets = updated_markets
|
||||||
|
|
||||||
|
mocker.patch('freqtrade.exchange.Exchange._load_markets', _load_markets)
|
||||||
|
assert exchange.markets == initial_markets
|
||||||
|
|
||||||
|
# less than 10 minutes have passed, no reload
|
||||||
|
exchange._reload_markets()
|
||||||
|
assert exchange.markets == initial_markets
|
||||||
|
|
||||||
|
# more than 10 minutes have passed, reload is executed
|
||||||
|
exchange._last_markets_refresh = arrow.utcnow().timestamp - 15 * 60
|
||||||
|
exchange._reload_markets()
|
||||||
|
assert exchange.markets == updated_markets
|
||||||
|
assert log_has('Performing scheduled market reload..', caplog.record_tuples)
|
||||||
|
|
||||||
|
|
||||||
def test_validate_pairs(default_conf, mocker): # test exchange.validate_pairs directly
|
def test_validate_pairs(default_conf, mocker): # test exchange.validate_pairs directly
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
type(api_mock).markets = PropertyMock(return_value={
|
type(api_mock).markets = PropertyMock(return_value={
|
||||||
|
Loading…
Reference in New Issue
Block a user