Test /monthly & clean
Signed-off-by: Antoine Merino <antoine.merino.dev@gmail.com>
This commit is contained in:
parent
87634f0409
commit
70253258f0
@ -358,7 +358,7 @@ class RPC:
|
|||||||
|
|
||||||
data = [
|
data = [
|
||||||
{
|
{
|
||||||
'date': f"{key.year}-{key.month}",
|
'date': f"{key.year}-{key.month:02d}",
|
||||||
'abs_profit': value["amount"],
|
'abs_profit': value["amount"],
|
||||||
'fiat_value': self._fiat_converter.convert_amount(
|
'fiat_value': self._fiat_converter.convert_amount(
|
||||||
value['amount'],
|
value['amount'],
|
||||||
|
@ -12,7 +12,6 @@ from unittest.mock import ANY, MagicMock
|
|||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
import pytest
|
import pytest
|
||||||
from dateutil.relativedelta import relativedelta
|
|
||||||
from telegram import Chat, Message, ReplyKeyboardMarkup, Update
|
from telegram import Chat, Message, ReplyKeyboardMarkup, Update
|
||||||
from telegram.error import BadRequest, NetworkError, TelegramError
|
from telegram.error import BadRequest, NetworkError, TelegramError
|
||||||
|
|
||||||
@ -503,36 +502,15 @@ def test_weekly_handle(default_conf, update, ticker, limit_buy_order, fee,
|
|||||||
trade.close_date = datetime.utcnow()
|
trade.close_date = datetime.utcnow()
|
||||||
trade.is_open = False
|
trade.is_open = False
|
||||||
|
|
||||||
# Make like the first trade was open and closed more than 8 weeks ago
|
# /weekly 1
|
||||||
trades[0].open_date = datetime.utcnow() - timedelta(weeks=8, days=2)
|
|
||||||
trades[0].close_date = datetime.utcnow() - timedelta(weeks=8, days=1)
|
|
||||||
|
|
||||||
# /weekly
|
|
||||||
# By default, the 8 previous weeks are shown
|
# By default, the 8 previous weeks are shown
|
||||||
# So the previous modified trade should be excluded from the stats
|
# So the previous modified trade should be excluded from the stats
|
||||||
context = MagicMock()
|
context = MagicMock()
|
||||||
context.args = []
|
context.args = ["1"]
|
||||||
telegram._weekly(update=update, context=context)
|
telegram._weekly(update=update, context=context)
|
||||||
# assert str(' 0.00012434 BTC') in msg_mock.call_args_list[0][0][0]
|
assert str(' 0.00018651 BTC') in msg_mock.call_args_list[0][0][0]
|
||||||
# assert str(' 1.865 USD') in msg_mock.call_args_list[0][0][0]
|
assert str(' 2.798 USD') in msg_mock.call_args_list[0][0][0]
|
||||||
# assert str(' 2 trades') in msg_mock.call_args_list[0][0][0]
|
assert str(' 3 trades') in msg_mock.call_args_list[0][0][0]
|
||||||
|
|
||||||
# The time-shifted trade should not appear
|
|
||||||
assert str(' 0.00006217 BTC') not in msg_mock.call_args_list[0][0][0]
|
|
||||||
assert str(' 0.933 USD') not in msg_mock.call_args_list[0][0][0]
|
|
||||||
assert str(' 1 trades') not in msg_mock.call_args_list[0][0][0]
|
|
||||||
|
|
||||||
# Reset msg_mock
|
|
||||||
msg_mock.reset_mock()
|
|
||||||
context.args = ["10"]
|
|
||||||
telegram._weekly(update=update, context=context)
|
|
||||||
assert msg_mock.call_count == 1
|
|
||||||
assert "Weekly Profit over the last 10 weeks (starting from Monday)</b>:" \
|
|
||||||
in msg_mock.call_args_list[0][0][0]
|
|
||||||
# Now, the time-shifted trade should be included
|
|
||||||
assert str(' 0.00006217 BTC') in msg_mock.call_args_list[0][0][0]
|
|
||||||
assert str(' 0.933 USD') in msg_mock.call_args_list[0][0][0]
|
|
||||||
assert str(' 1 trades') in msg_mock.call_args_list[0][0][0]
|
|
||||||
|
|
||||||
|
|
||||||
def test_weekly_wrong_input(default_conf, update, ticker, mocker) -> None:
|
def test_weekly_wrong_input(default_conf, update, ticker, mocker) -> None:
|
||||||
@ -547,7 +525,7 @@ def test_weekly_wrong_input(default_conf, update, ticker, mocker) -> None:
|
|||||||
# Try invalid data
|
# Try invalid data
|
||||||
msg_mock.reset_mock()
|
msg_mock.reset_mock()
|
||||||
freqtradebot.state = State.RUNNING
|
freqtradebot.state = State.RUNNING
|
||||||
# /daily -2
|
# /weekly -3
|
||||||
context = MagicMock()
|
context = MagicMock()
|
||||||
context.args = ["-3"]
|
context.args = ["-3"]
|
||||||
telegram._weekly(update=update, context=context)
|
telegram._weekly(update=update, context=context)
|
||||||
@ -617,6 +595,7 @@ def test_monthly_handle(default_conf, update, ticker, limit_buy_order, fee,
|
|||||||
context.args = []
|
context.args = []
|
||||||
telegram._monthly(update=update, context=context)
|
telegram._monthly(update=update, context=context)
|
||||||
assert msg_mock.call_count == 1
|
assert msg_mock.call_count == 1
|
||||||
|
# Default to 6 months
|
||||||
assert 'Monthly Profit over the last 6 months</b>:' in msg_mock.call_args_list[0][0][0]
|
assert 'Monthly Profit over the last 6 months</b>:' in msg_mock.call_args_list[0][0][0]
|
||||||
assert 'Month ' in msg_mock.call_args_list[0][0][0]
|
assert 'Month ' in msg_mock.call_args_list[0][0][0]
|
||||||
assert current_month in msg_mock.call_args_list[0][0][0]
|
assert current_month in msg_mock.call_args_list[0][0][0]
|
||||||
@ -639,35 +618,19 @@ def test_monthly_handle(default_conf, update, ticker, limit_buy_order, fee,
|
|||||||
trade.close_date = datetime.utcnow()
|
trade.close_date = datetime.utcnow()
|
||||||
trade.is_open = False
|
trade.is_open = False
|
||||||
|
|
||||||
# Make like the first trade was open and closed more than 6 months ago
|
# /monthly 12
|
||||||
trades[0].open_date = datetime.utcnow() - relativedelta(months=6, days=5)
|
|
||||||
trades[0].close_date = datetime.utcnow() - relativedelta(months=6, days=3)
|
|
||||||
|
|
||||||
# /monthly
|
|
||||||
# By default, the 6 previous months are shown
|
|
||||||
# So the previous modified trade should be excluded from the stats
|
|
||||||
context = MagicMock()
|
context = MagicMock()
|
||||||
context.args = []
|
context.args = ["12"]
|
||||||
telegram._monthly(update=update, context=context)
|
|
||||||
# assert str(' 0.00012434 BTC') in msg_mock.call_args_list[0][0][0]
|
|
||||||
# assert str(' 1.865 USD') in msg_mock.call_args_list[0][0][0]
|
|
||||||
# assert str(' 2 trades') in msg_mock.call_args_list[0][0][0]
|
|
||||||
|
|
||||||
# The time-shifted trade should not appear
|
|
||||||
assert str(' 0.00006217 BTC') not in msg_mock.call_args_list[0][0][0]
|
|
||||||
assert str(' 0.933 USD') not in msg_mock.call_args_list[0][0][0]
|
|
||||||
assert str(' 1 trades') not in msg_mock.call_args_list[0][0][0]
|
|
||||||
|
|
||||||
# Reset msg_mock
|
|
||||||
msg_mock.reset_mock()
|
|
||||||
context.args = ["8"]
|
|
||||||
telegram._monthly(update=update, context=context)
|
telegram._monthly(update=update, context=context)
|
||||||
assert msg_mock.call_count == 1
|
assert msg_mock.call_count == 1
|
||||||
|
assert 'Monthly Profit over the last 12 months</b>:' in msg_mock.call_args_list[0][0][0]
|
||||||
|
assert str(' 0.00018651 BTC') in msg_mock.call_args_list[0][0][0]
|
||||||
|
assert str(' 2.798 USD') in msg_mock.call_args_list[0][0][0]
|
||||||
|
assert str(' 3 trades') in msg_mock.call_args_list[0][0][0]
|
||||||
|
|
||||||
# Now, the time-shifted trade should be included
|
# The one-digit months should contain a zero, Eg: September 2021 = "2021-09"
|
||||||
assert str(' 0.00006217 BTC') in msg_mock.call_args_list[0][0][0]
|
# Since we loaded the last 12 months, any month should appear
|
||||||
assert str(' 0.933 USD') in msg_mock.call_args_list[0][0][0]
|
assert str('-09') in msg_mock.call_args_list[0][0][0]
|
||||||
assert str(' 1 trades') in msg_mock.call_args_list[0][0][0]
|
|
||||||
|
|
||||||
|
|
||||||
def test_monthly_wrong_input(default_conf, update, ticker, mocker) -> None:
|
def test_monthly_wrong_input(default_conf, update, ticker, mocker) -> None:
|
||||||
@ -682,7 +645,7 @@ def test_monthly_wrong_input(default_conf, update, ticker, mocker) -> None:
|
|||||||
# Try invalid data
|
# Try invalid data
|
||||||
msg_mock.reset_mock()
|
msg_mock.reset_mock()
|
||||||
freqtradebot.state = State.RUNNING
|
freqtradebot.state = State.RUNNING
|
||||||
# /daily -2
|
# /monthly -3
|
||||||
context = MagicMock()
|
context = MagicMock()
|
||||||
context.args = ["-3"]
|
context.args = ["-3"]
|
||||||
telegram._monthly(update=update, context=context)
|
telegram._monthly(update=update, context=context)
|
||||||
|
Loading…
Reference in New Issue
Block a user