Skip to content

Commit

Permalink
#2191 - Remove Technical-Failure from Stats
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanParish authored Jan 8, 2025
1 parent 68b26fd commit 3f9a6e9
Show file tree
Hide file tree
Showing 14 changed files with 189 additions and 161 deletions.
4 changes: 4 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ fileignoreconfig:
checksum: 128bde997e5a0f41e6bac5a5dfe3180f93b33bca138d4b4eb64443af7b1b15bd
- filename: tests/app/dao/test_api_key_dao.py
checksum: 5bab4eaddf8760c502111ae3e5f9f8bee59482d99f053f94598e8c77bd10b7b6
- filename: tests/app/dao/test_ft_billing_dao.py
checksum: dc425af859e49b9822259fad20d0ff99f3fde5c0237728fe73e5c9db2b78591b
- filename: tests/app/dao/test_services_dao.py
checksum: 572fb3a52e89ae19c5a94be881bcbfe0247bae112bce58d4ae1e9eff5a5c91b7
- filename: tests/app/v2/notifications/test_get_notifications.py
checksum: 167aa80c8aac01566b3cf627cdaa839feac9dc77f0b13b6d0a008035aa8e15f1
version: "1.0"
13 changes: 0 additions & 13 deletions app/dao/fact_notification_status_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
NOTIFICATION_CANCELLED,
NOTIFICATION_CREATED,
NOTIFICATION_DELIVERED,
NOTIFICATION_FAILED,
NOTIFICATION_SENDING,
NOTIFICATION_SENT,
NOTIFICATION_TEMPORARY_FAILURE,
Expand Down Expand Up @@ -815,18 +814,6 @@ def fetch_monthly_notification_statuses_per_service(
else_=0,
)
).label('count_delivered'),
# TODO 2191 - remove this after technical-failure is removed from the codebase
func.sum(
case(
[
(
FactNotificationStatus.notification_status.in_(['technical-failure', NOTIFICATION_FAILED]),
FactNotificationStatus.notification_count,
)
],
else_=0,
)
).label('count_technical_failure'),
func.sum(
case(
[
Expand Down
6 changes: 1 addition & 5 deletions app/service/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def format_admin_stats(statistics):
counts[row.notification_type]['test-key'] += row.count
else:
counts[row.notification_type]['total'] += row.count
# TODO 2191 - remove this after technical-failure is removed from the codebase
if row.status in ('technical-failure', 'permanent-failure', 'temporary-failure', 'virus-scan-failed'):
if row.status in ('permanent-failure', 'temporary-failure', 'virus-scan-failed'):
counts[row.notification_type]['failures'][row.status] += row.count

return counts
Expand All @@ -45,8 +44,6 @@ def create_stats_dict():
stats_dict[template][status] = 0

stats_dict[template]['failures'] = {
# TODO 2191 - remove this after technical-failure is removed from the codebase
'technical-failure': 0,
'permanent-failure': 0,
'temporary-failure': 0,
'virus-scan-failed': 0,
Expand Down Expand Up @@ -94,7 +91,6 @@ def _update_statuses_from_row(
update_dict['delivered'] += row.count
elif row.status in (
'failed',
'technical-failure',
'temporary-failure',
'permanent-failure',
'validation-failed',
Expand Down
7 changes: 1 addition & 6 deletions tests/app/celery/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,6 @@ def test_should_put_save_sms_task_in_research_mode_queue_if_research_mode_servic
assert mocked_deliver_sms.called


@pytest.mark.serial
def test_should_save_sms_if_restricted_service_and_valid_number(
notify_db_session,
mocker,
Expand All @@ -551,7 +550,6 @@ def test_should_save_sms_if_restricted_service_and_valid_number(
notification_id = uuid4()
encrypt_notification = encryption.encrypt(notification)

# Intermittently makes the status 'technical-failure'
save_sms(
service.id,
notification_id,
Expand Down Expand Up @@ -878,7 +876,6 @@ def test_should_use_email_template_and_persist(
)


@pytest.mark.serial
def test_save_email_should_use_template_version_from_job_not_latest(
notify_db_session,
sample_template,
Expand All @@ -902,7 +899,6 @@ def test_save_email_should_use_template_version_from_job_not_latest(

notification_id = uuid4()

# Intermittently makes the status 'technical-failure'
save_email(
template.service_id,
notification_id,
Expand All @@ -926,7 +922,6 @@ def test_save_email_should_use_template_version_from_job_not_latest(
)


@pytest.mark.serial
def test_should_use_email_template_subject_placeholders(
notify_db_session,
sample_template,
Expand All @@ -944,7 +939,7 @@ def test_should_use_email_template_subject_placeholders(

notification_id = uuid4()
now = datetime.utcnow()
# Intermittently makes the status 'technical-failure'

save_email(
template.service_id,
notification_id,
Expand Down
10 changes: 3 additions & 7 deletions tests/app/dao/test_fact_notification_status_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,8 +1063,8 @@ def test_fetch_monthly_notification_statuses_per_service(
assert len(results) == 6

# column order: date, service_id, service_name, notifaction_type, count_sending, count_delivered,
# count_technical_failure, count_temporary_failure, count_permanent_failure, count_sent
assert [x for x in results[0]] == [date(2019, 3, 1), service_one.id, service_one.name, EMAIL_TYPE, 4, 0, 0, 0, 3, 0]
# count_temporary_failure, count_permanent_failure, count_sent
assert [x for x in results[0]] == [date(2019, 3, 1), service_one.id, service_one.name, EMAIL_TYPE, 4, 0, 0, 3, 0]
assert [x for x in results[1]] == [
date(2019, 3, 1),
service_one.id,
Expand All @@ -1075,9 +1075,8 @@ def test_fetch_monthly_notification_statuses_per_service(
0,
0,
0,
0,
]
assert [x for x in results[2]] == [date(2019, 3, 1), service_one.id, service_one.name, SMS_TYPE, 0, 0, 0, 0, 0, 1]
assert [x for x in results[2]] == [date(2019, 3, 1), service_one.id, service_one.name, SMS_TYPE, 0, 0, 0, 0, 1]
assert [x for x in results[3]] == [
date(2019, 3, 1),
service_two.id,
Expand All @@ -1086,7 +1085,6 @@ def test_fetch_monthly_notification_statuses_per_service(
0,
0,
0,
0,
2,
0,
]
Expand All @@ -1100,7 +1098,6 @@ def test_fetch_monthly_notification_statuses_per_service(
0,
0,
0,
0,
]
assert [x for x in results[5]] == [
date(2019, 4, 1),
Expand All @@ -1109,7 +1106,6 @@ def test_fetch_monthly_notification_statuses_per_service(
LETTER_TYPE,
0,
0,
0,
10,
0,
0,
Expand Down
86 changes: 46 additions & 40 deletions tests/app/dao/test_ft_billing_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
KEY_TYPE_TEAM,
KEY_TYPE_TEST,
LETTER_TYPE,
NOTIFICATION_CREATED,
NOTIFICATION_DELIVERED,
NOTIFICATION_PENDING,
NOTIFICATION_SENDING,
NOTIFICATION_STATUS_TYPES,
NOTIFICATION_TEMPORARY_FAILURE,
SMS_TYPE,
)
from app.dao.fact_billing_dao import (
Expand Down Expand Up @@ -89,14 +94,15 @@ def test_fetch_billing_data_for_today_includes_data_with_the_right_status(
):
service = sample_service()
template = sample_template(service=service, template_type=EMAIL_TYPE)
sample_notification(template=template, status='created')
sample_notification(template=template, status='technical-failure')
# these statuses need to be ones that are not in NOTIFICATION_STATUS_TYPES_BILLABLE
sample_notification(template=template, status=NOTIFICATION_CREATED)
sample_notification(template=template, status=NOTIFICATION_PENDING)

today = convert_utc_to_local_timezone(datetime.utcnow())
results = fetch_billing_data_for_day(today, service.id)
assert isinstance(results, list) and not results, 'Should be an empty list'

for status in ('delivered', 'sending', 'temporary-failure'):
for status in (NOTIFICATION_DELIVERED, NOTIFICATION_SENDING, NOTIFICATION_TEMPORARY_FAILURE):
sample_notification(template=template, status=status)

results = fetch_billing_data_for_day(today, service.id)
Expand All @@ -114,7 +120,7 @@ def test_fetch_billing_data_for_today_includes_data_with_the_right_key_type(
template = sample_template(service=service, template_type=EMAIL_TYPE)

for key_type in (KEY_TYPE_NORMAL, KEY_TYPE_TEST, KEY_TYPE_TEAM):
sample_notification(template=template, status='delivered', key_type=key_type)
sample_notification(template=template, status=NOTIFICATION_DELIVERED, key_type=key_type)

today = convert_utc_to_local_timezone(datetime.utcnow())
results = fetch_billing_data_for_day(today, service.id)
Expand All @@ -132,11 +138,11 @@ def test_fetch_billing_data_for_today_includes_data_with_the_right_date(
process_day = datetime(2018, 4, 1, 13, 30, 0)
service = sample_service()
template = sample_template(service=service, template_type=EMAIL_TYPE)
sample_notification(template=template, status='delivered', created_at=process_day)
sample_notification(template=template, status='delivered', created_at=datetime(2018, 4, 1, 4, 23, 23))
sample_notification(template=template, status=NOTIFICATION_DELIVERED, created_at=process_day)
sample_notification(template=template, status=NOTIFICATION_DELIVERED, created_at=datetime(2018, 4, 1, 4, 23, 23))

sample_notification(template=template, status='delivered', created_at=datetime(2018, 3, 31, 20, 23, 23))
sample_notification(template=template, status='sending', created_at=process_day + timedelta(days=1))
sample_notification(template=template, status=NOTIFICATION_DELIVERED, created_at=datetime(2018, 3, 31, 20, 23, 23))
sample_notification(template=template, status=NOTIFICATION_SENDING, created_at=process_day + timedelta(days=1))

day_under_test = convert_utc_to_local_timezone(process_day)
results = fetch_billing_data_for_day(day_under_test, service.id)
Expand All @@ -162,7 +168,7 @@ def test_fetch_nightly_billing_counts_retrieves_correct_data_within_process_day(
# Create 3 SMS notifications for the given process date.
sample_notification(
template=template2,
status='delivered',
status=NOTIFICATION_DELIVERED,
created_at=process_day,
billing_code='test_code',
sms_sender_id=service.service_sms_senders[0].id,
Expand All @@ -171,15 +177,15 @@ def test_fetch_nightly_billing_counts_retrieves_correct_data_within_process_day(
)
sample_notification(
template=template1,
status='delivered',
status=NOTIFICATION_DELIVERED,
created_at=process_day,
sms_sender_id=service.service_sms_senders[0].id,
segments_count=5,
cost_in_millicents=55.5,
)
sample_notification(
template=template1,
status='delivered',
status=NOTIFICATION_DELIVERED,
created_at=datetime(2018, 4, 1, 4, 23, 23),
sms_sender_id=service.service_sms_senders[0].id,
segments_count=4,
Expand All @@ -189,15 +195,15 @@ def test_fetch_nightly_billing_counts_retrieves_correct_data_within_process_day(
# Create 2 SMS notifications not for the given process date.
sample_notification(
template=template1,
status='delivered',
status=NOTIFICATION_DELIVERED,
created_at=datetime(2018, 3, 31, 20, 23, 23),
sms_sender_id=service.service_sms_senders[0].id,
segments_count=1,
cost_in_millicents=0.0005,
)
sample_notification(
template=template1,
status='sending',
status=NOTIFICATION_SENDING,
created_at=process_day + timedelta(days=1),
sms_sender_id=service.service_sms_senders[0].id,
segments_count=1,
Expand Down Expand Up @@ -232,8 +238,8 @@ def test_fetch_billing_data_for_day_is_grouped_by_template_and_notification_type
service = sample_service()
email_template = sample_template(service=service, template_type=EMAIL_TYPE)
sms_template = sample_template(service=service, template_type=SMS_TYPE)
sample_notification(template=email_template, status='delivered')
sample_notification(template=sms_template, status='delivered')
sample_notification(template=email_template, status=NOTIFICATION_DELIVERED)
sample_notification(template=sms_template, status=NOTIFICATION_DELIVERED)

today = convert_utc_to_local_timezone(datetime.utcnow())
results = fetch_billing_data_for_day(today, service.id)
Expand All @@ -249,11 +255,11 @@ def test_fetch_billing_data_for_day_is_grouped_by_service(
):
service_1 = sample_service()
email_template = sample_template(service=service_1)
sample_notification(template=email_template, status='delivered')
sample_notification(template=email_template, status=NOTIFICATION_DELIVERED)

service_2 = sample_service()
sms_template = sample_template(service=service_2)
sample_notification(template=sms_template, status='delivered')
sample_notification(template=sms_template, status=NOTIFICATION_DELIVERED)

today = convert_utc_to_local_timezone(datetime.utcnow())
results = fetch_billing_data_for_day(today, (service_1.id, service_2.id))
Expand All @@ -270,8 +276,8 @@ def test_fetch_billing_data_for_day_is_grouped_by_provider(
):
service = sample_service()
template = sample_template(service=service)
sample_notification(template=template, status='delivered', sent_by='mmg')
sample_notification(template=template, status='delivered', sent_by='firetext')
sample_notification(template=template, status=NOTIFICATION_DELIVERED, sent_by='mmg')
sample_notification(template=template, status=NOTIFICATION_DELIVERED, sent_by='firetext')

today = convert_utc_to_local_timezone(datetime.utcnow())
results = fetch_billing_data_for_day(today, service.id)
Expand All @@ -289,8 +295,8 @@ def test_fetch_billing_data_for_day_is_grouped_by_rate_mulitplier(
):
service = sample_service()
template = sample_template(service=service)
sample_notification(template=template, status='delivered', rate_multiplier=1)
sample_notification(template=template, status='delivered', rate_multiplier=2)
sample_notification(template=template, status=NOTIFICATION_DELIVERED, rate_multiplier=1)
sample_notification(template=template, status=NOTIFICATION_DELIVERED, rate_multiplier=2)

today = convert_utc_to_local_timezone(datetime.utcnow())
results = fetch_billing_data_for_day(today, service.id)
Expand All @@ -307,8 +313,8 @@ def test_fetch_billing_data_for_day_is_grouped_by_international(
):
service = sample_service()
template = sample_template(service=service)
sample_notification(template=template, status='delivered', international=True)
sample_notification(template=template, status='delivered', international=False)
sample_notification(template=template, status=NOTIFICATION_DELIVERED, international=True)
sample_notification(template=template, status=NOTIFICATION_DELIVERED, international=False)

today = convert_utc_to_local_timezone(datetime.utcnow())
results = fetch_billing_data_for_day(today, service.id)
Expand All @@ -326,12 +332,12 @@ def test_fetch_billing_data_for_day_is_grouped_by_notification_type(
sms_template = sample_template(service=service, template_type=SMS_TYPE)
email_template = sample_template(service=service, template_type=EMAIL_TYPE)
letter_template = sample_template(service=service, template_type=LETTER_TYPE)
sample_notification(template=sms_template, status='delivered')
sample_notification(template=sms_template, status='delivered')
sample_notification(template=sms_template, status='delivered')
sample_notification(template=email_template, status='delivered')
sample_notification(template=email_template, status='delivered')
sample_notification(template=letter_template, status='delivered')
sample_notification(template=sms_template, status=NOTIFICATION_DELIVERED)
sample_notification(template=sms_template, status=NOTIFICATION_DELIVERED)
sample_notification(template=sms_template, status=NOTIFICATION_DELIVERED)
sample_notification(template=email_template, status=NOTIFICATION_DELIVERED)
sample_notification(template=email_template, status=NOTIFICATION_DELIVERED)
sample_notification(template=letter_template, status=NOTIFICATION_DELIVERED)

today = convert_utc_to_local_timezone(datetime.utcnow())
results = fetch_billing_data_for_day(today, service.id)
Expand All @@ -348,10 +354,10 @@ def test_fetch_billing_data_for_day_groups_by_postage(
service = sample_service()
letter_template = sample_template(service=service, template_type=LETTER_TYPE)
email_template = sample_template(service=service, template_type=EMAIL_TYPE)
sample_notification(template=letter_template, status='delivered', postage='first')
sample_notification(template=letter_template, status='delivered', postage='first')
sample_notification(template=letter_template, status='delivered', postage='second')
sample_notification(template=email_template, status='delivered')
sample_notification(template=letter_template, status=NOTIFICATION_DELIVERED, postage='first')
sample_notification(template=letter_template, status=NOTIFICATION_DELIVERED, postage='first')
sample_notification(template=letter_template, status=NOTIFICATION_DELIVERED, postage='second')
sample_notification(template=email_template, status=NOTIFICATION_DELIVERED)

today = convert_utc_to_local_timezone(datetime.utcnow())
results = fetch_billing_data_for_day(today, service.id)
Expand All @@ -366,8 +372,8 @@ def test_fetch_billing_data_for_day_sets_postage_for_emails_and_sms_to_none(
service = sample_service()
sms_template = sample_template(service=service, template_type=SMS_TYPE)
email_template = sample_template(service=service, template_type=EMAIL_TYPE)
sample_notification(template=sms_template, status='delivered')
sample_notification(template=email_template, status='delivered')
sample_notification(template=sms_template, status=NOTIFICATION_DELIVERED)
sample_notification(template=email_template, status=NOTIFICATION_DELIVERED)

today = convert_utc_to_local_timezone(datetime.utcnow())
results = fetch_billing_data_for_day(today, service.id)
Expand All @@ -392,10 +398,10 @@ def test_fetch_billing_data_for_day_uses_notification_history(
service = sample_service()
sms_template = sample_template(service=service, template_type=SMS_TYPE)
sample_notification_history(
template=sms_template, status='delivered', created_at=datetime.utcnow() - timedelta(days=8)
template=sms_template, status=NOTIFICATION_DELIVERED, created_at=datetime.utcnow() - timedelta(days=8)
)
sample_notification_history(
template=sms_template, status='delivered', created_at=datetime.utcnow() - timedelta(days=8)
template=sms_template, status=NOTIFICATION_DELIVERED, created_at=datetime.utcnow() - timedelta(days=8)
)

results = fetch_billing_data_for_day(
Expand All @@ -414,8 +420,8 @@ def test_fetch_billing_data_for_day_returns_list_for_given_service(
service_2 = sample_service()
template = sample_template(service=service)
template_2 = sample_template(service=service_2)
sample_notification(template=template, status='delivered')
sample_notification(template=template_2, status='delivered')
sample_notification(template=template, status=NOTIFICATION_DELIVERED)
sample_notification(template=template_2, status=NOTIFICATION_DELIVERED)

today = convert_utc_to_local_timezone(datetime.utcnow())
results = fetch_billing_data_for_day(today, service.id)
Expand Down Expand Up @@ -573,7 +579,7 @@ def test_fetch_monthly_billing_for_year_adds_data_for_today(
notification_type=EMAIL_TYPE,
rate=0.162,
)
sample_notification(template=template, status='delivered')
sample_notification(template=template, status=NOTIFICATION_DELIVERED)

stmt = select(func.count()).select_from(FactBilling).where(FactBilling.service_id == service.id)

Expand Down
Loading

0 comments on commit 3f9a6e9

Please sign in to comment.