mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-08 04:08:25 -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,
|
InvitedUser,
|
||||||
Job,
|
Job,
|
||||||
Notification,
|
Notification,
|
||||||
NotificationHistory,
|
|
||||||
NotificationAllTimeView,
|
NotificationAllTimeView,
|
||||||
|
NotificationHistory,
|
||||||
Organization,
|
Organization,
|
||||||
Permission,
|
Permission,
|
||||||
Service,
|
Service,
|
||||||
|
|||||||
@@ -243,20 +243,31 @@ def get_service_statistics_for_specific_days(service_id, start, days=1):
|
|||||||
|
|
||||||
return stats
|
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(
|
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()
|
start_date = datetime.strptime(start, "%Y-%m-%d").date()
|
||||||
|
|
||||||
if days == 1:
|
if days == 1:
|
||||||
stats = {}
|
stats = {}
|
||||||
stats[start] = statistics.format_statistics(
|
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:
|
else:
|
||||||
stats = {}
|
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)
|
new_date = start_date - timedelta(days=d)
|
||||||
key = new_date.strftime("%Y-%m-%d")
|
key = new_date.strftime("%Y-%m-%d")
|
||||||
stats[key] = statistics.format_statistics(
|
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
|
return stats
|
||||||
|
|||||||
@@ -301,13 +301,15 @@ def test_add_monthly_notification_status_stats():
|
|||||||
data = create_empty_monthly_notification_status_stats_dict(2018)
|
data = create_empty_monthly_notification_status_stats_dict(2018)
|
||||||
# this data won't be affected
|
# this data won't be affected
|
||||||
data["2018-05"][NotificationType.EMAIL][NotificationStatus.SENDING] = 32
|
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
|
# this data will get combined with the 8 from row_data
|
||||||
data["2018-05"][NotificationType.SMS][NotificationStatus.SENDING] = 16
|
data["2018-05"][NotificationType.SMS][NotificationStatus.SENDING] = 16
|
||||||
|
data["2018-05"][NotificationType.SMS][StatisticsType.REQUESTED] = 16
|
||||||
|
|
||||||
add_monthly_notification_status_stats(data, rows)
|
add_monthly_notification_status_stats(data, rows)
|
||||||
# first 3 months are empty
|
# first 3 months are empty
|
||||||
print("********* ", data)
|
|
||||||
assert data == {
|
assert data == {
|
||||||
"2018-01": {NotificationType.SMS: {}, NotificationType.EMAIL: {}},
|
"2018-01": {NotificationType.SMS: {}, NotificationType.EMAIL: {}},
|
||||||
"2018-02": {NotificationType.SMS: {}, NotificationType.EMAIL: {}},
|
"2018-02": {NotificationType.SMS: {}, NotificationType.EMAIL: {}},
|
||||||
@@ -326,7 +328,7 @@ def test_add_monthly_notification_status_stats():
|
|||||||
"2018-05": {
|
"2018-05": {
|
||||||
NotificationType.SMS: {
|
NotificationType.SMS: {
|
||||||
NotificationStatus.SENDING: 24,
|
NotificationStatus.SENDING: 24,
|
||||||
StatisticsType.REQUESTED: 8,
|
StatisticsType.REQUESTED: 24,
|
||||||
},
|
},
|
||||||
NotificationType.EMAIL: {
|
NotificationType.EMAIL: {
|
||||||
NotificationStatus.SENDING: 32,
|
NotificationStatus.SENDING: 32,
|
||||||
|
|||||||
Reference in New Issue
Block a user