add unit test to function get_valid_price

This commit is contained in:
axel 2021-08-12 15:30:49 -04:00
parent b098ce4e76
commit dbf7f34ecb
2 changed files with 31 additions and 3 deletions

View File

@ -1399,9 +1399,13 @@ class FreqtradeBot(LoggingMixin):
Check if the custom price is of the good type if not return proposed_price Check if the custom price is of the good type if not return proposed_price
:return: valid price for the order :return: valid price for the order
""" """
if custom_price and (isinstance(custom_price, int) if custom_price:
or isinstance(custom_price, float)): if isinstance(custom_price, int):
valid_price = custom_price valid_price = float(custom_price)
elif isinstance(custom_price, float):
valid_price = custom_price
else:
valid_price = proposed_price
else: else:
valid_price = proposed_price valid_price = proposed_price

View File

@ -4588,3 +4588,27 @@ def test_refind_lost_order(mocker, default_conf, fee, caplog):
freqtrade.refind_lost_order(trades[4]) freqtrade.refind_lost_order(trades[4])
assert log_has(f"Error updating {order['id']}.", caplog) assert log_has(f"Error updating {order['id']}.", caplog)
def test_get_valid_price(mocker, default_conf) -> None:
patch_RPCManager(mocker)
patch_exchange(mocker)
freqtrade = FreqtradeBot(default_conf)
custom_price_string = "10"
custom_price_float = 10.0
custom_price_int = 10
proposed_price = 12.2
valid_price_from_string = freqtrade.get_valid_price(custom_price_string, proposed_price)
valid_price_from_int = freqtrade.get_valid_price(custom_price_int, proposed_price)
valid_price_from_float = freqtrade.get_valid_price(custom_price_float, proposed_price)
assert isinstance(valid_price_from_string, float)
assert isinstance(valid_price_from_int, float)
assert isinstance(valid_price_from_float, float)
assert valid_price_from_string == proposed_price
assert valid_price_from_int == custom_price_int
assert valid_price_from_float == custom_price_float