Merge branch 'master' into research-mode-implementation

This commit is contained in:
Martyn Inglis
2016-06-01 17:06:38 +01:00
2 changed files with 8 additions and 15 deletions

View File

@@ -220,13 +220,11 @@ def send_sms(service_id, notification_id, encrypted_notification, created_at):
provider = provider_to_use('sms', notification_id)
restricted = False
if not service_allowed_to_send_to(notification['to'], service):
current_app.logger.info(
"SMS {} failed as restricted service".format(notification_id)
)
restricted = True
return
try:
@@ -245,7 +243,7 @@ def send_sms(service_id, notification_id, encrypted_notification, created_at):
service_id=service_id,
job_id=notification.get('job', None),
job_row_number=notification.get('row_number', None),
status='failed' if restricted else 'sending',
status='sending',
created_at=datetime.strptime(created_at, DATETIME_FORMAT),
sent_at=sent_at,
sent_by=provider.get_name(),
@@ -258,9 +256,6 @@ def send_sms(service_id, notification_id, encrypted_notification, created_at):
)
dao_create_notification(notification_db_object, TEMPLATE_TYPE_SMS, provider.get_name())
if restricted:
return
try:
if service.research_mode:
send_sms_response.apply_async(
@@ -298,13 +293,11 @@ def send_email(service_id, notification_id, from_address, encrypted_notification
provider = provider_to_use('email', notification_id)
restricted = False
if not service_allowed_to_send_to(notification['to'], service):
current_app.logger.info(
"Email {} failed as restricted service".format(notification_id)
)
restricted = True
return
try:
sent_at = datetime.utcnow()
@@ -316,7 +309,7 @@ def send_email(service_id, notification_id, from_address, encrypted_notification
service_id=service_id,
job_id=notification.get('job', None),
job_row_number=notification.get('row_number', None),
status='failed' if restricted else 'sending',
status='sending',
created_at=datetime.strptime(created_at, DATETIME_FORMAT),
sent_at=sent_at,
sent_by=provider.get_name()
@@ -329,9 +322,6 @@ def send_email(service_id, notification_id, from_address, encrypted_notification
datetime.strptime(created_at, DATETIME_FORMAT)
)
if restricted:
return
try:
template = Template(
dao_get_template_by_id(notification['template'], notification['template_version']).__dict__,

View File

@@ -460,8 +460,9 @@ def test_should_not_send_sms_if_restricted_service_and_invalid_number(notify_db,
"encrypted-in-reality",
now.strftime(DATETIME_FORMAT)
)
mmg_client.send_sms.assert_not_called()
with pytest.raises(NoResultFound):
notifications_dao.get_notification(service.id, notification_id)
def test_send_sms_should_use_template_version_from_job_not_latest(sample_template, mocker):
@@ -561,6 +562,8 @@ def test_should_not_send_email_if_restricted_service_and_invalid_email_address(n
)
aws_ses_client.send_email.assert_not_called()
with pytest.raises(NoResultFound):
notifications_dao.get_notification(service.id, notification_id)
def test_should_send_template_to_correct_sms_provider_and_persist_with_job_id(sample_job, mocker):