Update tests to test forceenter endpoint

This commit is contained in:
Matthias 2022-01-26 19:24:01 +01:00
parent 48d8cd82af
commit be7ce208dc
5 changed files with 19 additions and 14 deletions

View File

@ -19,6 +19,6 @@ class SignalTagType(Enum):
EXIT_TAG = "exit_tag" EXIT_TAG = "exit_tag"
class SignalDirection(Enum): class SignalDirection(str, Enum):
LONG = 'long' LONG = 'long'
SHORT = 'short' SHORT = 'short'

View File

@ -136,7 +136,8 @@ def show_config(rpc: Optional[RPC] = Depends(get_rpc_optional), config=Depends(g
# /forcebuy is deprecated with short addition. use ForceEntry instead # /forcebuy is deprecated with short addition. use ForceEntry instead
@router.post(['/forceenter', '/forcebuy'], response_model=ForceEnterResponse, tags=['trading']) @router.post('/forceenter', response_model=ForceEnterResponse, tags=['trading'])
@router.post('/forcebuy', response_model=ForceEnterResponse, tags=['trading'])
def forceentry(payload: ForceEnterPayload, rpc: RPC = Depends(get_rpc)): def forceentry(payload: ForceEnterPayload, rpc: RPC = Depends(get_rpc)):
ordertype = payload.ordertype.value if payload.ordertype else None ordertype = payload.ordertype.value if payload.ordertype else None
stake_amount = payload.stakeamount if payload.stakeamount else None stake_amount = payload.stakeamount if payload.stakeamount else None

View File

@ -1090,7 +1090,7 @@ def test_rpc_count(mocker, default_conf, ticker, fee) -> None:
assert counts["current"] == 1 assert counts["current"] == 1
def test_rpcforcebuy(mocker, default_conf, ticker, fee, limit_buy_order_open) -> None: def test_rpc_forceentry(mocker, default_conf, ticker, fee, limit_buy_order_open) -> None:
default_conf['forcebuy_enable'] = True default_conf['forcebuy_enable'] = True
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock()) mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
buy_mm = MagicMock(return_value=limit_buy_order_open) buy_mm = MagicMock(return_value=limit_buy_order_open)
@ -1141,7 +1141,7 @@ def test_rpcforcebuy(mocker, default_conf, ticker, fee, limit_buy_order_open) ->
assert trade is None assert trade is None
def test_rpcforcebuy_stopped(mocker, default_conf) -> None: def test_rpc_forceentry_stopped(mocker, default_conf) -> None:
default_conf['forcebuy_enable'] = True default_conf['forcebuy_enable'] = True
default_conf['initial_state'] = 'stopped' default_conf['initial_state'] = 'stopped'
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock()) mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
@ -1154,14 +1154,14 @@ def test_rpcforcebuy_stopped(mocker, default_conf) -> None:
rpc._rpc_force_entry(pair, None) rpc._rpc_force_entry(pair, None)
def test_rpcforcebuy_disabled(mocker, default_conf) -> None: def test_rpc_forceentry_disabled(mocker, default_conf) -> None:
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock()) mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
freqtradebot = get_patched_freqtradebot(mocker, default_conf) freqtradebot = get_patched_freqtradebot(mocker, default_conf)
patch_get_signal(freqtradebot) patch_get_signal(freqtradebot)
rpc = RPC(freqtradebot) rpc = RPC(freqtradebot)
pair = 'ETH/BTC' pair = 'ETH/BTC'
with pytest.raises(RPCException, match=r'Forcebuy not enabled.'): with pytest.raises(RPCException, match=r'Forceentry not enabled.'):
rpc._rpc_force_entry(pair, None) rpc._rpc_force_entry(pair, None)

View File

@ -543,7 +543,7 @@ def test_api_show_config(botclient):
assert 'unfilledtimeout' in response assert 'unfilledtimeout' in response
assert 'version' in response assert 'version' in response
assert 'api_version' in response assert 'api_version' in response
assert 1.1 <= response['api_version'] <= 1.2 assert 2.1 <= response['api_version'] <= 2.2
def test_api_daily(botclient, mocker, ticker, fee, markets): def test_api_daily(botclient, mocker, ticker, fee, markets):
@ -1062,23 +1062,27 @@ def test_api_whitelist(botclient):
# TODO -lev: add test for forcebuy (short) when feature is supported # TODO -lev: add test for forcebuy (short) when feature is supported
def test_api_forcebuy(botclient, mocker, fee): @pytest.mark.parametrize('endpoint', [
'forcebuy',
'forceenter',
])
def test_api_forceentry(botclient, mocker, fee, endpoint):
ftbot, client = botclient ftbot, client = botclient
rc = client_post(client, f"{BASE_URI}/forcebuy", rc = client_post(client, f"{BASE_URI}/{endpoint}",
data='{"pair": "ETH/BTC"}') data='{"pair": "ETH/BTC"}')
assert_response(rc, 502) assert_response(rc, 502)
assert rc.json() == {"error": "Error querying /api/v1/forcebuy: Forcebuy not enabled."} assert rc.json() == {"error": f"Error querying /api/v1/{endpoint}: Forceentry not enabled."}
# enable forcebuy # enable forcebuy
ftbot.config['forcebuy_enable'] = True ftbot.config['forcebuy_enable'] = True
fbuy_mock = MagicMock(return_value=None) fbuy_mock = MagicMock(return_value=None)
mocker.patch("freqtrade.rpc.RPC._rpc_force_entry", fbuy_mock) mocker.patch("freqtrade.rpc.RPC._rpc_force_entry", fbuy_mock)
rc = client_post(client, f"{BASE_URI}/forcebuy", rc = client_post(client, f"{BASE_URI}/{endpoint}",
data='{"pair": "ETH/BTC"}') data='{"pair": "ETH/BTC"}')
assert_response(rc) assert_response(rc)
assert rc.json() == {"status": "Error buying pair ETH/BTC."} assert rc.json() == {"status": "Error entering long trade for pair ETH/BTC."}
# Test creating trade # Test creating trade
fbuy_mock = MagicMock(return_value=Trade( fbuy_mock = MagicMock(return_value=Trade(
@ -1101,7 +1105,7 @@ def test_api_forcebuy(botclient, mocker, fee):
)) ))
mocker.patch("freqtrade.rpc.RPC._rpc_force_entry", fbuy_mock) mocker.patch("freqtrade.rpc.RPC._rpc_force_entry", fbuy_mock)
rc = client_post(client, f"{BASE_URI}/forcebuy", rc = client_post(client, f"{BASE_URI}/{endpoint}",
data='{"pair": "ETH/BTC"}') data='{"pair": "ETH/BTC"}')
assert_response(rc) assert_response(rc)
assert rc.json() == { assert rc.json() == {

View File

@ -1175,7 +1175,7 @@ def test_forcebuy_handle_exception(default_conf, update, mocker) -> None:
telegram._forcebuy(update=update, context=MagicMock()) telegram._forcebuy(update=update, context=MagicMock())
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert msg_mock.call_args_list[0][0][0] == 'Forcebuy not enabled.' assert msg_mock.call_args_list[0][0][0] == 'Forceentry not enabled.'
def test_forcebuy_no_pair(default_conf, update, mocker) -> None: def test_forcebuy_no_pair(default_conf, update, mocker) -> None: