Merge branch 'master' into split-sms-and-retry

This commit is contained in:
Martyn Inglis
2016-06-13 11:39:13 +01:00
24 changed files with 352 additions and 87 deletions

View File

@@ -20,6 +20,8 @@ def test_make_mmg_callback(notify_api, rmock):
send_sms_response("mmg", "1234", "07811111111")
assert rmock.called
assert rmock.request_history[0].url == endpoint
assert json.loads(rmock.request_history[0].text)['MSISDN'] == '07811111111'
def test_make_firetext_callback(notify_api, rmock):
@@ -32,6 +34,8 @@ def test_make_firetext_callback(notify_api, rmock):
send_sms_response("firetext", "1234", "07811111111")
assert rmock.called
assert rmock.request_history[0].url == endpoint
assert 'mobile=07811111111' in rmock.request_history[0].text
def test_make_ses_callback(notify_api, rmock):
@@ -71,11 +75,21 @@ def test_temp_failure_mmg_callback():
def test_delivered_firetext_callback():
assert firetext_callback("1234", "07811111111") == "mobile=07811111111&status=0&time=2016-03-10 14:17:00&reference=1234" # noqa
assert firetext_callback('1234', '07811111111') == {
'mobile': '07811111111',
'status': '0',
'time': '2016-03-10 14:17:00',
'reference': '1234'
}
def test_failure_firetext_callback():
assert firetext_callback("1234", "07822222222") == "mobile=07822222222&status=1&time=2016-03-10 14:17:00&reference=1234" # noqa
assert firetext_callback('1234', '07822222222') == {
'mobile': '07822222222',
'status': '1',
'time': '2016-03-10 14:17:00',
'reference': '1234'
}
def test_delivered_ses_callback():

View File

@@ -7,7 +7,6 @@ from notifications_utils.recipients import validate_phone_number, format_phone_n
from app.celery import provider_tasks
from app.celery.tasks import (
send_sms,
send_sms_code,
send_email,
process_job,
email_invited_user,
@@ -16,7 +15,8 @@ from app.celery.tasks import (
delete_invitations,
delete_failed_notifications,
delete_successful_notifications,
provider_to_use
provider_to_use,
timeout_notifications
)
from app.celery.research_mode_tasks import (
send_email_response,
@@ -807,33 +807,6 @@ def test_should_not_send_email_if_db_peristance_failed(sample_email_template, mo
assert 'No row was found for one' in str(e.value)
def test_should_send_sms_code(mocker):
notification = {'to': '+447234123123',
'secret_code': '12345'}
encrypted_notification = encryption.encrypt(notification)
mocker.patch('app.mmg_client.send_sms')
send_sms_code(encrypted_notification)
mmg_client.send_sms.assert_called_once_with(
format_phone_number(validate_phone_number(notification['to'])),
"{} is your Notify authentication code".format(notification['secret_code']),
'send-sms-code')
def test_should_throw_mmg_client_exception(mocker):
notification = {'to': '+447234123123',
'secret_code': '12345'}
encrypted_notification = encryption.encrypt(notification)
mocker.patch('app.mmg_client.send_sms', side_effect=MMGClientException(mmg_error))
send_sms_code(encrypted_notification)
mmg_client.send_sms.assert_called_once_with(
format_phone_number(validate_phone_number(notification['to'])),
"{} is your Notify authentication code".format(notification['secret_code']),
'send-sms-code')
def test_email_invited_user_should_send_email(notify_api, mocker):
with notify_api.test_request_context():
invitation = {'to': 'new_person@it.gov.uk',
@@ -1016,3 +989,41 @@ def _notification_json(template, to, personalisation=None, job_id=None, row_numb
if row_number:
notification['row_number'] = row_number
return notification
def test_update_status_of_notifications_after_timeout(notify_api,
notify_db,
notify_db_session,
sample_service,
sample_template,
mmg_provider):
with notify_api.test_request_context():
not1 = sample_notification(
notify_db,
notify_db_session,
service=sample_service,
template=sample_template,
status='sending',
created_at=datetime.utcnow() - timedelta(
seconds=current_app.config.get('SENDING_NOTIFICATIONS_TIMEOUT_PERIOD') + 10))
timeout_notifications()
assert not1.status == 'temporary-failure'
def test_not_update_status_of_notification_before_timeout(notify_api,
notify_db,
notify_db_session,
sample_service,
sample_template,
mmg_provider):
with notify_api.test_request_context():
not1 = sample_notification(
notify_db,
notify_db_session,
service=sample_service,
template=sample_template,
status='sending',
created_at=datetime.utcnow() - timedelta(
seconds=current_app.config.get('SENDING_NOTIFICATIONS_TIMEOUT_PERIOD') - 10))
timeout_notifications()
assert not1.status == 'sending'