Use notify to send email verification

This commit is contained in:
Rebecca Law
2016-06-09 16:41:20 +01:00
parent b677768de1
commit cfd31541f4
3 changed files with 90 additions and 14 deletions

View File

@@ -309,18 +309,47 @@ def test_send_sms_code_returns_404_for_bad_input_data(notify_api, notify_db, not
assert json.loads(resp.get_data(as_text=True))['message'] == 'No result found'
@freeze_time("2016-01-01 11:09:00.061258")
def test_send_user_email_verification(notify_api,
sample_email_code,
mock_celery_email_registration_verification,
mock_encryption):
sample_user,
mocker,
email_verification_template):
with notify_api.test_request_context():
with notify_api.test_client() as client:
data = json.dumps({})
mocker.patch('uuid.uuid4', return_value='some_uuid') # for the notification id
mocker.patch('app.encryption.encrypt', return_value="something_encrypted")
mocked = mocker.patch('app.celery.tasks.send_email.apply_async')
auth_header = create_authorization_header()
resp = client.post(
url_for('user.send_user_email_verification', user_id=str(sample_email_code.user.id)),
url_for('user.send_user_email_verification', user_id=str(sample_user.id)),
data=data,
headers=[('Content-Type', 'application/json'), auth_header])
assert resp.status_code == 204
app.celery.tasks.email_registration_verification.apply_async.assert_called_once_with(['something_encrypted'], queue='email-registration-verification') # noqa
assert mocked.call_count == 1
app.celery.tasks.send_email.apply_async.assert_called_once_with(
(str(current_app.config['NOTIFY_SERVICE_ID']),
'some_uuid',
'"GOV.UK Notify" <{}>'.format(current_app.config['VERIFY_CODE_FROM_EMAIL_ADDRESS']),
"something_encrypted",
"2016-01-01T11:09:00.061258"),
queue="email-registration-verification")
def test_send_email_verification_returns_404_for_bad_input_data(notify_api, notify_db, notify_db_session):
"""
Tests POST endpoint /user/<user_id>/sms-code return 404 for bad input data
"""
with notify_api.test_request_context():
with notify_api.test_client() as client:
data = json.dumps({})
import uuid
uuid_ = uuid.uuid4()
auth_header = create_authorization_header()
resp = client.post(
url_for('user.send_user_email_verification', user_id=uuid_),
data=data,
headers=[('Content-Type', 'application/json'), auth_header])
assert resp.status_code == 404
assert json.loads(resp.get_data(as_text=True))['message'] == 'No result found'