mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
Remove send email code task
We don’t send email codes any more
This commit is contained in:
@@ -336,19 +336,6 @@ def send_sms_via_firetext(to, content, reference):
|
|||||||
current_app.logger.exception(e)
|
current_app.logger.exception(e)
|
||||||
|
|
||||||
|
|
||||||
@notify_celery.task(name='send-email-code')
|
|
||||||
def send_email_code(encrypted_verification_message):
|
|
||||||
verification_message = encryption.decrypt(encrypted_verification_message)
|
|
||||||
try:
|
|
||||||
aws_ses_client.send_email(current_app.config['VERIFY_CODE_FROM_EMAIL_ADDRESS'],
|
|
||||||
verification_message['to'],
|
|
||||||
"Verification code",
|
|
||||||
"{} is your Notify authentication code".format(
|
|
||||||
verification_message['secret_code']))
|
|
||||||
except AwsSesClientException as e:
|
|
||||||
current_app.logger.exception(e)
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: when placeholders in templates work, this will be a real template
|
# TODO: when placeholders in templates work, this will be a real template
|
||||||
def invitation_template(user_name, service_name, url, expiry_date):
|
def invitation_template(user_name, service_name, url, expiry_date):
|
||||||
from string import Template
|
from string import Template
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ from app.schemas import (
|
|||||||
|
|
||||||
from app.celery.tasks import (
|
from app.celery.tasks import (
|
||||||
send_sms_code,
|
send_sms_code,
|
||||||
send_email_code,
|
|
||||||
email_reset_password,
|
email_reset_password,
|
||||||
email_registration_verification
|
email_registration_verification
|
||||||
)
|
)
|
||||||
@@ -135,25 +134,6 @@ def send_user_sms_code(user_id):
|
|||||||
return jsonify({}), 204
|
return jsonify({}), 204
|
||||||
|
|
||||||
|
|
||||||
@user.route('/<uuid:user_id>/email-code', methods=['POST'])
|
|
||||||
def send_user_email_code(user_id):
|
|
||||||
user_to_send_to = get_model_users(user_id=user_id)
|
|
||||||
verify_code, errors = request_verify_code_schema.load(request.get_json())
|
|
||||||
if errors:
|
|
||||||
return jsonify(result="error", message=errors), 400
|
|
||||||
|
|
||||||
from app.dao.users_dao import create_secret_code
|
|
||||||
secret_code = create_secret_code()
|
|
||||||
create_user_code(user_to_send_to, secret_code, 'email')
|
|
||||||
|
|
||||||
email = user_to_send_to.email_address if verify_code.get('to', None) is None else verify_code.get('to')
|
|
||||||
verification_message = {'to': email, 'secret_code': secret_code}
|
|
||||||
|
|
||||||
send_email_code.apply_async([encryption.encrypt(verification_message)], queue='email-code')
|
|
||||||
|
|
||||||
return jsonify({}), 204
|
|
||||||
|
|
||||||
|
|
||||||
@user.route('/<uuid:user_id>/email-verification', methods=['POST'])
|
@user.route('/<uuid:user_id>/email-verification', methods=['POST'])
|
||||||
def send_user_email_verification(user_id):
|
def send_user_email_verification(user_id):
|
||||||
user_to_send_to = get_model_users(user_id=user_id)
|
user_to_send_to = get_model_users(user_id=user_id)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ from notifications_utils.recipients import validate_phone_number, format_phone_n
|
|||||||
from app.celery.tasks import (
|
from app.celery.tasks import (
|
||||||
send_sms,
|
send_sms,
|
||||||
send_sms_code,
|
send_sms_code,
|
||||||
send_email_code,
|
|
||||||
send_email,
|
send_email,
|
||||||
process_job,
|
process_job,
|
||||||
email_invited_user,
|
email_invited_user,
|
||||||
@@ -763,23 +762,6 @@ def test_should_throw_mmg_client_exception(mocker):
|
|||||||
'send-sms-code')
|
'send-sms-code')
|
||||||
|
|
||||||
|
|
||||||
def test_should_send_email_code(mocker):
|
|
||||||
verification = {'to': 'someone@it.gov.uk',
|
|
||||||
'secret_code': 11111}
|
|
||||||
|
|
||||||
encrypted_verification = encryption.encrypt(verification)
|
|
||||||
mocker.patch('app.aws_ses_client.send_email')
|
|
||||||
|
|
||||||
send_email_code(encrypted_verification)
|
|
||||||
|
|
||||||
aws_ses_client.send_email.assert_called_once_with(
|
|
||||||
current_app.config['VERIFY_CODE_FROM_EMAIL_ADDRESS'],
|
|
||||||
verification['to'],
|
|
||||||
"Verification code",
|
|
||||||
"{} is your Notify authentication code".format(verification['secret_code'])
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_email_invited_user_should_send_email(notify_api, mocker):
|
def test_email_invited_user_should_send_email(notify_api, mocker):
|
||||||
with notify_api.test_request_context():
|
with notify_api.test_request_context():
|
||||||
invitation = {'to': 'new_person@it.gov.uk',
|
invitation = {'to': 'new_person@it.gov.uk',
|
||||||
|
|||||||
@@ -344,11 +344,6 @@ def mock_celery_send_sms_code(mocker):
|
|||||||
return mocker.patch('app.celery.tasks.send_sms_code.apply_async')
|
return mocker.patch('app.celery.tasks.send_sms_code.apply_async')
|
||||||
|
|
||||||
|
|
||||||
@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')
|
@pytest.fixture(scope='function')
|
||||||
def mock_celery_email_registration_verification(mocker):
|
def mock_celery_email_registration_verification(mocker):
|
||||||
return mocker.patch('app.celery.tasks.email_registration_verification.apply_async')
|
return mocker.patch('app.celery.tasks.email_registration_verification.apply_async')
|
||||||
|
|||||||
@@ -313,51 +313,6 @@ 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'
|
assert json.loads(resp.get_data(as_text=True))['message'] == 'No result found'
|
||||||
|
|
||||||
|
|
||||||
def test_send_user_email_code(notify_api,
|
|
||||||
sample_email_code,
|
|
||||||
mock_celery_send_email_code,
|
|
||||||
mock_encryption):
|
|
||||||
"""
|
|
||||||
Tests POST endpoint /user/<user_id>/email-code
|
|
||||||
"""
|
|
||||||
with notify_api.test_request_context():
|
|
||||||
with notify_api.test_client() as client:
|
|
||||||
data = json.dumps({})
|
|
||||||
auth_header = create_authorization_header(
|
|
||||||
path=url_for('user.send_user_email_code', user_id=sample_email_code.user.id),
|
|
||||||
method='POST',
|
|
||||||
request_body=data)
|
|
||||||
resp = client.post(
|
|
||||||
url_for('user.send_user_email_code', user_id=sample_email_code.user.id),
|
|
||||||
data=data,
|
|
||||||
headers=[('Content-Type', 'application/json'), auth_header])
|
|
||||||
assert resp.status_code == 204
|
|
||||||
app.celery.tasks.send_email_code.apply_async.assert_called_once_with(['something_encrypted'],
|
|
||||||
queue='email-code')
|
|
||||||
|
|
||||||
|
|
||||||
def test_send_user_email_code_returns_404_for_when_user_does_not_exist(notify_api,
|
|
||||||
notify_db,
|
|
||||||
notify_db_session,
|
|
||||||
fake_uuid):
|
|
||||||
"""
|
|
||||||
Tests POST endpoint /user/<user_id>/email-code return 404 for missing user
|
|
||||||
"""
|
|
||||||
with notify_api.test_request_context():
|
|
||||||
with notify_api.test_client() as client:
|
|
||||||
data = json.dumps({})
|
|
||||||
auth_header = create_authorization_header(
|
|
||||||
path=url_for('user.send_user_email_code', user_id=fake_uuid),
|
|
||||||
method='POST',
|
|
||||||
request_body=data)
|
|
||||||
resp = client.post(
|
|
||||||
url_for('user.send_user_email_code', user_id=fake_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'
|
|
||||||
|
|
||||||
|
|
||||||
def test_send_user_email_verification(notify_api,
|
def test_send_user_email_verification(notify_api,
|
||||||
sample_email_code,
|
sample_email_code,
|
||||||
mock_celery_email_registration_verification,
|
mock_celery_email_registration_verification,
|
||||||
|
|||||||
Reference in New Issue
Block a user