Merge pull request #3173 from alphagov/performance-platform-endpoints

Add an endpoint to return all the data required for the performance platform page
This commit is contained in:
Rebecca Law
2021-03-10 13:27:08 +00:00
committed by GitHub
13 changed files with 345 additions and 3 deletions

View File

@@ -14,7 +14,7 @@ from app.dao.fact_notification_status_dao import (
fetch_notification_status_totals_for_all_services,
fetch_notification_statuses_for_job,
fetch_stats_for_all_services_by_date_range, fetch_monthly_template_usage_for_service,
get_total_sent_notifications_for_day_and_type
get_total_sent_notifications_for_day_and_type, get_total_notifications_for_date_range
)
from app.models import (
FactNotificationStatus,
@@ -703,3 +703,39 @@ def test_fetch_monthly_notification_statuses_per_service_for_rows_that_should_be
results = fetch_monthly_notification_statuses_per_service(date(2019, 3, 1), date(2019, 3, 31))
assert len(results) == 0
def test_get_total_notifications_for_date_range(sample_service):
template_sms = create_template(service=sample_service, template_type='sms', template_name='a')
template_email = create_template(service=sample_service, template_type='email', template_name='b')
template_letter = create_template(service=sample_service, template_type='letter', template_name='c')
create_ft_notification_status(bst_date=date(2021, 2, 28),
service=template_email.service,
template=template_email,
count=15)
create_ft_notification_status(bst_date=date(2021, 2, 28),
service=template_sms.service,
template=template_sms,
count=20)
create_ft_notification_status(bst_date=date(2021, 2, 28),
service=template_letter.service,
template=template_letter,
count=3)
create_ft_notification_status(bst_date=date(2021, 3, 1),
service=template_email.service,
template=template_email,
count=15)
create_ft_notification_status(bst_date=date(2021, 3, 1),
service=template_sms.service,
template=template_sms,
count=20)
create_ft_notification_status(bst_date=date(2021, 3, 1),
service=template_letter.service,
template=template_letter,
count=3)
results = get_total_notifications_for_date_range(start_date=datetime(2021, 3, 1), end_date=datetime(2021, 3, 1))
assert len(results) == 1
assert results[0] == ("2021-03-01", 15, 20, 3)

View File

@@ -3,7 +3,9 @@ from datetime import datetime
from freezegun import freeze_time
from app.dao import fact_processing_time_dao
from app.dao.fact_processing_time_dao import get_processing_time_percentage_for_date_range
from app.models import FactProcessingTime
from tests.app.db import create_process_time
def test_insert_update_processing_time(notify_db_session):
@@ -40,3 +42,29 @@ def test_insert_update_processing_time(notify_db_session):
assert result[0].messages_within_10_secs == 3
assert result[0].created_at
assert result[0].updated_at == datetime(2021, 2, 23, 13, 23, 33)
def test_get_processing_time_percentage_for_date_range(notify_db_session):
create_process_time(
bst_date='2021-02-21',
messages_total=5,
messages_within_10_secs=4
)
create_process_time(
bst_date='2021-02-22',
messages_total=3,
messages_within_10_secs=2
)
create_process_time(
bst_date='2021-02-23',
messages_total=4,
messages_within_10_secs=3
)
results = get_processing_time_percentage_for_date_range('2021-02-22', '2021-02-22')
assert len(results) == 1
assert results[0].date == '2021-02-22'
assert results[0].messages_total == 3
assert results[0].messages_within_10_secs == 2
assert round(results[0].percentage, 1) == 66.7

View File

@@ -33,7 +33,7 @@ from app.dao.services_dao import (dao_add_user_to_service, dao_create_service,
dao_update_service,
delete_service_and_all_associated_db_objects,
fetch_todays_total_message_count,
get_services_by_partial_name)
get_services_by_partial_name, get_live_services_with_organisation)
from app.dao.users_dao import create_user_code, save_model_user
from app.models import (EMAIL_TYPE, INTERNATIONAL_SMS_TYPE, KEY_TYPE_NORMAL,
KEY_TYPE_TEAM, KEY_TYPE_TEST, LETTER_TYPE, SMS_TYPE,
@@ -1155,3 +1155,26 @@ def test_dao_find_services_with_high_failure_rates(notify_db_session, fake_uuid)
assert len(result) == 1
assert str(result[0].service_id) == fake_uuid
assert result[0].permanent_failure_rate == 0.25
def test_get_live_services_with_organisation(sample_organisation):
trial_service = create_service(service_name='trial service', restricted=True)
live_service = create_service(service_name="count as live")
live_service_diff_org = create_service(service_name="live service different org")
dont_count_as_live = create_service(service_name="dont count as live", count_as_live=False)
inactive_service = create_service(service_name="inactive", active=False)
service_without_org = create_service(service_name="no org")
another_org = create_organisation(name='different org', )
dao_add_service_to_organisation(trial_service, sample_organisation.id)
dao_add_service_to_organisation(live_service, sample_organisation.id)
dao_add_service_to_organisation(dont_count_as_live, sample_organisation.id)
dao_add_service_to_organisation(inactive_service, sample_organisation.id)
dao_add_service_to_organisation(live_service_diff_org, another_org.id)
services = get_live_services_with_organisation()
assert len(services) == 3
assert ([(x.service_name, x.organisation_name) for x in services]) == [
(live_service_diff_org.name, another_org.name),
(live_service.name, sample_organisation.name),
(service_without_org.name, None)]

View File

@@ -5,6 +5,7 @@ from datetime import datetime, date, timedelta
import pytest
from app import db
from app.dao import fact_processing_time_dao
from app.dao.email_branding_dao import dao_create_email_branding
from app.dao.inbound_sms_dao import dao_create_inbound_sms
from app.dao.invited_org_user_dao import save_invited_org_user
@@ -67,7 +68,7 @@ from app.models import (
BroadcastEvent,
BroadcastProvider,
BroadcastProviderMessage,
BroadcastProviderMessageNumber
BroadcastProviderMessageNumber, FactProcessingTime
)
@@ -752,6 +753,15 @@ def create_ft_notification_status(
return data
def create_process_time(bst_date='2021-03-01', messages_total=35, messages_within_10_secs=34):
data = FactProcessingTime(
bst_date=bst_date,
messages_total=messages_total,
messages_within_10_secs=messages_within_10_secs
)
fact_processing_time_dao.insert_update_processing_time(data)
def create_service_guest_list(service, email_address=None, mobile_number=None):
if email_address:
guest_list_user = ServiceGuestList.from_string(service.id, EMAIL_TYPE, email_address)

View File

@@ -0,0 +1,77 @@
from datetime import date
from tests.app.db import create_template, create_ft_notification_status, create_process_time
def test_performance_dashboard(sample_service, admin_request):
template_sms = create_template(service=sample_service, template_type='sms', template_name='a')
template_email = create_template(service=sample_service, template_type='email', template_name='b')
template_letter = create_template(service=sample_service, template_type='letter', template_name='c')
create_ft_notification_status(bst_date=date(2021, 2, 28),
service=template_email.service,
template=template_email,
count=10)
create_ft_notification_status(bst_date=date(2021, 2, 28),
service=template_sms.service,
template=template_sms,
count=5)
create_ft_notification_status(bst_date=date(2021, 2, 28),
service=template_letter.service,
template=template_letter,
count=2)
create_ft_notification_status(bst_date=date(2021, 3, 1),
service=template_email.service,
template=template_email,
count=15)
create_ft_notification_status(bst_date=date(2021, 3, 1),
service=template_sms.service,
template=template_sms,
count=20)
create_ft_notification_status(bst_date=date(2021, 3, 1),
service=template_letter.service,
template=template_letter,
count=3)
create_ft_notification_status(bst_date=date(2021, 3, 2),
service=template_email.service,
template=template_email,
count=25)
create_ft_notification_status(bst_date=date(2021, 3, 2),
service=template_sms.service,
template=template_sms,
count=30)
create_ft_notification_status(bst_date=date(2021, 3, 2),
service=template_letter.service,
template=template_letter,
count=10)
create_ft_notification_status(bst_date=date(2021, 3, 3),
service=template_email.service,
template=template_email,
count=45)
create_ft_notification_status(bst_date=date(2021, 3, 3),
service=template_sms.service,
template=template_sms,
count=35)
create_ft_notification_status(bst_date=date(2021, 3, 3),
service=template_letter.service,
template=template_letter,
count=15)
create_process_time(bst_date='2021-02-28', messages_total=15, messages_within_10_secs=14)
create_process_time(bst_date='2021-03-01', messages_total=35, messages_within_10_secs=34)
create_process_time(bst_date='2021-03-02', messages_total=15, messages_within_10_secs=14)
create_process_time(bst_date='2021-03-03', messages_total=15, messages_within_10_secs=14)
results = admin_request.get(endpoint="performance_dashboard.get_performance_dashboard",
start_date='2021-03-01',
end_date='2021-03-02')
assert results['total_notifications'] == 10+5+2+15+20+3+25+30+10+45+35+15
assert results['email_notifications'] == 10+15+25+45
assert results['sms_notifications'] == 5+20+30+35
assert results['letter_notifications'] == 2+3+10+15
assert results['notifications_by_type'] == [{"date": '2021-03-01', "emails": 15, "sms": 20, "letters": 3},
{"date": '2021-03-02', "emails": 25, "sms": 30, "letters": 10}]
assert results['processing_time'] == [{"date": "2021-03-01", "percentage_under_10_seconds": 97.1},
{"date": "2021-03-02", "percentage_under_10_seconds": 93.3}]
assert results["live_service_count"] == 1
assert results["services_using_notify"][0]["service_name"] == sample_service.name
assert not results["services_using_notify"][0]["organisation_name"]