mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-07 14:18:24 -04:00
Delete unused parameters from the save_email and save_sms jobs
These both had default arguments of `api_key_id` and `key_type` which were never being passed in, so these have been removed.
This commit is contained in:
@@ -181,14 +181,12 @@ def __sending_limits_for_job_exceeded(service, job, job_id):
|
|||||||
def save_sms(self,
|
def save_sms(self,
|
||||||
service_id,
|
service_id,
|
||||||
notification_id,
|
notification_id,
|
||||||
encrypted_notification,
|
encrypted_notification):
|
||||||
api_key_id=None,
|
|
||||||
key_type=KEY_TYPE_NORMAL):
|
|
||||||
notification = encryption.decrypt(encrypted_notification)
|
notification = encryption.decrypt(encrypted_notification)
|
||||||
service = dao_fetch_service_by_id(service_id)
|
service = dao_fetch_service_by_id(service_id)
|
||||||
template = dao_get_template_by_id(notification['template'], version=notification['template_version'])
|
template = dao_get_template_by_id(notification['template'], version=notification['template_version'])
|
||||||
|
|
||||||
if not service_allowed_to_send_to(notification['to'], service, key_type):
|
if not service_allowed_to_send_to(notification['to'], service, KEY_TYPE_NORMAL):
|
||||||
current_app.logger.debug(
|
current_app.logger.debug(
|
||||||
"SMS {} failed as restricted service".format(notification_id)
|
"SMS {} failed as restricted service".format(notification_id)
|
||||||
)
|
)
|
||||||
@@ -202,8 +200,8 @@ def save_sms(self,
|
|||||||
service=service,
|
service=service,
|
||||||
personalisation=notification.get('personalisation'),
|
personalisation=notification.get('personalisation'),
|
||||||
notification_type=SMS_TYPE,
|
notification_type=SMS_TYPE,
|
||||||
api_key_id=api_key_id,
|
api_key_id=None,
|
||||||
key_type=key_type,
|
key_type=KEY_TYPE_NORMAL,
|
||||||
created_at=datetime.utcnow(),
|
created_at=datetime.utcnow(),
|
||||||
job_id=notification.get('job', None),
|
job_id=notification.get('job', None),
|
||||||
job_row_number=notification.get('row_number', None),
|
job_row_number=notification.get('row_number', None),
|
||||||
@@ -232,15 +230,13 @@ def save_sms(self,
|
|||||||
def save_email(self,
|
def save_email(self,
|
||||||
service_id,
|
service_id,
|
||||||
notification_id,
|
notification_id,
|
||||||
encrypted_notification,
|
encrypted_notification):
|
||||||
api_key_id=None,
|
|
||||||
key_type=KEY_TYPE_NORMAL):
|
|
||||||
notification = encryption.decrypt(encrypted_notification)
|
notification = encryption.decrypt(encrypted_notification)
|
||||||
|
|
||||||
service = dao_fetch_service_by_id(service_id)
|
service = dao_fetch_service_by_id(service_id)
|
||||||
template = dao_get_template_by_id(notification['template'], version=notification['template_version'])
|
template = dao_get_template_by_id(notification['template'], version=notification['template_version'])
|
||||||
|
|
||||||
if not service_allowed_to_send_to(notification['to'], service, key_type):
|
if not service_allowed_to_send_to(notification['to'], service, KEY_TYPE_NORMAL):
|
||||||
current_app.logger.info("Email {} failed as restricted service".format(notification_id))
|
current_app.logger.info("Email {} failed as restricted service".format(notification_id))
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -252,8 +248,8 @@ def save_email(self,
|
|||||||
service=service,
|
service=service,
|
||||||
personalisation=notification.get('personalisation'),
|
personalisation=notification.get('personalisation'),
|
||||||
notification_type=EMAIL_TYPE,
|
notification_type=EMAIL_TYPE,
|
||||||
api_key_id=api_key_id,
|
api_key_id=None,
|
||||||
key_type=key_type,
|
key_type=KEY_TYPE_NORMAL,
|
||||||
created_at=datetime.utcnow(),
|
created_at=datetime.utcnow(),
|
||||||
job_id=notification.get('job', None),
|
job_id=notification.get('job', None),
|
||||||
job_row_number=notification.get('row_number', None),
|
job_row_number=notification.get('row_number', None),
|
||||||
|
|||||||
@@ -37,8 +37,6 @@ from app.models import (
|
|||||||
NotificationHistory,
|
NotificationHistory,
|
||||||
EMAIL_TYPE,
|
EMAIL_TYPE,
|
||||||
KEY_TYPE_NORMAL,
|
KEY_TYPE_NORMAL,
|
||||||
KEY_TYPE_TEAM,
|
|
||||||
KEY_TYPE_TEST,
|
|
||||||
JOB_STATUS_FINISHED,
|
JOB_STATUS_FINISHED,
|
||||||
JOB_STATUS_ERROR,
|
JOB_STATUS_ERROR,
|
||||||
JOB_STATUS_IN_PROGRESS,
|
JOB_STATUS_IN_PROGRESS,
|
||||||
@@ -489,58 +487,6 @@ def test_should_save_sms_if_restricted_service_and_valid_number(notify_db, notif
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_should_save_sms_if_restricted_service_and_non_team_number_with_test_key(notify_db,
|
|
||||||
notify_db_session,
|
|
||||||
mocker):
|
|
||||||
user = create_user(mobile_number="07700 900205")
|
|
||||||
service = create_sample_service(notify_db, notify_db_session, user=user, restricted=True)
|
|
||||||
template = create_sample_template(notify_db, notify_db_session, service=service)
|
|
||||||
|
|
||||||
notification = _notification_json(template, "07700 900849")
|
|
||||||
mocked_deliver_sms = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
|
|
||||||
|
|
||||||
notification_id = uuid.uuid4()
|
|
||||||
save_sms(
|
|
||||||
service.id,
|
|
||||||
notification_id,
|
|
||||||
encryption.encrypt(notification),
|
|
||||||
key_type=KEY_TYPE_TEST
|
|
||||||
)
|
|
||||||
|
|
||||||
persisted_notification = Notification.query.one()
|
|
||||||
mocked_deliver_sms.assert_called_once_with(
|
|
||||||
[str(persisted_notification.id)],
|
|
||||||
queue="send-sms-tasks"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_should_save_email_if_restricted_service_and_non_team_email_address_with_test_key(notify_db,
|
|
||||||
notify_db_session,
|
|
||||||
mocker):
|
|
||||||
user = create_user()
|
|
||||||
service = create_sample_service(notify_db, notify_db_session, user=user, restricted=True)
|
|
||||||
template = create_sample_template(
|
|
||||||
notify_db, notify_db_session, service=service, template_type='email', subject_line='Hello'
|
|
||||||
)
|
|
||||||
|
|
||||||
notification = _notification_json(template, to="test@example.com")
|
|
||||||
mocked_deliver_email = mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
|
|
||||||
|
|
||||||
notification_id = uuid.uuid4()
|
|
||||||
save_email(
|
|
||||||
service.id,
|
|
||||||
notification_id,
|
|
||||||
encryption.encrypt(notification),
|
|
||||||
key_type=KEY_TYPE_TEST
|
|
||||||
)
|
|
||||||
|
|
||||||
persisted_notification = Notification.query.one()
|
|
||||||
mocked_deliver_email.assert_called_once_with(
|
|
||||||
[str(persisted_notification.id)],
|
|
||||||
queue="send-email-tasks"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_save_email_should_save_default_email_reply_to_text_on_notification(notify_db_session, mocker):
|
def test_save_email_should_save_default_email_reply_to_text_on_notification(notify_db_session, mocker):
|
||||||
service = create_service()
|
service = create_service()
|
||||||
create_reply_to_email(service=service, email_address='reply_to@digital.gov.uk', is_default=True)
|
create_reply_to_email(service=service, email_address='reply_to@digital.gov.uk', is_default=True)
|
||||||
@@ -554,7 +500,6 @@ def test_save_email_should_save_default_email_reply_to_text_on_notification(noti
|
|||||||
service.id,
|
service.id,
|
||||||
notification_id,
|
notification_id,
|
||||||
encryption.encrypt(notification),
|
encryption.encrypt(notification),
|
||||||
key_type=KEY_TYPE_TEST
|
|
||||||
)
|
)
|
||||||
|
|
||||||
persisted_notification = Notification.query.one()
|
persisted_notification = Notification.query.one()
|
||||||
@@ -573,7 +518,6 @@ def test_save_sms_should_save_default_smm_sender_notification_reply_to_text_on(n
|
|||||||
service.id,
|
service.id,
|
||||||
notification_id,
|
notification_id,
|
||||||
encryption.encrypt(notification),
|
encryption.encrypt(notification),
|
||||||
key_type=KEY_TYPE_TEST
|
|
||||||
)
|
)
|
||||||
|
|
||||||
persisted_notification = Notification.query.one()
|
persisted_notification = Notification.query.one()
|
||||||
@@ -644,7 +588,7 @@ def test_should_put_save_email_task_in_research_mode_queue_if_research_mode_serv
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_should_save_sms_template_to_and_persist_with_job_id(sample_job, sample_api_key, mocker):
|
def test_should_save_sms_template_to_and_persist_with_job_id(sample_job, mocker):
|
||||||
notification = _notification_json(
|
notification = _notification_json(
|
||||||
sample_job.template,
|
sample_job.template,
|
||||||
to="+447234123123",
|
to="+447234123123",
|
||||||
@@ -658,8 +602,6 @@ def test_should_save_sms_template_to_and_persist_with_job_id(sample_job, sample_
|
|||||||
sample_job.service.id,
|
sample_job.service.id,
|
||||||
notification_id,
|
notification_id,
|
||||||
encryption.encrypt(notification),
|
encryption.encrypt(notification),
|
||||||
api_key_id=str(sample_api_key.id),
|
|
||||||
key_type=KEY_TYPE_NORMAL
|
|
||||||
)
|
)
|
||||||
persisted_notification = Notification.query.one()
|
persisted_notification = Notification.query.one()
|
||||||
assert persisted_notification.to == '+447234123123'
|
assert persisted_notification.to == '+447234123123'
|
||||||
@@ -670,7 +612,7 @@ def test_should_save_sms_template_to_and_persist_with_job_id(sample_job, sample_
|
|||||||
assert persisted_notification.created_at >= now
|
assert persisted_notification.created_at >= now
|
||||||
assert not persisted_notification.sent_by
|
assert not persisted_notification.sent_by
|
||||||
assert persisted_notification.job_row_number == 2
|
assert persisted_notification.job_row_number == 2
|
||||||
assert persisted_notification.api_key_id == sample_api_key.id
|
assert persisted_notification.api_key_id is None
|
||||||
assert persisted_notification.key_type == KEY_TYPE_NORMAL
|
assert persisted_notification.key_type == KEY_TYPE_NORMAL
|
||||||
assert persisted_notification.notification_type == 'sms'
|
assert persisted_notification.notification_type == 'sms'
|
||||||
|
|
||||||
@@ -680,33 +622,6 @@ def test_should_save_sms_template_to_and_persist_with_job_id(sample_job, sample_
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_should_not_save_email_if_team_key_and_recipient_not_in_team(sample_email_template_with_placeholders,
|
|
||||||
sample_team_api_key,
|
|
||||||
mocker):
|
|
||||||
notification = _notification_json(
|
|
||||||
sample_email_template_with_placeholders,
|
|
||||||
"my_email@my_email.com",
|
|
||||||
{"name": "Jo"},
|
|
||||||
row_number=1)
|
|
||||||
apply_async = mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
|
|
||||||
notification_id = uuid.uuid4()
|
|
||||||
|
|
||||||
team_members = [user.email_address for user in sample_email_template_with_placeholders.service.users]
|
|
||||||
assert "my_email@my_email.com" not in team_members
|
|
||||||
|
|
||||||
save_email(
|
|
||||||
sample_email_template_with_placeholders.service_id,
|
|
||||||
notification_id,
|
|
||||||
encryption.encrypt(notification),
|
|
||||||
api_key_id=str(sample_team_api_key.id),
|
|
||||||
key_type=KEY_TYPE_TEAM
|
|
||||||
)
|
|
||||||
|
|
||||||
assert Notification.query.count() == 0
|
|
||||||
|
|
||||||
apply_async.not_called()
|
|
||||||
|
|
||||||
|
|
||||||
def test_should_not_save_sms_if_team_key_and_recipient_not_in_team(notify_db, notify_db_session, mocker):
|
def test_should_not_save_sms_if_team_key_and_recipient_not_in_team(notify_db, notify_db_session, mocker):
|
||||||
assert Notification.query.count() == 0
|
assert Notification.query.count() == 0
|
||||||
user = create_user(mobile_number="07700 900205")
|
user = create_user(mobile_number="07700 900205")
|
||||||
@@ -747,8 +662,6 @@ def test_should_use_email_template_and_persist(sample_email_template_with_placeh
|
|||||||
sample_email_template_with_placeholders.service_id,
|
sample_email_template_with_placeholders.service_id,
|
||||||
notification_id,
|
notification_id,
|
||||||
encryption.encrypt(notification),
|
encryption.encrypt(notification),
|
||||||
api_key_id=str(sample_api_key.id),
|
|
||||||
key_type=sample_api_key.key_type
|
|
||||||
)
|
)
|
||||||
|
|
||||||
persisted_notification = Notification.query.one()
|
persisted_notification = Notification.query.one()
|
||||||
@@ -762,7 +675,7 @@ def test_should_use_email_template_and_persist(sample_email_template_with_placeh
|
|||||||
assert persisted_notification.job_row_number == 1
|
assert persisted_notification.job_row_number == 1
|
||||||
assert persisted_notification.personalisation == {'name': 'Jo'}
|
assert persisted_notification.personalisation == {'name': 'Jo'}
|
||||||
assert persisted_notification._personalisation == encryption.encrypt({"name": "Jo"})
|
assert persisted_notification._personalisation == encryption.encrypt({"name": "Jo"})
|
||||||
assert persisted_notification.api_key_id == sample_api_key.id
|
assert persisted_notification.api_key_id is None
|
||||||
assert persisted_notification.key_type == KEY_TYPE_NORMAL
|
assert persisted_notification.key_type == KEY_TYPE_NORMAL
|
||||||
assert persisted_notification.notification_type == 'email'
|
assert persisted_notification.notification_type == 'email'
|
||||||
|
|
||||||
@@ -1112,7 +1025,6 @@ def test_save_sms_uses_sms_sender_reply_to_text(mocker, notify_db_session):
|
|||||||
service.id,
|
service.id,
|
||||||
notification_id,
|
notification_id,
|
||||||
encryption.encrypt(notification),
|
encryption.encrypt(notification),
|
||||||
key_type=KEY_TYPE_TEST
|
|
||||||
)
|
)
|
||||||
|
|
||||||
persisted_notification = Notification.query.one()
|
persisted_notification = Notification.query.one()
|
||||||
|
|||||||
Reference in New Issue
Block a user