From 99133d92a75425eba791fd66c07418dbd721482c Mon Sep 17 00:00:00 2001 From: Jumana B Date: Mon, 6 Jan 2025 09:04:28 -0500 Subject: [PATCH] Fixed the send to get data for notification_count_for_the_year (#2029) * Fixed the send to get data for notification_count_for_the_year * fix * fix --- app/notify_client/notification_counts_client.py | 7 ++++--- tests/app/notify_client/test_notification_counts_client.py | 7 +++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/notify_client/notification_counts_client.py b/app/notify_client/notification_counts_client.py index d97511efd0..001a980b7a 100644 --- a/app/notify_client/notification_counts_client.py +++ b/app/notify_client/notification_counts_client.py @@ -1,5 +1,3 @@ -from datetime import datetime - from notifications_utils.clients.redis import ( email_daily_count_cache_key, sms_daily_count_cache_key, @@ -7,6 +5,7 @@ from app import redis_client, service_api_client, template_statistics_client from app.models.service import Service +from app.utils import get_current_financial_year class NotificationCounts: @@ -83,8 +82,10 @@ def get_limit_stats(self, service: Service): } """ + current_financial_year = get_current_financial_year() sent_today = self.get_all_notification_counts_for_today(service.id) - sent_thisyear = self.get_all_notification_counts_for_year(service.id, datetime.now().year) + # We are interested in getting data for the financial year, not the calendar year + sent_thisyear = self.get_all_notification_counts_for_year(service.id, current_financial_year) limit_stats = { "email": { diff --git a/tests/app/notify_client/test_notification_counts_client.py b/tests/app/notify_client/test_notification_counts_client.py index 3d4f510bca..da938daa4c 100644 --- a/tests/app/notify_client/test_notification_counts_client.py +++ b/tests/app/notify_client/test_notification_counts_client.py @@ -1,9 +1,9 @@ -from datetime import datetime from unittest.mock import Mock, patch import pytest from app.notify_client.notification_counts_client import NotificationCounts +from app.utils import get_current_financial_year @pytest.fixture @@ -199,4 +199,7 @@ def test_get_limit_stats_dependencies_called(self, mocker): # Assert dependencies called mock_today.assert_called_once_with(mock_service.id) - mock_year.assert_called_once_with(mock_service.id, datetime.now().year) + mock_year.assert_called_once_with( + mock_service.id, + get_current_financial_year(), + )