From 7e16a4e778d5fdc528fc5eee57f5fa48c6e5cd8e Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Fri, 28 Feb 2025 06:04:07 +0000 Subject: [PATCH] test_message_summary: Fix failing tests. Tests were failing due to credit usage being capture in the next month instead of current if the current time is last day of the month. To fix this, we mock current time to not be the last day of any month. --- zerver/tests/test_message_summary.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/zerver/tests/test_message_summary.py b/zerver/tests/test_message_summary.py index ab1c68e7e9..9dccff58cf 100644 --- a/zerver/tests/test_message_summary.py +++ b/zerver/tests/test_message_summary.py @@ -1,8 +1,10 @@ import os import warnings +from datetime import datetime, timezone from unittest import mock import orjson +import time_machine from django.conf import settings from typing_extensions import override @@ -44,12 +46,19 @@ class MessagesSummaryTestCase(ZulipTestCase): self.user, self.channel_name, content=content, topic_name=self.topic_name ) + # Tests fail on the last day of the month due to us capturing the credit usage for that day + # on the first of the next month, so we need to set the date to a different day. + not_last_day_of_any_month = datetime(2025, 2, 18, 1, tzinfo=timezone.utc) + + self.mocked_time_patcher = time_machine.travel(not_last_day_of_any_month, tick=False) + self.mocked_time_patcher.start() if settings.GENERATE_LITELLM_FIXTURES: # nocoverage self.patcher = mock.patch("litellm.completion", wraps=litellm.completion) self.mocked_completion = self.patcher.start() @override def tearDown(self) -> None: + self.mocked_time_patcher.stop() if settings.GENERATE_LITELLM_FIXTURES: # nocoverage self.patcher.stop() super().tearDown()