From 6ac1f39fd0a8becc270e0b727ac983ad6b88609c Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Thu, 17 Jan 2019 17:20:21 +0000 Subject: [PATCH] Remove dao_fetch_monthly_historical_stats_by_template, a query using NotificationHistory that is no longer used. --- app/dao/services_dao.py | 29 +++-------------------------- tests/app/dao/test_services_dao.py | 26 -------------------------- 2 files changed, 3 insertions(+), 52 deletions(-) diff --git a/app/dao/services_dao.py b/app/dao/services_dao.py index 342ba7dfb..52536c116 100644 --- a/app/dao/services_dao.py +++ b/app/dao/services_dao.py @@ -1,8 +1,8 @@ import uuid -from datetime import date, datetime, timedelta, time +from datetime import date, datetime, timedelta from notifications_utils.statsd_decorators import statsd -from sqlalchemy import asc, func, extract +from sqlalchemy import asc, func from sqlalchemy.orm import joinedload from flask import current_app @@ -35,7 +35,7 @@ from app.models import ( SMS_TYPE, LETTER_TYPE, ) -from app.utils import get_london_month_from_utc_column, get_london_midnight_in_utc, midnight_n_days_ago +from app.utils import get_london_midnight_in_utc, midnight_n_days_ago DEFAULT_SERVICE_PERMISSIONS = [ SMS_TYPE, @@ -364,26 +364,3 @@ def dao_fetch_active_users_for_service(service_id): ) return query.all() - - -@statsd(namespace="dao") -def dao_fetch_monthly_historical_stats_by_template(): - month = get_london_month_from_utc_column(NotificationHistory.created_at) - year = func.date_trunc("year", NotificationHistory.created_at) - end_date = datetime.combine(date.today(), time.min) - - return db.session.query( - NotificationHistory.template_id, - extract('month', month).label('month'), - extract('year', year).label('year'), - func.count().label('count') - ).filter( - NotificationHistory.created_at < end_date - ).group_by( - NotificationHistory.template_id, - month, - year - ).order_by( - year, - month - ).all() diff --git a/tests/app/dao/test_services_dao.py b/tests/app/dao/test_services_dao.py index 766f2ef59..4a1ec0b4b 100644 --- a/tests/app/dao/test_services_dao.py +++ b/tests/app/dao/test_services_dao.py @@ -30,7 +30,6 @@ from app.dao.services_dao import ( dao_resume_service, dao_fetch_active_users_for_service, dao_fetch_service_by_inbound_number, - dao_fetch_monthly_historical_stats_by_template, ) from app.dao.users_dao import save_model_user, create_user_code from app.models import ( @@ -874,31 +873,6 @@ def _assert_service_permissions(service_permissions, expected): assert set(expected) == set(p.permission for p in service_permissions) -def test_dao_fetch_monthly_historical_stats_by_template(notify_db_session): - service = create_service() - template_one = create_template(service=service, template_name='1') - template_two = create_template(service=service, template_name='2') - - create_notification(created_at=datetime(2017, 10, 1), template=template_one, status='delivered') - create_notification(created_at=datetime(2016, 4, 1), template=template_two, status='delivered') - create_notification(created_at=datetime(2016, 4, 1), template=template_two, status='delivered') - create_notification(created_at=datetime.now(), template=template_two, status='delivered') - - result = sorted(dao_fetch_monthly_historical_stats_by_template(), key=lambda x: (x.month, x.year)) - - 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 create_email_sms_letter_template(): service = create_service() template_one = create_template(service=service, template_name='1', template_type='email')