Change trades-test2 to better test correct behaviour
This commit is contained in:
parent
bf182dc01e
commit
4f126bea35
@ -1718,8 +1718,8 @@ async def test__async_fetch_trades(default_conf, mocker, caplog, exchange_name,
|
|||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
||||||
async def test__async_get_trade_history_id(default_conf, mocker, caplog, exchange_name,
|
async def test__async_get_trade_history_id(default_conf, mocker, exchange_name,
|
||||||
trades_history):
|
fetch_trades_result):
|
||||||
|
|
||||||
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
|
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
|
||||||
pagination_arg = exchange._trades_pagination_arg
|
pagination_arg = exchange._trades_pagination_arg
|
||||||
@ -1727,28 +1727,29 @@ async def test__async_get_trade_history_id(default_conf, mocker, caplog, exchang
|
|||||||
async def mock_get_trade_hist(pair, *args, **kwargs):
|
async def mock_get_trade_hist(pair, *args, **kwargs):
|
||||||
if 'since' in kwargs:
|
if 'since' in kwargs:
|
||||||
# Return first 3
|
# Return first 3
|
||||||
return trades_history[:-2]
|
return fetch_trades_result[:-2]
|
||||||
elif kwargs.get('params', {}).get(pagination_arg) == trades_history[-3][1]:
|
elif kwargs.get('params', {}).get(pagination_arg) == fetch_trades_result[-3]['id']:
|
||||||
# Return 2
|
# Return 2
|
||||||
return trades_history[-3:-1]
|
return fetch_trades_result[-3:-1]
|
||||||
else:
|
else:
|
||||||
# Return last 2
|
# Return last 2
|
||||||
return trades_history[-2:]
|
return fetch_trades_result[-2:]
|
||||||
# Monkey-patch async function
|
# Monkey-patch async function
|
||||||
exchange._async_fetch_trades = MagicMock(side_effect=mock_get_trade_hist)
|
exchange._api_async.fetch_trades = MagicMock(side_effect=mock_get_trade_hist)
|
||||||
|
|
||||||
pair = 'ETH/BTC'
|
pair = 'ETH/BTC'
|
||||||
ret = await exchange._async_get_trade_history_id(pair, since=trades_history[0][0],
|
ret = await exchange._async_get_trade_history_id(pair,
|
||||||
until=trades_history[-1][0]-1)
|
since=fetch_trades_result[0]['timestamp'],
|
||||||
|
until=fetch_trades_result[-1]['timestamp'] - 1)
|
||||||
assert type(ret) is tuple
|
assert type(ret) is tuple
|
||||||
assert ret[0] == pair
|
assert ret[0] == pair
|
||||||
assert type(ret[1]) is list
|
assert type(ret[1]) is list
|
||||||
assert len(ret[1]) == len(trades_history)
|
assert len(ret[1]) == len(fetch_trades_result)
|
||||||
assert exchange._async_fetch_trades.call_count == 3
|
assert exchange._api_async.fetch_trades.call_count == 3
|
||||||
fetch_trades_cal = exchange._async_fetch_trades.call_args_list
|
fetch_trades_cal = exchange._api_async.fetch_trades.call_args_list
|
||||||
# first call (using since, not fromId)
|
# first call (using since, not fromId)
|
||||||
assert fetch_trades_cal[0][0][0] == pair
|
assert fetch_trades_cal[0][0][0] == pair
|
||||||
assert fetch_trades_cal[0][1]['since'] == trades_history[0][0]
|
assert fetch_trades_cal[0][1]['since'] == fetch_trades_result[0]['timestamp']
|
||||||
|
|
||||||
# 2nd call
|
# 2nd call
|
||||||
assert fetch_trades_cal[1][0][0] == pair
|
assert fetch_trades_cal[1][0][0] == pair
|
||||||
|
Loading…
Reference in New Issue
Block a user