Use celery to send the email verification code.

This commit is contained in:
Rebecca Law
2016-02-18 09:52:27 +00:00
parent 9073814d9f
commit c1df61a7d4
6 changed files with 36 additions and 34 deletions

View File

@@ -98,17 +98,17 @@ def test_should_log_firetext_client_exception(mocker):
def test_should_send_email_code(mocker):
notification = {'to_address': 'someone@it.gov.uk',
verification = {'to_address': 'someone@it.gov.uk',
'from_address': 'no-reply@notify.gov.uk',
'subject': 'Verification code',
'body': 11111}
encrypted_notification = encryption.encrypt(notification)
encrypted_verification = encryption.encrypt(verification)
mocker.patch('app.aws_ses_client.send_email')
send_email_code(encrypted_notification)
send_email_code(encrypted_verification)
aws_ses_client.send_email.assert_called_once_with((notification['from_address'],
notification['to_address'],
notification['subject'],
notification['body']))
aws_ses_client.send_email.assert_called_once_with(verification['from_address'],
verification['to_address'],
verification['subject'],
verification['body'])

View File

@@ -212,3 +212,8 @@ def mock_celery_send_sms_code(mocker):
@pytest.fixture(scope='function')
def mock_celery_send_email_code(mocker):
return mocker.patch('app.celery.tasks.send_email_code.apply_async')
@pytest.fixture(scope='function')
def mock_encryption(mocker):
return mocker.patch('app.encryption.encrypt', return_value="something_encrypted")

View File

@@ -301,7 +301,8 @@ def test_send_user_code_for_sms_with_optional_to_field(notify_api,
def test_send_user_code_for_email(notify_api,
sample_email_code,
mock_secret_code,
mock_celery_send_email_code):
mock_celery_send_email_code,
mock_encryption):
"""
Tests POST endpoint '/<user_id>/code' successful email
"""
@@ -317,18 +318,16 @@ def test_send_user_code_for_email(notify_api,
data=data,
headers=[('Content-Type', 'application/json'), auth_header])
assert resp.status_code == 204
notification = {'to_address': sample_email_code.user.email_address,
'from_address': notify_api.config['VERIFY_CODE_FROM_EMAIL_ADDRESS'],
'subject': 'Verification code',
'body': 11111}
encrypted = encryption.encrypt([notification])
app.celery.tasks.send_email_code.apply_async.assert_called_once_with([encrypted], queue='email_code')
app.celery.tasks.send_email_code.apply_async.assert_called_once_with(['something_encrypted'],
queue='email_code')
def test_send_user_code_for_email_uses_optional_to_field(notify_api,
sample_email_code,
mock_secret_code,
mock_celery_send_email_code):
mock_celery_send_email_code,
mock_encryption):
"""
Tests POST endpoint '/<user_id>/code' successful email with included in body
"""
@@ -344,13 +343,9 @@ def test_send_user_code_for_email_uses_optional_to_field(notify_api,
data=data,
headers=[('Content-Type', 'application/json'), auth_header])
assert resp.status_code == 204
notification = json.dumps({'to_address': 'different@email.gov.uk',
'from_address': 'no-reply@notify.works',
'subject': 'Verification code',
'body': '11111'})
encrypted = encryption.encrypt([notification])
app.celery.tasks.send_email_code.apply_async.assert_called_once_with([encrypted], queue='email_code')
app.celery.tasks.send_email_code.apply_async.assert_called_once_with(['something_encrypted'],
queue='email_code')
def test_request_verify_code_schema_invalid_code_type(notify_api, notify_db, notify_db_session, sample_user):