mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-24 01:11:38 -05:00
Merge pull request #2310 from alphagov/remove-used-query
Remove unused query
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user