added tests

This commit is contained in:
Bloodhunter4rc
2023-06-24 14:31:30 +02:00
parent 36b33fb407
commit caca070c1a
2 changed files with 72 additions and 7 deletions

View File

@@ -51,6 +51,11 @@ class RemotePairList(IPairList):
self._init_done = False
self._last_pairlist: List[Any] = list()
if self._mode not in ['whitelist', 'blacklist']:
raise OperationalException(
'`mode` not configured correctly. Supported Modes '
'are "whitelist","blacklist"')
@property
def needstickers(self) -> bool:
"""
@@ -257,7 +262,7 @@ class RemotePairList(IPairList):
if self._mode == "whitelist":
merged_list = pairlist + rpl_pairlist
merged_list = sorted(set(merged_list), key=merged_list.index)
elif self._mode == "blacklist":
else:
for pair in pairlist:
if pair not in rpl_pairlist:
merged_list.append(pair)
@@ -266,10 +271,5 @@ class RemotePairList(IPairList):
if filtered:
self.log_once(f"Blacklist - Filtered out pairs: {filtered}", logger.info)
else:
raise OperationalException(
'`mode` not configured correctly. Supported Modes: '
'are "whitelist","blacklist"')
merged_list = merged_list[:self._number_pairs]
return merged_list

View File

@@ -16,11 +16,12 @@ def rpl_config(default_conf):
default_conf['exchange']['pair_whitelist'] = [
'ETH/USDT',
'BTC/USDT',
'XRP/USDT',
]
default_conf['exchange']['pair_blacklist'] = [
'BLK/USDT'
]
return default_conf
@@ -183,3 +184,67 @@ def test_fetch_pairlist_mock_response_valid(mocker, rpl_config):
assert pairs == ["ETH/USDT", "XRP/USDT", "LTC/USDT", "EOS/USDT"]
assert time_elapsed == 0.4
assert remote_pairlist._refresh_period == 60
def test_remote_pairlist_init_wrong_mode(mocker, rpl_config):
rpl_config['pairlists'] = [
{
"method": "RemotePairList",
"mode": "blacklis",
"number_assets": 20,
"pairlist_url": "http://example.com/pairlist",
"keep_pairlist_on_failure": True,
}
]
get_patched_exchange(mocker, rpl_config)
with pytest.raises(OperationalException, match=r'`mode` not configured correctly.'
r' Supported Modes are "whitelist","blacklist"'):
get_patched_freqtradebot(mocker, rpl_config)
def test_remote_pairlist_blacklist(mocker, rpl_config, caplog):
mock_response = MagicMock()
mock_response.json.return_value = {
"pairs": ["XRP/USDT"],
"refresh_period": 60
}
mock_response.headers = {
"content-type": "application/json"
}
rpl_config['pairlists'] = [
{
"method": "RemotePairList",
"mode": "blacklist",
"pairlist_url": "http://example.com/pairlist",
"number_assets": 3
}
]
mocker.patch("freqtrade.plugins.pairlist.RemotePairList.requests.get",
return_value=mock_response)
exchange = get_patched_exchange(mocker, rpl_config)
freqtrade = get_patched_freqtradebot(mocker, rpl_config)
freqtrade.pairlists.refresh_pairlist()
whitelist = freqtrade.pairlists.whitelist
pairlistmanager = PairListManager(exchange, rpl_config)
remote_pairlist = RemotePairList(exchange, pairlistmanager, rpl_config,
rpl_config['pairlists'][0], 0)
pairs, time_elapsed = remote_pairlist.fetch_pairlist()
assert pairs == ["XRP/USDT"]
whitelist = remote_pairlist.filter_pairlist(["XRP/USDT", "ETH/USDT"], {})
assert whitelist == ["ETH/USDT"]
assert log_has(f"Blacklist - Filtered out pairs: {pairs}", caplog)