Update remaining tests to get rid of .query
This commit is contained in:
parent
9d6e973e5b
commit
4cfbc55d34
@ -406,8 +406,8 @@ def test_migrate_pairlocks(mocker, default_conf, fee, caplog):
|
|||||||
init_db(default_conf['db_url'])
|
init_db(default_conf['db_url'])
|
||||||
|
|
||||||
assert len(PairLock.get_all_locks().all()) == 2
|
assert len(PairLock.get_all_locks().all()) == 2
|
||||||
assert len(PairLock.query.filter(PairLock.pair == '*').all()) == 1
|
assert len(PairLock.session.scalars(select(PairLock).filter(PairLock.pair == '*')).all()) == 1
|
||||||
pairlocks = PairLock.query.filter(PairLock.pair == 'ETH/BTC').all()
|
pairlocks = PairLock.session.scalars(select(PairLock).filter(PairLock.pair == 'ETH/BTC')).all()
|
||||||
assert len(pairlocks) == 1
|
assert len(pairlocks) == 1
|
||||||
pairlocks[0].pair == 'ETH/BTC'
|
pairlocks[0].pair == 'ETH/BTC'
|
||||||
pairlocks[0].side == '*'
|
pairlocks[0].side == '*'
|
||||||
|
@ -2017,6 +2017,7 @@ def test_Trade_object_idem():
|
|||||||
'get_open_trades_without_assigned_fees',
|
'get_open_trades_without_assigned_fees',
|
||||||
'get_open_order_trades',
|
'get_open_order_trades',
|
||||||
'get_trades',
|
'get_trades',
|
||||||
|
'get_trades_query',
|
||||||
'get_exit_reason_performance',
|
'get_exit_reason_performance',
|
||||||
'get_enter_tag_performance',
|
'get_enter_tag_performance',
|
||||||
'get_mix_tag_performance',
|
'get_mix_tag_performance',
|
||||||
|
@ -711,8 +711,8 @@ def test_PrecisionFilter_error(mocker, whitelist_conf) -> None:
|
|||||||
|
|
||||||
def test_PerformanceFilter_error(mocker, whitelist_conf, caplog) -> None:
|
def test_PerformanceFilter_error(mocker, whitelist_conf, caplog) -> None:
|
||||||
whitelist_conf['pairlists'] = [{"method": "StaticPairList"}, {"method": "PerformanceFilter"}]
|
whitelist_conf['pairlists'] = [{"method": "StaticPairList"}, {"method": "PerformanceFilter"}]
|
||||||
if hasattr(Trade, 'query'):
|
if hasattr(Trade, 'session'):
|
||||||
del Trade.query
|
del Trade.session
|
||||||
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
mocker.patch(f'{EXMS}.exchange_has', MagicMock(return_value=True))
|
||||||
exchange = get_patched_exchange(mocker, whitelist_conf)
|
exchange = get_patched_exchange(mocker, whitelist_conf)
|
||||||
pm = PairListManager(exchange, whitelist_conf, MagicMock())
|
pm = PairListManager(exchange, whitelist_conf, MagicMock())
|
||||||
|
@ -107,7 +107,7 @@ def test_PairLocks_getlongestlock(use_db):
|
|||||||
# No lock should be present
|
# No lock should be present
|
||||||
PairLocks.use_db = use_db
|
PairLocks.use_db = use_db
|
||||||
if use_db:
|
if use_db:
|
||||||
assert len(PairLock.query.all()) == 0
|
assert len(PairLock.get_all_locks().all()) == 0
|
||||||
|
|
||||||
assert PairLocks.use_db == use_db
|
assert PairLocks.use_db == use_db
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ def test_PairLocks_reason(use_db):
|
|||||||
PairLocks.use_db = use_db
|
PairLocks.use_db = use_db
|
||||||
# No lock should be present
|
# No lock should be present
|
||||||
if use_db:
|
if use_db:
|
||||||
assert len(PairLock.query.all()) == 0
|
assert len(PairLock.get_all_locks().all()) == 0
|
||||||
|
|
||||||
assert PairLocks.use_db == use_db
|
assert PairLocks.use_db == use_db
|
||||||
|
|
||||||
|
@ -2499,7 +2499,8 @@ def test_manage_open_orders_entry(
|
|||||||
freqtrade.manage_open_orders()
|
freqtrade.manage_open_orders()
|
||||||
assert cancel_order_mock.call_count == 1
|
assert cancel_order_mock.call_count == 1
|
||||||
assert rpc_mock.call_count == 2
|
assert rpc_mock.call_count == 2
|
||||||
trades = Trade.query.filter(Trade.open_order_id.is_(open_trade.open_order_id)).all()
|
trades = Trade.session.scalars(
|
||||||
|
select(Trade).filter(Trade.open_order_id.is_(open_trade.open_order_id))).all()
|
||||||
nb_trades = len(trades)
|
nb_trades = len(trades)
|
||||||
assert nb_trades == 0
|
assert nb_trades == 0
|
||||||
# Custom user buy-timeout is never called
|
# Custom user buy-timeout is never called
|
||||||
@ -2537,7 +2538,8 @@ def test_adjust_entry_cancel(
|
|||||||
# check that order is cancelled
|
# check that order is cancelled
|
||||||
freqtrade.strategy.adjust_entry_price = MagicMock(return_value=None)
|
freqtrade.strategy.adjust_entry_price = MagicMock(return_value=None)
|
||||||
freqtrade.manage_open_orders()
|
freqtrade.manage_open_orders()
|
||||||
trades = Trade.query.filter(Trade.open_order_id.is_(open_trade.open_order_id)).all()
|
trades = Trade.session.scalars(
|
||||||
|
select(Trade).filter(Trade.open_order_id.is_(open_trade.open_order_id))).all()
|
||||||
assert len(trades) == 0
|
assert len(trades) == 0
|
||||||
assert len(Order.session.scalars(select(Order)).all()) == 0
|
assert len(Order.session.scalars(select(Order)).all()) == 0
|
||||||
assert log_has_re(
|
assert log_has_re(
|
||||||
@ -2578,7 +2580,8 @@ def test_adjust_entry_maintain_replace(
|
|||||||
# Check that order is maintained
|
# Check that order is maintained
|
||||||
freqtrade.strategy.adjust_entry_price = MagicMock(return_value=old_order['price'])
|
freqtrade.strategy.adjust_entry_price = MagicMock(return_value=old_order['price'])
|
||||||
freqtrade.manage_open_orders()
|
freqtrade.manage_open_orders()
|
||||||
trades = Trade.query.filter(Trade.open_order_id.is_(open_trade.open_order_id)).all()
|
trades = Trade.session.scalars(
|
||||||
|
select(Trade).filter(Trade.open_order_id.is_(open_trade.open_order_id))).all()
|
||||||
assert len(trades) == 1
|
assert len(trades) == 1
|
||||||
assert len(Order.get_open_orders()) == 1
|
assert len(Order.get_open_orders()) == 1
|
||||||
# Entry adjustment is called
|
# Entry adjustment is called
|
||||||
@ -2588,7 +2591,8 @@ def test_adjust_entry_maintain_replace(
|
|||||||
freqtrade.get_valid_enter_price_and_stake = MagicMock(return_value={100, 10, 1})
|
freqtrade.get_valid_enter_price_and_stake = MagicMock(return_value={100, 10, 1})
|
||||||
freqtrade.strategy.adjust_entry_price = MagicMock(return_value=1234)
|
freqtrade.strategy.adjust_entry_price = MagicMock(return_value=1234)
|
||||||
freqtrade.manage_open_orders()
|
freqtrade.manage_open_orders()
|
||||||
trades = Trade.query.filter(Trade.open_order_id.is_(open_trade.open_order_id)).all()
|
trades = Trade.session.scalars(
|
||||||
|
select(Trade).filter(Trade.open_order_id.is_(open_trade.open_order_id))).all()
|
||||||
assert len(trades) == 1
|
assert len(trades) == 1
|
||||||
nb_all_orders = len(Order.session.scalars(select(Order)).all())
|
nb_all_orders = len(Order.session.scalars(select(Order)).all())
|
||||||
assert nb_all_orders == 2
|
assert nb_all_orders == 2
|
||||||
@ -2629,7 +2633,8 @@ def test_check_handle_cancelled_buy(
|
|||||||
freqtrade.manage_open_orders()
|
freqtrade.manage_open_orders()
|
||||||
assert cancel_order_mock.call_count == 0
|
assert cancel_order_mock.call_count == 0
|
||||||
assert rpc_mock.call_count == 2
|
assert rpc_mock.call_count == 2
|
||||||
trades = Trade.query.filter(Trade.open_order_id.is_(open_trade.open_order_id)).all()
|
trades = Trade.session.scalars(
|
||||||
|
select(Trade).filter(Trade.open_order_id.is_(open_trade.open_order_id))).all()
|
||||||
assert len(trades) == 0
|
assert len(trades) == 0
|
||||||
assert log_has_re(
|
assert log_has_re(
|
||||||
f"{'Sell' if is_short else 'Buy'} order cancelled on exchange for Trade.*", caplog)
|
f"{'Sell' if is_short else 'Buy'} order cancelled on exchange for Trade.*", caplog)
|
||||||
@ -2660,7 +2665,8 @@ def test_manage_open_orders_buy_exception(
|
|||||||
freqtrade.manage_open_orders()
|
freqtrade.manage_open_orders()
|
||||||
assert cancel_order_mock.call_count == 0
|
assert cancel_order_mock.call_count == 0
|
||||||
assert rpc_mock.call_count == 1
|
assert rpc_mock.call_count == 1
|
||||||
trades = Trade.query.filter(Trade.open_order_id.is_(open_trade.open_order_id)).all()
|
trades = Trade.session.scalars(
|
||||||
|
select(Trade).filter(Trade.open_order_id.is_(open_trade.open_order_id))).all()
|
||||||
nb_trades = len(trades)
|
nb_trades = len(trades)
|
||||||
assert nb_trades == 1
|
assert nb_trades == 1
|
||||||
|
|
||||||
@ -2860,7 +2866,8 @@ def test_manage_open_orders_partial(
|
|||||||
freqtrade.manage_open_orders()
|
freqtrade.manage_open_orders()
|
||||||
assert cancel_order_mock.call_count == 1
|
assert cancel_order_mock.call_count == 1
|
||||||
assert rpc_mock.call_count == 3
|
assert rpc_mock.call_count == 3
|
||||||
trades = Trade.query.filter(Trade.open_order_id.is_(open_trade.open_order_id)).all()
|
trades = Trade.session.scalars(
|
||||||
|
select(Trade).filter(Trade.open_order_id.is_(open_trade.open_order_id))).all()
|
||||||
assert len(trades) == 1
|
assert len(trades) == 1
|
||||||
assert trades[0].amount == 23.0
|
assert trades[0].amount == 23.0
|
||||||
assert trades[0].stake_amount == open_trade.open_rate * trades[0].amount / leverage
|
assert trades[0].stake_amount == open_trade.open_rate * trades[0].amount / leverage
|
||||||
@ -2907,7 +2914,8 @@ def test_manage_open_orders_partial_fee(
|
|||||||
|
|
||||||
assert cancel_order_mock.call_count == 1
|
assert cancel_order_mock.call_count == 1
|
||||||
assert rpc_mock.call_count == 3
|
assert rpc_mock.call_count == 3
|
||||||
trades = Trade.query.filter(Trade.open_order_id.is_(open_trade.open_order_id)).all()
|
trades = Trade.session.scalars(
|
||||||
|
select(Trade).filter(Trade.open_order_id.is_(open_trade.open_order_id))).all()
|
||||||
assert len(trades) == 1
|
assert len(trades) == 1
|
||||||
# Verify that trade has been updated
|
# Verify that trade has been updated
|
||||||
assert trades[0].amount == (limit_buy_order_old_partial['amount'] -
|
assert trades[0].amount == (limit_buy_order_old_partial['amount'] -
|
||||||
@ -2957,7 +2965,8 @@ def test_manage_open_orders_partial_except(
|
|||||||
|
|
||||||
assert cancel_order_mock.call_count == 1
|
assert cancel_order_mock.call_count == 1
|
||||||
assert rpc_mock.call_count == 3
|
assert rpc_mock.call_count == 3
|
||||||
trades = Trade.query.filter(Trade.open_order_id.is_(open_trade.open_order_id)).all()
|
trades = Trade.session.scalars(
|
||||||
|
select(Trade).filter(Trade.open_order_id.is_(open_trade.open_order_id))).all()
|
||||||
assert len(trades) == 1
|
assert len(trades) == 1
|
||||||
# Verify that trade has been updated
|
# Verify that trade has been updated
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user