mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
Delete functions which call the job statistics tasks
The JobStatistics table is going to be deleted. There are currently 3 tasks which use the JobStatistics model via the Statistics DAO, so we need to make sure that these tasks aren't being used before they are deleted in a separate PR. This commit deletes: * The `create_initial_notification_statistic_tasks` function which gets used to call the `record_initial_job_statistics` task. * The `create_outcome_notification_statistic_tasks` function which gets used to call the `record_outcome_job_statistics` task. * And the scheduling of the `timeout-job-statistics` scheduled task.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import uuid
|
||||
from collections import namedtuple
|
||||
from datetime import datetime
|
||||
from unittest.mock import ANY, call
|
||||
from unittest.mock import ANY
|
||||
|
||||
import pytest
|
||||
from flask import current_app
|
||||
@@ -75,7 +75,6 @@ def test_should_send_personalised_template_to_correct_sms_provider_and_persist(
|
||||
reply_to_text=sample_sms_template_with_html.service.get_default_sms_sender())
|
||||
|
||||
mocker.patch('app.mmg_client.send_sms')
|
||||
stats_mock = mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
send_to_providers.send_sms_to_provider(
|
||||
db_notification
|
||||
@@ -88,8 +87,6 @@ def test_should_send_personalised_template_to_correct_sms_provider_and_persist(
|
||||
sender=current_app.config['FROM_NUMBER']
|
||||
)
|
||||
|
||||
stats_mock.assert_called_once_with(db_notification)
|
||||
|
||||
notification = Notification.query.filter_by(id=db_notification.id).one()
|
||||
|
||||
assert notification.status == 'sending'
|
||||
@@ -110,7 +107,6 @@ def test_should_send_personalised_template_to_correct_email_provider_and_persist
|
||||
)
|
||||
|
||||
mocker.patch('app.aws_ses_client.send_email', return_value='reference')
|
||||
stats_mock = mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
send_to_providers.send_email_to_provider(
|
||||
db_notification
|
||||
@@ -124,7 +120,6 @@ def test_should_send_personalised_template_to_correct_email_provider_and_persist
|
||||
html_body=ANY,
|
||||
reply_to_address=None
|
||||
)
|
||||
stats_mock.assert_called_once_with(db_notification)
|
||||
|
||||
assert '<!DOCTYPE html' in app.aws_ses_client.send_email.call_args[1]['html_body']
|
||||
assert '<em>some HTML</em>' in app.aws_ses_client.send_email.call_args[1]['html_body']
|
||||
@@ -141,11 +136,9 @@ def test_should_not_send_email_message_when_service_is_inactive_notifcation_is_i
|
||||
):
|
||||
sample_service.active = False
|
||||
send_mock = mocker.patch("app.aws_ses_client.send_email", return_value='reference')
|
||||
stats_mock = mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
send_to_providers.send_email_to_provider(sample_notification)
|
||||
send_mock.assert_not_called()
|
||||
stats_mock.assert_not_called()
|
||||
assert Notification.query.get(sample_notification.id).status == 'technical-failure'
|
||||
|
||||
|
||||
@@ -154,11 +147,9 @@ def test_should_not_send_sms_message_when_service_is_inactive_notifcation_is_in_
|
||||
sample_service, sample_notification, mocker, client_send):
|
||||
sample_service.active = False
|
||||
send_mock = mocker.patch(client_send, return_value='reference')
|
||||
stats_mock = mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
send_to_providers.send_sms_to_provider(sample_notification)
|
||||
send_mock.assert_not_called()
|
||||
stats_mock.assert_not_called()
|
||||
assert Notification.query.get(sample_notification.id).status == 'technical-failure'
|
||||
|
||||
|
||||
@@ -169,7 +160,6 @@ def test_send_sms_should_use_template_version_from_notification_not_latest(
|
||||
reply_to_text=sample_template.service.get_default_sms_sender())
|
||||
|
||||
mocker.patch('app.mmg_client.send_sms')
|
||||
mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
version_on_notification = sample_template.version
|
||||
|
||||
@@ -209,7 +199,6 @@ def test_should_call_send_sms_response_task_if_research_mode(
|
||||
):
|
||||
mocker.patch('app.mmg_client.send_sms')
|
||||
mocker.patch('app.delivery.send_to_providers.send_sms_response')
|
||||
stats_mock = mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
if research_mode:
|
||||
sample_service.research_mode = True
|
||||
@@ -222,7 +211,6 @@ def test_should_call_send_sms_response_task_if_research_mode(
|
||||
sample_notification
|
||||
)
|
||||
assert not mmg_client.send_sms.called
|
||||
stats_mock.assert_called_once_with(sample_notification)
|
||||
|
||||
app.delivery.send_to_providers.send_sms_response.assert_called_once_with(
|
||||
'mmg', str(sample_notification.id), sample_notification.to
|
||||
@@ -260,7 +248,6 @@ def test_should_set_billable_units_to_zero_in_research_mode_or_test_key(
|
||||
|
||||
mocker.patch('app.mmg_client.send_sms')
|
||||
mocker.patch('app.delivery.send_to_providers.send_sms_response')
|
||||
stats_mock = mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
if research_mode:
|
||||
sample_service.research_mode = True
|
||||
@@ -271,7 +258,6 @@ def test_should_set_billable_units_to_zero_in_research_mode_or_test_key(
|
||||
send_to_providers.send_sms_to_provider(
|
||||
sample_notification
|
||||
)
|
||||
stats_mock.assert_called_once_with(sample_notification)
|
||||
assert notifications_dao.get_notification_by_id(sample_notification.id).billable_units == 0
|
||||
|
||||
|
||||
@@ -282,7 +268,6 @@ def test_should_not_send_to_provider_when_status_is_not_created(
|
||||
notification = create_notification(template=sample_template, status='sending')
|
||||
mocker.patch('app.mmg_client.send_sms')
|
||||
response_mock = mocker.patch('app.delivery.send_to_providers.send_sms_response')
|
||||
stats_mock = mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
send_to_providers.send_sms_to_provider(
|
||||
notification
|
||||
@@ -290,7 +275,6 @@ def test_should_not_send_to_provider_when_status_is_not_created(
|
||||
|
||||
app.mmg_client.send_sms.assert_not_called()
|
||||
response_mock.assert_not_called()
|
||||
stats_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_should_send_sms_with_downgraded_content(notify_db_session, mocker):
|
||||
@@ -307,7 +291,6 @@ def test_should_send_sms_with_downgraded_content(notify_db_session, mocker):
|
||||
)
|
||||
|
||||
mocker.patch('app.mmg_client.send_sms')
|
||||
mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
send_to_providers.send_sms_to_provider(db_notification)
|
||||
|
||||
@@ -324,7 +307,6 @@ def test_send_sms_should_use_service_sms_sender(
|
||||
sample_template,
|
||||
mocker):
|
||||
mocker.patch('app.mmg_client.send_sms')
|
||||
mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
sms_sender = create_service_sms_sender(service=sample_service, sms_sender='123456', is_default=False)
|
||||
db_notification = create_notification(template=sample_template, sms_sender_id=sms_sender.id,
|
||||
@@ -363,14 +345,12 @@ def test_send_email_to_provider_should_call_research_mode_task_response_task_if_
|
||||
mocker.patch('app.uuid.uuid4', return_value=reference)
|
||||
mocker.patch('app.aws_ses_client.send_email')
|
||||
mocker.patch('app.delivery.send_to_providers.send_email_response')
|
||||
stats_mock = mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
send_to_providers.send_email_to_provider(
|
||||
notification
|
||||
)
|
||||
|
||||
assert not app.aws_ses_client.send_email.called
|
||||
stats_mock.assert_called_once_with(notification)
|
||||
app.delivery.send_to_providers.send_email_response.assert_called_once_with(str(reference), 'john@smith.com')
|
||||
persisted_notification = Notification.query.filter_by(id=notification.id).one()
|
||||
assert persisted_notification.to == 'john@smith.com'
|
||||
@@ -390,12 +370,10 @@ def test_send_email_to_provider_should_not_send_to_provider_when_status_is_not_c
|
||||
notification = create_notification(template=sample_email_template, status='sending')
|
||||
mocker.patch('app.aws_ses_client.send_email')
|
||||
mocker.patch('app.delivery.send_to_providers.send_email_response')
|
||||
stats_mock = mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
send_to_providers.send_sms_to_provider(
|
||||
notification
|
||||
)
|
||||
stats_mock.assert_not_called()
|
||||
app.aws_ses_client.send_email.assert_not_called()
|
||||
app.delivery.send_to_providers.send_email_response.assert_not_called()
|
||||
|
||||
@@ -405,7 +383,6 @@ def test_send_email_should_use_service_reply_to_email(
|
||||
sample_email_template,
|
||||
mocker):
|
||||
mocker.patch('app.aws_ses_client.send_email', return_value='reference')
|
||||
mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
db_notification = create_notification(template=sample_email_template, reply_to_text='foo@bar.com')
|
||||
create_reply_to_email(service=sample_service, email_address='foo@bar.com')
|
||||
@@ -512,7 +489,6 @@ def test_get_logo_url_works_for_different_environments(base_url, expected_url):
|
||||
def test_should_not_set_billable_units_if_research_mode(notify_db, sample_service, sample_notification, mocker):
|
||||
mocker.patch('app.mmg_client.send_sms')
|
||||
mocker.patch('app.delivery.send_to_providers.send_sms_response')
|
||||
stats_mock = mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
sample_service.research_mode = True
|
||||
notify_db.session.add(sample_service)
|
||||
@@ -521,7 +497,6 @@ def test_should_not_set_billable_units_if_research_mode(notify_db, sample_servic
|
||||
send_to_providers.send_sms_to_provider(
|
||||
sample_notification
|
||||
)
|
||||
stats_mock.assert_called_once_with(sample_notification)
|
||||
persisted_notification = notifications_dao.get_notification_by_id(sample_notification.id)
|
||||
assert persisted_notification.billable_units == 0
|
||||
|
||||
@@ -545,7 +520,6 @@ def test_should_update_billable_units_according_to_research_mode_and_key_type(
|
||||
):
|
||||
mocker.patch('app.mmg_client.send_sms')
|
||||
mocker.patch('app.delivery.send_to_providers.send_sms_response')
|
||||
stats_mock = mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
if research_mode:
|
||||
sample_service.research_mode = True
|
||||
@@ -557,7 +531,6 @@ def test_should_update_billable_units_according_to_research_mode_and_key_type(
|
||||
send_to_providers.send_sms_to_provider(
|
||||
sample_notification
|
||||
)
|
||||
stats_mock.assert_called_once_with(sample_notification)
|
||||
assert sample_notification.billable_units == billable_units
|
||||
|
||||
|
||||
@@ -591,7 +564,6 @@ def test_should_send_sms_to_international_providers(
|
||||
|
||||
mocker.patch('app.mmg_client.send_sms')
|
||||
mocker.patch('app.firetext_client.send_sms')
|
||||
stats_mock = mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
send_to_providers.send_sms_to_provider(
|
||||
db_notification_uk
|
||||
@@ -618,11 +590,6 @@ def test_should_send_sms_to_international_providers(
|
||||
notification_uk = Notification.query.filter_by(id=db_notification_uk.id).one()
|
||||
notification_int = Notification.query.filter_by(id=db_notification_international.id).one()
|
||||
|
||||
stats_mock.assert_has_calls([
|
||||
call(db_notification_uk),
|
||||
call(db_notification_international)
|
||||
])
|
||||
|
||||
assert notification_uk.status == 'sending'
|
||||
assert notification_uk.sent_by == 'firetext'
|
||||
assert notification_int.status == 'sent'
|
||||
@@ -642,7 +609,6 @@ def test_should_send_international_sms_with_formatted_phone_number(
|
||||
|
||||
send_notification_mock = mocker.patch('app.mmg_client.send_sms')
|
||||
mocker.patch('app.delivery.send_to_providers.send_sms_response')
|
||||
mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
send_to_providers.send_sms_to_provider(
|
||||
notification
|
||||
@@ -664,7 +630,6 @@ def test_should_set_international_phone_number_to_sent_status(
|
||||
|
||||
mocker.patch('app.mmg_client.send_sms')
|
||||
mocker.patch('app.delivery.send_to_providers.send_sms_response')
|
||||
mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
send_to_providers.send_sms_to_provider(
|
||||
notification
|
||||
@@ -691,7 +656,6 @@ def test_should_handle_sms_sender_and_prefix_message(
|
||||
notify_db_session
|
||||
):
|
||||
mocker.patch('app.mmg_client.send_sms')
|
||||
mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
service = create_service_with_defined_sms_sender(sms_sender_value=sms_sender, prefix_sms=prefix_sms)
|
||||
template = create_template(service, content='bar')
|
||||
notification = create_notification(template, reply_to_text=sms_sender)
|
||||
@@ -710,7 +674,6 @@ def test_send_email_to_provider_uses_reply_to_from_notification(
|
||||
sample_email_template,
|
||||
mocker):
|
||||
mocker.patch('app.aws_ses_client.send_email', return_value='reference')
|
||||
mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
db_notification = create_notification(template=sample_email_template, reply_to_text="test@test.com")
|
||||
|
||||
@@ -732,7 +695,6 @@ def test_send_email_to_provider_should_format_reply_to_email_address(
|
||||
sample_email_template,
|
||||
mocker):
|
||||
mocker.patch('app.aws_ses_client.send_email', return_value='reference')
|
||||
mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
db_notification = create_notification(template=sample_email_template, reply_to_text="test@test.com\t")
|
||||
|
||||
@@ -753,7 +715,6 @@ def test_send_email_to_provider_should_format_reply_to_email_address(
|
||||
def test_send_sms_to_provider_should_format_phone_number(sample_notification, mocker):
|
||||
sample_notification.to = '+44 (7123) 123-123'
|
||||
send_mock = mocker.patch('app.mmg_client.send_sms')
|
||||
mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
send_to_providers.send_sms_to_provider(sample_notification)
|
||||
|
||||
@@ -763,7 +724,6 @@ def test_send_sms_to_provider_should_format_phone_number(sample_notification, mo
|
||||
def test_send_email_to_provider_should_format_email_address(sample_email_notification, mocker):
|
||||
sample_email_notification.to = 'test@example.com\t'
|
||||
send_mock = mocker.patch('app.aws_ses_client.send_email', return_value='reference')
|
||||
mocker.patch('app.delivery.send_to_providers.create_initial_notification_statistic_tasks')
|
||||
|
||||
send_to_providers.send_email_to_provider(sample_email_notification)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user