Add tests for cancel_order_with_result
This commit is contained in:
@@ -1759,6 +1759,40 @@ def test_is_cancel_order_result_suitable(mocker, default_conf, exchange_name, or
|
||||
exchange = get_patched_exchange(mocker, default_conf, id=exchange_name)
|
||||
assert exchange.is_cancel_order_result_suitable(order) == result
|
||||
|
||||
|
||||
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
||||
@pytest.mark.parametrize("corder,call_corder,call_forder", [
|
||||
({'status': 'closed', 'amount': 10, 'fee': {}}, 1, 0),
|
||||
({'amount': 10, 'fee': {}}, 1, 1),
|
||||
])
|
||||
def test_cancel_order_with_result(default_conf, mocker, exchange_name, corder,
|
||||
call_corder, call_forder):
|
||||
default_conf['dry_run'] = False
|
||||
api_mock = MagicMock()
|
||||
api_mock.cancel_order = MagicMock(return_value=corder)
|
||||
api_mock.fetch_order = MagicMock(return_value={})
|
||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||
res = exchange.cancel_order_with_result('1234', 'ETH/BTC', 1234)
|
||||
assert isinstance(res, dict)
|
||||
assert api_mock.cancel_order.call_count == call_corder
|
||||
assert api_mock.fetch_order.call_count == call_forder
|
||||
|
||||
|
||||
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
||||
def test_cancel_order_with_result_error(default_conf, mocker, exchange_name, caplog):
|
||||
default_conf['dry_run'] = False
|
||||
api_mock = MagicMock()
|
||||
api_mock.cancel_order = MagicMock(side_effect=ccxt.InvalidOrder("Did not find order"))
|
||||
api_mock.fetch_order = MagicMock(side_effect=ccxt.InvalidOrder("Did not find order"))
|
||||
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||
|
||||
res = exchange.cancel_order_with_result('1234', 'ETH/BTC', 1541)
|
||||
assert isinstance(res, dict)
|
||||
assert log_has("Could not cancel order 1234.", caplog)
|
||||
assert log_has("Could not fetch cancelled order 1234.", caplog)
|
||||
assert res['amount'] == 1541
|
||||
|
||||
|
||||
# Ensure that if not dry_run, we should call API
|
||||
@pytest.mark.parametrize("exchange_name", EXCHANGES)
|
||||
def test_cancel_order(default_conf, mocker, exchange_name):
|
||||
|
Reference in New Issue
Block a user