mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-28 01:48:33 -04:00
Updated sort order, endpoint defenition, and tests
for REQUESTED attribute
This commit is contained in:
@@ -27,8 +27,8 @@ from app.models import (
|
||||
InvitedUser,
|
||||
Job,
|
||||
Notification,
|
||||
NotificationHistory,
|
||||
NotificationAllTimeView,
|
||||
NotificationHistory,
|
||||
Organization,
|
||||
Permission,
|
||||
Service,
|
||||
|
||||
@@ -243,20 +243,31 @@ def get_service_statistics_for_specific_days(service_id, start, days=1):
|
||||
|
||||
return stats
|
||||
|
||||
@service_blueprint.route("/<uuid:service_id>/statistics/user/<uuid:user_id>/<string:start>/<int:days>")
|
||||
def get_service_notification_statistics_by_day_by_user(service_id, user_id, start, days):
|
||||
|
||||
@service_blueprint.route(
|
||||
"/<uuid:service_id>/statistics/user/<uuid:user_id>/<string:start>/<int:days>"
|
||||
)
|
||||
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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user