From d5499058562370ff62d301f13ec16c0e1458444b Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 20 Jan 2022 07:11:48 +0100 Subject: [PATCH] Api-backtest to test new functionality --- tests/rpc/test_rpc_apiserver.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index d6a58322a..207d80cef 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -1326,7 +1326,7 @@ def test_sysinfo(botclient): assert 'ram_pct' in result -def test_api_backtesting(botclient, mocker, fee, caplog): +def test_api_backtesting(botclient, mocker, fee, caplog, tmpdir): ftbot, client = botclient mocker.patch('freqtrade.exchange.Exchange.get_fee', fee) @@ -1347,6 +1347,11 @@ def test_api_backtesting(botclient, mocker, fee, caplog): assert result['status'] == 'reset' assert not result['running'] assert result['status_msg'] == 'Backtest reset' + ftbot.config['export'] = 'trades' + ftbot.config['backtest_cache'] = 'none' + ftbot.config['user_data_dir'] = Path(tmpdir) + ftbot.config['exportfilename'] = Path(tmpdir) / "backtest_results" + ftbot.config['exportfilename'].mkdir() # start backtesting data = { @@ -1421,6 +1426,14 @@ def test_api_backtesting(botclient, mocker, fee, caplog): rc = client_post(client, f"{BASE_URI}/backtest", data=json.dumps(data)) assert log_has("Backtesting caused an error: ", caplog) + ftbot.config['backtest_cache'] = 'day' + + # Rerun backtest (should get previous result) + rc = client_post(client, f"{BASE_URI}/backtest", data=json.dumps(data)) + assert_response(rc) + result = rc.json() + assert log_has_re('Reusing result of previous backtest.*', caplog) + # Delete backtesting to avoid leakage since the backtest-object may stick around. rc = client_delete(client, f"{BASE_URI}/backtest") assert_response(rc)