Skip to content

Commit b8b94d5

Browse files
committed
test: update tests for new reload_markets behavior
1 parent 33b5482 commit b8b94d5

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

tests/exchange/test_exchange.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,8 @@ def test__load_markets(default_conf, mocker, caplog):
590590

591591
expected_return = {"ETH/BTC": "available"}
592592
api_mock = MagicMock()
593-
api_mock.load_markets = get_mock_coro(return_value=expected_return)
593+
api_mock.load_markets = get_mock_coro()
594+
api_mock.markets = expected_return
594595
mocker.patch(f"{EXMS}._init_ccxt", MagicMock(return_value=api_mock))
595596
default_conf["exchange"]["pair_whitelist"] = ["ETH/BTC"]
596597
ex = Exchange(default_conf)
@@ -606,6 +607,7 @@ def test_reload_markets(default_conf, mocker, caplog, time_machine):
606607
time_machine.move_to(start_dt, tick=False)
607608
api_mock = MagicMock()
608609
api_mock.load_markets = get_mock_coro(return_value=initial_markets)
610+
api_mock.markets = initial_markets
609611
default_conf["exchange"]["markets_refresh_interval"] = 10
610612
exchange = get_patched_exchange(
611613
mocker, default_conf, api_mock, exchange="binance", mock_markets=False
@@ -624,6 +626,7 @@ def test_reload_markets(default_conf, mocker, caplog, time_machine):
624626
api_mock.load_markets = get_mock_coro(return_value=updated_markets)
625627
# more than 10 minutes have passed, reload is executed
626628
time_machine.move_to(start_dt + timedelta(minutes=11), tick=False)
629+
api_mock.markets = updated_markets
627630
exchange.reload_markets()
628631
assert exchange.markets == updated_markets
629632
assert lam_spy.call_count == 1
@@ -669,34 +672,33 @@ def test_reload_markets_exception(default_conf, mocker, caplog):
669672

670673

671674
@pytest.mark.parametrize("stake_currency", ["ETH", "BTC", "USDT"])
672-
def test_validate_stakecurrency(default_conf, stake_currency, mocker, caplog):
675+
def test_validate_stakecurrency(default_conf, stake_currency, mocker):
673676
default_conf["stake_currency"] = stake_currency
674677
api_mock = MagicMock()
675-
type(api_mock).load_markets = get_mock_coro(
676-
return_value={
677-
"ETH/BTC": {"quote": "BTC"},
678-
"LTC/BTC": {"quote": "BTC"},
679-
"XRP/ETH": {"quote": "ETH"},
680-
"NEO/USDT": {"quote": "USDT"},
681-
}
682-
)
678+
api_mock.load_markets = get_mock_coro()
679+
api_mock.markets = {
680+
"ETH/BTC": {"quote": "BTC"},
681+
"LTC/BTC": {"quote": "BTC"},
682+
"XRP/ETH": {"quote": "ETH"},
683+
"NEO/USDT": {"quote": "USDT"},
684+
}
683685
mocker.patch(f"{EXMS}._init_ccxt", MagicMock(return_value=api_mock))
684686
mocker.patch(f"{EXMS}.validate_timeframes")
685687
mocker.patch(f"{EXMS}.validate_pricing")
686688
Exchange(default_conf)
687689

688690

689-
def test_validate_stakecurrency_error(default_conf, mocker, caplog):
691+
def test_validate_stakecurrency_error(default_conf, mocker):
690692
default_conf["stake_currency"] = "XRP"
691693
api_mock = MagicMock()
692-
type(api_mock).load_markets = get_mock_coro(
693-
return_value={
694-
"ETH/BTC": {"quote": "BTC"},
695-
"LTC/BTC": {"quote": "BTC"},
696-
"XRP/ETH": {"quote": "ETH"},
697-
"NEO/USDT": {"quote": "USDT"},
698-
}
699-
)
694+
api_mock.load_markets = get_mock_coro()
695+
api_mock.markets = {
696+
"ETH/BTC": {"quote": "BTC"},
697+
"LTC/BTC": {"quote": "BTC"},
698+
"XRP/ETH": {"quote": "ETH"},
699+
"NEO/USDT": {"quote": "USDT"},
700+
}
701+
700702
mocker.patch(f"{EXMS}._init_ccxt", MagicMock(return_value=api_mock))
701703
mocker.patch(f"{EXMS}.validate_timeframes")
702704
with pytest.raises(
@@ -705,7 +707,7 @@ def test_validate_stakecurrency_error(default_conf, mocker, caplog):
705707
):
706708
Exchange(default_conf)
707709

708-
type(api_mock).load_markets = get_mock_coro(side_effect=ccxt.NetworkError("No connection."))
710+
api_mock.load_markets = get_mock_coro(side_effect=ccxt.NetworkError("No connection."))
709711
mocker.patch(f"{EXMS}._init_ccxt", MagicMock(return_value=api_mock))
710712

711713
with pytest.raises(

0 commit comments

Comments
 (0)