mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
Merge pull request #2249 from alphagov/improve-performance-of-platform-admin-page
Improve performance of platform stats page
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import uuid
|
||||
from datetime import datetime, timedelta, date
|
||||
from datetime import datetime, timedelta
|
||||
from functools import partial
|
||||
|
||||
import pytest
|
||||
@@ -35,7 +35,6 @@ from app.dao.notifications_dao import (
|
||||
dao_get_notifications_by_references,
|
||||
dao_get_notification_history_by_reference,
|
||||
notifications_not_yet_sent,
|
||||
fetch_aggregate_stats_by_date_range_for_all_services,
|
||||
)
|
||||
from app.dao.services_dao import dao_update_service
|
||||
from app.models import (
|
||||
@@ -1787,51 +1786,3 @@ def test_notifications_not_yet_sent_return_no_rows(sample_service, notification_
|
||||
|
||||
results = notifications_not_yet_sent(older_than, notification_type)
|
||||
assert len(results) == 0
|
||||
|
||||
|
||||
def test_fetch_aggregate_stats_by_date_range_for_all_services_returns_empty_list_when_no_stats(notify_db_session):
|
||||
start_date = date(2018, 1, 1)
|
||||
end_date = date(2018, 1, 5)
|
||||
|
||||
result = fetch_aggregate_stats_by_date_range_for_all_services(start_date, end_date)
|
||||
assert result == []
|
||||
|
||||
|
||||
@freeze_time('2018-01-08')
|
||||
def test_fetch_aggregate_stats_by_date_range_for_all_services_groups_stats(
|
||||
sample_template,
|
||||
sample_email_template,
|
||||
sample_letter_template,
|
||||
):
|
||||
today = datetime.now().date()
|
||||
|
||||
for i in range(3):
|
||||
create_notification(template=sample_email_template, status='permanent-failure',
|
||||
created_at=today)
|
||||
|
||||
create_notification(template=sample_email_template, status='sent', created_at=today)
|
||||
create_notification(template=sample_template, status='sent', created_at=today)
|
||||
create_notification(template=sample_template, status='sent', created_at=today,
|
||||
key_type=KEY_TYPE_TEAM)
|
||||
create_notification(template=sample_letter_template, status='virus-scan-failed',
|
||||
created_at=today)
|
||||
|
||||
result = fetch_aggregate_stats_by_date_range_for_all_services(today, today)
|
||||
|
||||
assert len(result) == 5
|
||||
assert ('email', 'permanent-failure', 'normal', 3) in result
|
||||
assert ('email', 'sent', 'normal', 1) in result
|
||||
assert ('sms', 'sent', 'normal', 1) in result
|
||||
assert ('sms', 'sent', 'team', 1) in result
|
||||
assert ('letter', 'virus-scan-failed', 'normal', 1) in result
|
||||
|
||||
|
||||
def test_fetch_aggregate_stats_by_date_range_for_all_services_uses_bst_date(sample_template):
|
||||
query_day = datetime(2018, 6, 5).date()
|
||||
create_notification(sample_template, status='sent', created_at=datetime(2018, 6, 4, 23, 59))
|
||||
create_notification(sample_template, status='created', created_at=datetime(2018, 6, 5, 23, 00))
|
||||
|
||||
result = fetch_aggregate_stats_by_date_range_for_all_services(query_day, query_day)
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].status == 'sent'
|
||||
|
||||
Reference in New Issue
Block a user