Submitting with unit test for the working scenario.
Strongly recommend core team check the unit test is even targetting the correct code in exchange/__init__.py I have a real knowledge gap on mocker, in so far as how tests map to what they're targeting.
This commit is contained in:
parent
8648ac9da2
commit
0a059662b3
@ -95,9 +95,7 @@ class Exchange(object):
|
|||||||
except (KeyError, AttributeError):
|
except (KeyError, AttributeError):
|
||||||
raise OperationalException(f'Exchange {name} is not supported')
|
raise OperationalException(f'Exchange {name} is not supported')
|
||||||
|
|
||||||
# check if config requests sanbox, if so use ['test'] from url
|
self.set_sandbox(api, exchange_config, name)
|
||||||
if (exchange_config.get('sandbox')):
|
|
||||||
api.urls['api'] = api.urls['test']
|
|
||||||
|
|
||||||
return api
|
return api
|
||||||
|
|
||||||
@ -111,6 +109,14 @@ class Exchange(object):
|
|||||||
"""exchange ccxt id"""
|
"""exchange ccxt id"""
|
||||||
return self._api.id
|
return self._api.id
|
||||||
|
|
||||||
|
def set_sandbox(self, api, exchange_config: dict, name: str):
|
||||||
|
if exchange_config.get('sandbox'):
|
||||||
|
if api.urls.get('test'):
|
||||||
|
api.urls['api'] = api.urls['test']
|
||||||
|
else:
|
||||||
|
logger.warning(self, "No Sandbox URL in CCXT, exiting. Please check your config.json")
|
||||||
|
raise OperationalException(f'Exchange {name} does not provide a sandbox api')
|
||||||
|
|
||||||
def validate_pairs(self, pairs: List[str]) -> None:
|
def validate_pairs(self, pairs: List[str]) -> None:
|
||||||
"""
|
"""
|
||||||
Checks if all given pairs are tradable on the current exchange.
|
Checks if all given pairs are tradable on the current exchange.
|
||||||
|
@ -51,6 +51,36 @@ def test_init_exception(default_conf, mocker):
|
|||||||
mocker.patch("ccxt.binance", MagicMock(side_effect=AttributeError))
|
mocker.patch("ccxt.binance", MagicMock(side_effect=AttributeError))
|
||||||
Exchange(default_conf)
|
Exchange(default_conf)
|
||||||
|
|
||||||
|
def test_set_sandbox(default_conf, mocker):
|
||||||
|
"""
|
||||||
|
Test working scenario
|
||||||
|
"""
|
||||||
|
api_mock = MagicMock()
|
||||||
|
api_mock.load_markets = MagicMock(return_value={
|
||||||
|
'ETH/BTC': '', 'LTC/BTC': '', 'XRP/BTC': '', 'NEO/BTC': ''
|
||||||
|
})
|
||||||
|
url_mock = PropertyMock(return_value={'test': "api-public.sandbox.gdax.com", '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())
|
||||||
|
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)
|
||||||
|
|
||||||
def test_validate_pairs(default_conf, mocker):
|
def test_validate_pairs(default_conf, mocker):
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
|
Loading…
Reference in New Issue
Block a user