From 68d63e25d1dfb35ff66ce13760f9504a486b6785 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Wed, 2 Jul 2025 08:24:09 -0700 Subject: [PATCH] more tests --- .ds.baseline | 4 +-- tests/app/service/test_rest.py | 54 +++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/.ds.baseline b/.ds.baseline index 5c9d98348..53c246982 100644 --- a/.ds.baseline +++ b/.ds.baseline @@ -295,7 +295,7 @@ "filename": "tests/app/service/test_rest.py", "hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", "is_verified": false, - "line_number": 1283, + "line_number": 1286, "is_secret": false } ], @@ -374,5 +374,5 @@ } ] }, - "generated_at": "2025-07-02T15:07:48Z" + "generated_at": "2025-07-02T15:24:03Z" } diff --git a/tests/app/service/test_rest.py b/tests/app/service/test_rest.py index 4d16bd62f..d5329955d 100644 --- a/tests/app/service/test_rest.py +++ b/tests/app/service/test_rest.py @@ -38,7 +38,10 @@ from app.models import ( ServiceSmsSender, User, ) -from app.service.rest import get_service_statistics_for_specific_days +from app.service.rest import ( + get_service_statistics_for_specific_days, + get_service_statistics_for_specific_days_by_user, +) from app.utils import utc_now from tests import create_admin_authorization_header from tests.app.db import ( @@ -3793,3 +3796,52 @@ def test_get_service_statistics_for_specific_days( hours=48, total_notifications=fake_total_notifications, ) + + +@patch("app.service.rest.dao_fetch_status_for_service_from_days_for_user") +@patch("app.service.rest.get_specific_hours_stats") +def test_get_service_statistics_for_specific_days_by_user( + mock_get_stats, mock_fetch_stats +): + service_id = "service-abc" + user_id = "user-123" + start_date_str = "2025-07-01" + days = 3 + expected_end = datetime(2025, 7, 1) + expected_start = expected_end - timedelta(days=days - 1) + + mock_total_notifications = { + datetime(2025, 6, 29, 10): 5, + datetime(2025, 6, 30, 12): 8, + } + mock_results = [ + MagicMock( + notification_type="email", + status="delivered", + hour=datetime(2025, 6, 29, 10), + count=5, + ), + MagicMock( + notification_type="sms", + status="sent", + hour=datetime(2025, 6, 30, 12), + count=8, + ), + ] + + mock_fetch_stats.return_value = (mock_total_notifications, mock_results) + expected_stats = {"emails_delivered": 5, "sms_sent": 8} + mock_get_stats.return_value = expected_stats + result = get_service_statistics_for_specific_days_by_user( + service_id, user_id, start_date_str, days + ) + assert result == expected_stats + mock_fetch_stats.assert_called_once_with( + service_id, expected_start, expected_end, user_id + ) + mock_get_stats.assert_called_once_with( + mock_results, + expected_start, + hours=days * 24, + total_notifications=mock_total_notifications, + )