From 0082ba3dd0527b43c73d7f7dab3f58958a2ed622 Mon Sep 17 00:00:00 2001 From: Anastasia Gradova Date: Thu, 6 Jun 2024 22:11:24 -0600 Subject: [PATCH] Updated sort order, endpoint defenition, and tests for REQUESTED attribute --- app/dao/services_dao.py | 2 +- app/service/rest.py | 25 +++++++++++++++++++------ tests/app/service/test_statistics.py | 6 ++++-- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index 67fa69da2..e2082a1ba 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -27,8 +27,8 @@ from app.models import ( InvitedUser, Job, Notification, - NotificationHistory, NotificationAllTimeView, + NotificationHistory, Organization, Permission, Service, diff --git a/app/service/rest.py b/app/service/rest.py index dafccbbe3..372dec7a5 100644 --- a/app/service/rest.py +++ b/app/service/rest.py @@ -243,20 +243,31 @@ def get_service_statistics_for_specific_days(service_id, start, days=1): return stats -@service_blueprint.route("//statistics/user///") -def get_service_notification_statistics_by_day_by_user(service_id, user_id, start, days): + +@service_blueprint.route( + "//statistics/user///" +) +def get_service_notification_statistics_by_day_by_user( + service_id, user_id, start, days +): return jsonify( - data=get_service_statistics_for_specific_days_by_user(service_id, user_id, start, int(days)) + data=get_service_statistics_for_specific_days_by_user( + service_id, user_id, start, int(days) + ) ) -def get_service_statistics_for_specific_days_by_user(service_id, user_id, start, days=1): +def get_service_statistics_for_specific_days_by_user( + service_id, user_id, start, days=1 +): start_date = datetime.strptime(start, "%Y-%m-%d").date() if days == 1: stats = {} stats[start] = statistics.format_statistics( - dao_fetch_stats_for_service_from_day_for_user(service_id, start_date, user_id) + dao_fetch_stats_for_service_from_day_for_user( + service_id, start_date, user_id + ) ) else: stats = {} @@ -264,7 +275,9 @@ def get_service_statistics_for_specific_days_by_user(service_id, user_id, start, new_date = start_date - timedelta(days=d) key = new_date.strftime("%Y-%m-%d") stats[key] = statistics.format_statistics( - dao_fetch_stats_for_service_from_day_for_user(service_id, new_date, user_id) + dao_fetch_stats_for_service_from_day_for_user( + service_id, new_date, user_id + ) ) return stats diff --git a/tests/app/service/test_statistics.py b/tests/app/service/test_statistics.py index b58b85f78..c760d01b8 100644 --- a/tests/app/service/test_statistics.py +++ b/tests/app/service/test_statistics.py @@ -301,13 +301,15 @@ def test_add_monthly_notification_status_stats(): data = create_empty_monthly_notification_status_stats_dict(2018) # this data won't be affected data["2018-05"][NotificationType.EMAIL][NotificationStatus.SENDING] = 32 + data["2018-05"][NotificationType.EMAIL][StatisticsType.REQUESTED] = 32 # this data will get combined with the 8 from row_data data["2018-05"][NotificationType.SMS][NotificationStatus.SENDING] = 16 + data["2018-05"][NotificationType.SMS][StatisticsType.REQUESTED] = 16 add_monthly_notification_status_stats(data, rows) # first 3 months are empty - print("********* ", data) + assert data == { "2018-01": {NotificationType.SMS: {}, NotificationType.EMAIL: {}}, "2018-02": {NotificationType.SMS: {}, NotificationType.EMAIL: {}}, @@ -326,7 +328,7 @@ def test_add_monthly_notification_status_stats(): "2018-05": { NotificationType.SMS: { NotificationStatus.SENDING: 24, - StatisticsType.REQUESTED: 8, + StatisticsType.REQUESTED: 24, }, NotificationType.EMAIL: { NotificationStatus.SENDING: 32,