diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 1882e09c4..92d152c83 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -6,7 +6,7 @@ import asyncio import logging import re import threading -from datetime import datetime, timedelta, timezone +from datetime import timedelta from functools import reduce from random import choice, randint from string import ascii_uppercase @@ -16,7 +16,7 @@ import pytest import time_machine from pandas import DataFrame from sqlalchemy import select -from telegram import Chat, Message, ReplyKeyboardMarkup, Update +from telegram import Chat, Message, ReplyKeyboardMarkup, Update, User from telegram.error import BadRequest, NetworkError, TelegramError from freqtrade import __version__ @@ -67,7 +67,12 @@ def default_conf(default_conf) -> dict: @pytest.fixture def update(): - message = Message(0, datetime.now(timezone.utc), Chat(1235, 0)) + message = Message( + 0, + dt_now(), + Chat(1235, 0), + from_user=User(5432, "test", is_bot=False), + ) _update = Update(0, message=message) return _update @@ -232,8 +237,12 @@ async def test_authorized_only(default_conf, mocker, caplog, update) -> None: async def test_authorized_only_unauthorized(default_conf, mocker, caplog) -> None: patch_exchange(mocker) caplog.set_level(logging.DEBUG) - chat = Chat(0xDEADBEEF, 0) - message = Message(randint(1, 100), datetime.now(timezone.utc), chat) + message = Message( + randint(1, 100), + dt_now(), + Chat(0xDEADBEEF, 0), + from_user=User(5432, "test", is_bot=False), + ) update = Update(randint(1, 100), message=message) default_conf["telegram"]["enabled"] = False @@ -638,7 +647,7 @@ async def test_daily_handle(default_conf_usdt, update, ticker, fee, mocker, time assert msg_mock.call_count == 1 assert "Daily Profit over the last 2 days:" in msg_mock.call_args_list[0][0][0] assert "Day " in msg_mock.call_args_list[0][0][0] - assert str(datetime.now(timezone.utc).date()) in msg_mock.call_args_list[0][0][0] + assert str(dt_now().date()) in msg_mock.call_args_list[0][0][0] assert " 6.83 USDT" in msg_mock.call_args_list[0][0][0] assert " 7.51 USD" in msg_mock.call_args_list[0][0][0] assert "(2)" in msg_mock.call_args_list[0][0][0] @@ -651,11 +660,8 @@ async def test_daily_handle(default_conf_usdt, update, ticker, fee, mocker, time await telegram._daily(update=update, context=context) assert msg_mock.call_count == 1 assert "Daily Profit over the last 7 days:" in msg_mock.call_args_list[0][0][0] - assert str(datetime.now(timezone.utc).date()) in msg_mock.call_args_list[0][0][0] - assert ( - str((datetime.now(timezone.utc) - timedelta(days=5)).date()) - in msg_mock.call_args_list[0][0][0] - ) + assert str(dt_now().date()) in msg_mock.call_args_list[0][0][0] + assert str((dt_now() - timedelta(days=5)).date()) in msg_mock.call_args_list[0][0][0] assert " 6.83 USDT" in msg_mock.call_args_list[0][0][0] assert " 7.51 USD" in msg_mock.call_args_list[0][0][0] assert "(2)" in msg_mock.call_args_list[0][0][0] @@ -725,7 +731,7 @@ async def test_weekly_handle(default_conf_usdt, update, ticker, fee, mocker, tim in msg_mock.call_args_list[0][0][0] ) assert "Monday " in msg_mock.call_args_list[0][0][0] - today = datetime.now(timezone.utc).date() + today = dt_now().date() first_iso_day_of_current_week = today - timedelta(days=today.weekday()) assert str(first_iso_day_of_current_week) in msg_mock.call_args_list[0][0][0] assert " 2.74 USDT" in msg_mock.call_args_list[0][0][0] @@ -793,7 +799,7 @@ async def test_monthly_handle(default_conf_usdt, update, ticker, fee, mocker, ti assert msg_mock.call_count == 1 assert "Monthly Profit over the last 2 months:" in msg_mock.call_args_list[0][0][0] assert "Month " in msg_mock.call_args_list[0][0][0] - today = datetime.now(timezone.utc).date() + today = dt_now().date() current_month = f"{today.year}-{today.month:02} " assert current_month in msg_mock.call_args_list[0][0][0] assert " 2.74 USDT" in msg_mock.call_args_list[0][0][0] @@ -898,7 +904,7 @@ async def test_telegram_profit_handle( trade.orders.append(oobj) trade.update_trade(oobj) - trade.close_date = datetime.now(timezone.utc) + trade.close_date = dt_now() trade.is_open = False Trade.commit()