mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-11 09:27:56 -04:00
There is no need to have a separate table to store template monthly statistics. It's easy enough to aggregate the stats from ft_notification_status.
This removes the nightly task, and all the dao methods. The next PR will remove the table.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import functools
|
||||
from datetime import datetime, timedelta
|
||||
from functools import partial
|
||||
from unittest.mock import call, patch, PropertyMock
|
||||
@@ -31,7 +30,6 @@ from app.celery.scheduled_tasks import (
|
||||
send_total_sent_notifications_to_performance_platform,
|
||||
switch_current_sms_provider_on_slow_delivery,
|
||||
timeout_notifications,
|
||||
daily_stats_template_usage_by_month,
|
||||
letter_raise_alert_if_no_ack_file_for_zip,
|
||||
replay_created_notifications
|
||||
)
|
||||
@@ -46,8 +44,6 @@ from app.dao.provider_details_dao import (
|
||||
)
|
||||
from app.exceptions import NotificationTechnicalFailureException
|
||||
from app.models import (
|
||||
NotificationHistory,
|
||||
StatsTemplateUsageByMonth,
|
||||
JOB_STATUS_IN_PROGRESS,
|
||||
JOB_STATUS_ERROR,
|
||||
LETTER_TYPE,
|
||||
@@ -69,7 +65,6 @@ from tests.app.db import (
|
||||
from tests.app.conftest import (
|
||||
sample_job as create_sample_job,
|
||||
sample_notification_history as create_notification_history,
|
||||
sample_template as create_sample_template,
|
||||
datetime_in_past
|
||||
)
|
||||
|
||||
@@ -806,151 +801,6 @@ def test_check_job_status_task_sets_jobs_to_error(mocker, sample_template):
|
||||
assert job_2.job_status == JOB_STATUS_IN_PROGRESS
|
||||
|
||||
|
||||
def test_daily_stats_template_usage_by_month(notify_db, notify_db_session):
|
||||
notification_history = functools.partial(
|
||||
create_notification_history,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
status='delivered'
|
||||
)
|
||||
|
||||
template_one = create_sample_template(notify_db, notify_db_session)
|
||||
template_two = create_sample_template(notify_db, notify_db_session)
|
||||
|
||||
notification_history(created_at=datetime(2017, 10, 1), sample_template=template_one)
|
||||
notification_history(created_at=datetime(2016, 4, 1), sample_template=template_two)
|
||||
notification_history(created_at=datetime(2016, 4, 1), sample_template=template_two)
|
||||
notification_history(created_at=datetime.now(), sample_template=template_two)
|
||||
|
||||
daily_stats_template_usage_by_month()
|
||||
|
||||
result = db.session.query(
|
||||
StatsTemplateUsageByMonth
|
||||
).order_by(
|
||||
StatsTemplateUsageByMonth.year,
|
||||
StatsTemplateUsageByMonth.month
|
||||
).all()
|
||||
|
||||
assert len(result) == 2
|
||||
|
||||
assert result[0].template_id == template_two.id
|
||||
assert result[0].month == 4
|
||||
assert result[0].year == 2016
|
||||
assert result[0].count == 2
|
||||
|
||||
assert result[1].template_id == template_one.id
|
||||
assert result[1].month == 10
|
||||
assert result[1].year == 2017
|
||||
assert result[1].count == 1
|
||||
|
||||
|
||||
def test_daily_stats_template_usage_by_month_no_data():
|
||||
daily_stats_template_usage_by_month()
|
||||
|
||||
results = db.session.query(StatsTemplateUsageByMonth).all()
|
||||
|
||||
assert len(results) == 0
|
||||
|
||||
|
||||
def test_daily_stats_template_usage_by_month_multiple_runs(notify_db, notify_db_session):
|
||||
notification_history = functools.partial(
|
||||
create_notification_history,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
status='delivered'
|
||||
)
|
||||
|
||||
template_one = create_sample_template(notify_db, notify_db_session)
|
||||
template_two = create_sample_template(notify_db, notify_db_session)
|
||||
|
||||
notification_history(created_at=datetime(2017, 11, 1), sample_template=template_one)
|
||||
notification_history(created_at=datetime(2016, 4, 1), sample_template=template_two)
|
||||
notification_history(created_at=datetime(2016, 4, 1), sample_template=template_two)
|
||||
notification_history(created_at=datetime.now(), sample_template=template_two)
|
||||
|
||||
daily_stats_template_usage_by_month()
|
||||
|
||||
template_three = create_sample_template(notify_db, notify_db_session)
|
||||
|
||||
notification_history(created_at=datetime(2017, 10, 1), sample_template=template_three)
|
||||
notification_history(created_at=datetime(2017, 9, 1), sample_template=template_three)
|
||||
notification_history(created_at=datetime(2016, 4, 1), sample_template=template_two)
|
||||
notification_history(created_at=datetime(2016, 4, 1), sample_template=template_two)
|
||||
notification_history(created_at=datetime.now(), sample_template=template_two)
|
||||
|
||||
daily_stats_template_usage_by_month()
|
||||
|
||||
result = db.session.query(
|
||||
StatsTemplateUsageByMonth
|
||||
).order_by(
|
||||
StatsTemplateUsageByMonth.year,
|
||||
StatsTemplateUsageByMonth.month
|
||||
).all()
|
||||
|
||||
assert len(result) == 4
|
||||
|
||||
assert result[0].template_id == template_two.id
|
||||
assert result[0].month == 4
|
||||
assert result[0].year == 2016
|
||||
assert result[0].count == 4
|
||||
|
||||
assert result[1].template_id == template_three.id
|
||||
assert result[1].month == 9
|
||||
assert result[1].year == 2017
|
||||
assert result[1].count == 1
|
||||
|
||||
assert result[2].template_id == template_three.id
|
||||
assert result[2].month == 10
|
||||
assert result[2].year == 2017
|
||||
assert result[2].count == 1
|
||||
|
||||
assert result[3].template_id == template_one.id
|
||||
assert result[3].month == 11
|
||||
assert result[3].year == 2017
|
||||
assert result[3].count == 1
|
||||
|
||||
|
||||
def test_dao_fetch_monthly_historical_stats_by_template_null_template_id_not_counted(notify_db, notify_db_session):
|
||||
notification_history = functools.partial(
|
||||
create_notification_history,
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
status='delivered'
|
||||
)
|
||||
|
||||
template_one = create_sample_template(notify_db, notify_db_session, template_name='1')
|
||||
history = notification_history(created_at=datetime(2017, 2, 1), sample_template=template_one)
|
||||
|
||||
NotificationHistory.query.filter(
|
||||
NotificationHistory.id == history.id
|
||||
).update(
|
||||
{
|
||||
'template_id': None
|
||||
}
|
||||
)
|
||||
|
||||
daily_stats_template_usage_by_month()
|
||||
|
||||
result = db.session.query(
|
||||
StatsTemplateUsageByMonth
|
||||
).all()
|
||||
|
||||
assert len(result) == 0
|
||||
|
||||
notification_history(created_at=datetime(2017, 2, 1), sample_template=template_one)
|
||||
|
||||
daily_stats_template_usage_by_month()
|
||||
|
||||
result = db.session.query(
|
||||
StatsTemplateUsageByMonth
|
||||
).order_by(
|
||||
StatsTemplateUsageByMonth.year,
|
||||
StatsTemplateUsageByMonth.month
|
||||
).all()
|
||||
|
||||
assert len(result) == 1
|
||||
|
||||
|
||||
def mock_s3_get_list_match(bucket_name, subfolder='', suffix='', last_modified=None):
|
||||
if subfolder == '2018-01-11/zips_sent':
|
||||
return ['NOTIFY.20180111175007.ZIP.TXT', 'NOTIFY.20180111175008.ZIP.TXT']
|
||||
|
||||
Reference in New Issue
Block a user