From 54858a0bbba9f3481cd6238bfadeaace71d5c481 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 27 Dec 2021 16:39:47 +0100 Subject: [PATCH] Simplify test to only initialize and mock once. --- tests/exchange/test_exchange.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index be3f9e879..7bd62c838 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -1745,21 +1745,20 @@ async def test__async_get_candle_history(default_conf, mocker, caplog, exchange_ async def test__async_kucoin_get_candle_history(default_conf, mocker, caplog): caplog.set_level(logging.INFO) api_mock = MagicMock() + api_mock.fetch_ohlcv = MagicMock(side_effect=ccxt.DDoSProtection( + "kucoin GET https://openapi-v2.kucoin.com/api/v1/market/candles?" + "symbol=ETH-BTC&type=5min&startAt=1640268735&endAt=1640418735" + "429 Too Many Requests" '{"code":"429000","msg":"Too Many Requests"}')) + exchange = get_patched_exchange(mocker, default_conf, api_mock, id="kucoin") - assert not log_contains('Kucoin 429 error, avoid triggering DDosProtection backoff delay', - caplog) + msg = "Kucoin 429 error, avoid triggering DDosProtection backoff delay" + assert not log_contains(msg, caplog) for _ in range(3): with pytest.raises(DDosProtection, match=r'429 Too Many Requests'): - api_mock.fetch_ohlcv = MagicMock(side_effect=ccxt.DDoSProtection( - "kucoin GET https://openapi-v2.kucoin.com/api/v1/market/candles?" - "symbol=ETH-BTC&type=5min&startAt=1640268735&endAt=1640418735" - "429 Too Many Requests" '{"code":"429000","msg":"Too Many Requests"}')) - exchange = get_patched_exchange(mocker, default_conf, api_mock, id="kucoin") await exchange._async_get_candle_history( - 'ETH/BTC', "5m", (arrow.utcnow().int_timestamp - 2000) * 1000, count=1) - assert num_log_contains("Kucoin 429 error, avoid triggering DDosProtection backoff delay", - caplog) == 1 + "ETH/BTC", "5m", (arrow.utcnow().int_timestamp - 2000) * 1000, count=1) + assert num_log_contains(msg, caplog) == 1 @pytest.mark.asyncio