mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-26 17:23:50 -04:00
Removed unused method
This commit is contained in:
@@ -7,26 +7,25 @@ from datetime import (
|
|||||||
|
|
||||||
from boto.exception import BotoClientError
|
from boto.exception import BotoClientError
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
from notifications_utils.international_billing_rates import INTERNATIONAL_BILLING_RATES
|
||||||
from notifications_utils.recipients import (
|
from notifications_utils.recipients import (
|
||||||
validate_and_format_email_address,
|
validate_and_format_email_address,
|
||||||
InvalidEmailError,
|
InvalidEmailError,
|
||||||
try_validate_and_format_phone_number
|
try_validate_and_format_phone_number
|
||||||
)
|
)
|
||||||
from notifications_utils.statsd_decorators import statsd
|
from notifications_utils.statsd_decorators import statsd
|
||||||
from werkzeug.datastructures import MultiDict
|
from notifications_utils.timezones import convert_utc_to_bst
|
||||||
from sqlalchemy import (desc, func, or_, asc)
|
from sqlalchemy import (desc, func, or_, asc)
|
||||||
from sqlalchemy.orm import joinedload
|
from sqlalchemy.orm import joinedload
|
||||||
from sqlalchemy.sql.expression import case
|
|
||||||
from sqlalchemy.sql import functions
|
from sqlalchemy.sql import functions
|
||||||
from notifications_utils.international_billing_rates import INTERNATIONAL_BILLING_RATES
|
from sqlalchemy.sql.expression import case
|
||||||
from notifications_utils.timezones import convert_utc_to_bst
|
from werkzeug.datastructures import MultiDict
|
||||||
|
|
||||||
from app import db, create_uuid
|
from app import db, create_uuid
|
||||||
from app.aws.s3 import remove_s3_object, get_s3_bucket_objects
|
from app.aws.s3 import remove_s3_object, get_s3_bucket_objects
|
||||||
from app.letters.utils import LETTERS_PDF_FILE_LOCATION_STRUCTURE
|
from app.dao.dao_utils import transactional
|
||||||
from app.utils import midnight_n_days_ago, escape_special_characters
|
|
||||||
from app.errors import InvalidRequest
|
from app.errors import InvalidRequest
|
||||||
|
from app.letters.utils import LETTERS_PDF_FILE_LOCATION_STRUCTURE
|
||||||
from app.models import (
|
from app.models import (
|
||||||
Notification,
|
Notification,
|
||||||
NotificationHistory,
|
NotificationHistory,
|
||||||
@@ -47,9 +46,8 @@ from app.models import (
|
|||||||
EMAIL_TYPE,
|
EMAIL_TYPE,
|
||||||
ServiceDataRetention
|
ServiceDataRetention
|
||||||
)
|
)
|
||||||
|
|
||||||
from app.dao.dao_utils import transactional
|
|
||||||
from app.utils import get_london_midnight_in_utc
|
from app.utils import get_london_midnight_in_utc
|
||||||
|
from app.utils import midnight_n_days_ago, escape_special_characters
|
||||||
|
|
||||||
|
|
||||||
@statsd(namespace="dao")
|
@statsd(namespace="dao")
|
||||||
@@ -623,31 +621,3 @@ def guess_notification_type(search_term):
|
|||||||
return EMAIL_TYPE
|
return EMAIL_TYPE
|
||||||
else:
|
else:
|
||||||
return SMS_TYPE
|
return SMS_TYPE
|
||||||
|
|
||||||
|
|
||||||
@statsd(namespace='dao')
|
|
||||||
def fetch_aggregate_stats_by_date_range_for_all_services(start_date, end_date):
|
|
||||||
start_date = get_london_midnight_in_utc(start_date)
|
|
||||||
end_date = get_london_midnight_in_utc(end_date + timedelta(days=1))
|
|
||||||
table = NotificationHistory
|
|
||||||
|
|
||||||
if start_date >= datetime.utcnow() - timedelta(days=7):
|
|
||||||
table = Notification
|
|
||||||
|
|
||||||
query = db.session.query(
|
|
||||||
table.notification_type,
|
|
||||||
table.status,
|
|
||||||
table.key_type,
|
|
||||||
func.count(table.id).label('count')
|
|
||||||
).filter(
|
|
||||||
table.created_at >= start_date,
|
|
||||||
table.created_at < end_date
|
|
||||||
).group_by(
|
|
||||||
table.notification_type,
|
|
||||||
table.key_type,
|
|
||||||
table.status
|
|
||||||
).order_by(
|
|
||||||
table.notification_type,
|
|
||||||
)
|
|
||||||
|
|
||||||
return query.all()
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime, timedelta, date
|
from datetime import datetime, timedelta
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -33,7 +33,6 @@ from app.dao.notifications_dao import (
|
|||||||
dao_get_notifications_by_references,
|
dao_get_notifications_by_references,
|
||||||
dao_get_notification_history_by_reference,
|
dao_get_notification_history_by_reference,
|
||||||
notifications_not_yet_sent,
|
notifications_not_yet_sent,
|
||||||
fetch_aggregate_stats_by_date_range_for_all_services,
|
|
||||||
)
|
)
|
||||||
from app.dao.services_dao import dao_update_service
|
from app.dao.services_dao import dao_update_service
|
||||||
from app.models import (
|
from app.models import (
|
||||||
@@ -1802,51 +1801,3 @@ def test_notifications_not_yet_sent_return_no_rows(sample_service, notification_
|
|||||||
|
|
||||||
results = notifications_not_yet_sent(older_than, notification_type)
|
results = notifications_not_yet_sent(older_than, notification_type)
|
||||||
assert len(results) == 0
|
assert len(results) == 0
|
||||||
|
|
||||||
|
|
||||||
def test_fetch_aggregate_stats_by_date_range_for_all_services_returns_empty_list_when_no_stats(notify_db_session):
|
|
||||||
start_date = date(2018, 1, 1)
|
|
||||||
end_date = date(2018, 1, 5)
|
|
||||||
|
|
||||||
result = fetch_aggregate_stats_by_date_range_for_all_services(start_date, end_date)
|
|
||||||
assert result == []
|
|
||||||
|
|
||||||
|
|
||||||
@freeze_time('2018-01-08')
|
|
||||||
def test_fetch_aggregate_stats_by_date_range_for_all_services_groups_stats(
|
|
||||||
sample_template,
|
|
||||||
sample_email_template,
|
|
||||||
sample_letter_template,
|
|
||||||
):
|
|
||||||
today = datetime.now().date()
|
|
||||||
|
|
||||||
for i in range(3):
|
|
||||||
create_notification(template=sample_email_template, status='permanent-failure',
|
|
||||||
created_at=today)
|
|
||||||
|
|
||||||
create_notification(template=sample_email_template, status='sent', created_at=today)
|
|
||||||
create_notification(template=sample_template, status='sent', created_at=today)
|
|
||||||
create_notification(template=sample_template, status='sent', created_at=today,
|
|
||||||
key_type=KEY_TYPE_TEAM)
|
|
||||||
create_notification(template=sample_letter_template, status='virus-scan-failed',
|
|
||||||
created_at=today)
|
|
||||||
|
|
||||||
result = fetch_aggregate_stats_by_date_range_for_all_services(today, today)
|
|
||||||
|
|
||||||
assert len(result) == 5
|
|
||||||
assert ('email', 'permanent-failure', 'normal', 3) in result
|
|
||||||
assert ('email', 'sent', 'normal', 1) in result
|
|
||||||
assert ('sms', 'sent', 'normal', 1) in result
|
|
||||||
assert ('sms', 'sent', 'team', 1) in result
|
|
||||||
assert ('letter', 'virus-scan-failed', 'normal', 1) in result
|
|
||||||
|
|
||||||
|
|
||||||
def test_fetch_aggregate_stats_by_date_range_for_all_services_uses_bst_date(sample_template):
|
|
||||||
query_day = datetime(2018, 6, 5).date()
|
|
||||||
create_notification(sample_template, status='sent', created_at=datetime(2018, 6, 4, 23, 59))
|
|
||||||
create_notification(sample_template, status='created', created_at=datetime(2018, 6, 5, 23, 00))
|
|
||||||
|
|
||||||
result = fetch_aggregate_stats_by_date_range_for_all_services(query_day, query_day)
|
|
||||||
|
|
||||||
assert len(result) == 1
|
|
||||||
assert result[0].status == 'sent'
|
|
||||||
|
|||||||
Reference in New Issue
Block a user