mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Create a new query for template monthly stats.
This commit is contained in:
@@ -11,7 +11,8 @@ from app.dao.fact_notification_status_dao import (
|
||||
fetch_notification_status_for_service_for_today_and_7_previous_days,
|
||||
fetch_notification_status_totals_for_all_services,
|
||||
fetch_notification_statuses_for_job,
|
||||
fetch_stats_for_all_services_by_date_range)
|
||||
fetch_stats_for_all_services_by_date_range, fetch_monthly_template_usage_for_service
|
||||
)
|
||||
from app.models import FactNotificationStatus, KEY_TYPE_TEST, KEY_TYPE_TEAM, EMAIL_TYPE, SMS_TYPE, LETTER_TYPE
|
||||
from freezegun import freeze_time
|
||||
from tests.app.db import create_notification, create_service, create_template, create_ft_notification_status, create_job
|
||||
@@ -338,3 +339,29 @@ def test_fetch_stats_for_all_services_by_date_range(notify_db_session):
|
||||
assert not results[4].notification_type
|
||||
assert not results[4].status
|
||||
assert not results[4].count
|
||||
|
||||
|
||||
def test_fetch_monthly_template_usage_for_service(sample_service):
|
||||
template_one = create_template(service=sample_service, template_type='sms', template_name='one')
|
||||
template_two = create_template(service=sample_service, template_type='email', template_name='one')
|
||||
template_three = create_template(service=sample_service, template_type='letter', template_name='one')
|
||||
|
||||
create_ft_notification_status(bst_date=date(2018, 1, 1),
|
||||
service=sample_service,
|
||||
template=template_one,
|
||||
count=2)
|
||||
create_ft_notification_status(bst_date=date(2018, 2, 1),
|
||||
service=sample_service,
|
||||
template=template_two,
|
||||
count=3)
|
||||
create_ft_notification_status(bst_date=date(2018, 3, 1),
|
||||
service=sample_service,
|
||||
template=template_three,
|
||||
count=5)
|
||||
|
||||
results = fetch_monthly_template_usage_for_service(
|
||||
datetime(2017, 4, 1), datetime(2018, 3, 31), sample_service.id
|
||||
)
|
||||
|
||||
print(results)
|
||||
assert len(results) == 3
|
||||
|
||||
@@ -28,13 +28,7 @@ def test_get_template_usage_by_month_returns_correct_data(
|
||||
admin_request,
|
||||
sample_template
|
||||
):
|
||||
create_notification(sample_template, created_at=datetime(2016, 4, 1), status='created')
|
||||
create_notification(sample_template, created_at=datetime(2017, 4, 1), status='sending')
|
||||
create_notification(sample_template, created_at=datetime(2017, 4, 1), status='permanent-failure')
|
||||
create_notification(sample_template, created_at=datetime(2017, 4, 1), status='temporary-failure')
|
||||
|
||||
daily_stats_template_usage_by_month()
|
||||
|
||||
create_ft_notification_status(bst_date=date(2017, 4, 2), template=sample_template, count=3)
|
||||
create_notification(sample_template, created_at=datetime.utcnow())
|
||||
|
||||
resp_json = admin_request.get(
|
||||
@@ -85,14 +79,8 @@ def test_get_template_usage_by_month_returns_two_templates(admin_request, sample
|
||||
template_name=PRECOMPILED_TEMPLATE_NAME,
|
||||
hidden=True
|
||||
)
|
||||
|
||||
create_notification(template_one, created_at=datetime(2017, 4, 1), status='created')
|
||||
create_notification(sample_template, created_at=datetime(2017, 4, 1), status='sending')
|
||||
create_notification(sample_template, created_at=datetime(2017, 4, 1), status='permanent-failure')
|
||||
create_notification(sample_template, created_at=datetime(2017, 4, 1), status='temporary-failure')
|
||||
|
||||
daily_stats_template_usage_by_month()
|
||||
|
||||
create_ft_notification_status(bst_date=datetime(2017, 4, 1), template=template_one, count=1)
|
||||
create_ft_notification_status(bst_date=datetime(2017, 4, 1), template=sample_template, count=3)
|
||||
create_notification(sample_template, created_at=datetime.utcnow())
|
||||
|
||||
resp_json = admin_request.get(
|
||||
|
||||
Reference in New Issue
Block a user