mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
Add new email template for the GOV.UK Notify service, to send an email to users that register with the same email address.
Add a new endpoint to send the email.
This commit is contained in:
@@ -699,3 +699,38 @@ def password_reset_email_template(notify_db,
|
||||
template = Template(**data)
|
||||
db.session.add(template)
|
||||
return template
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def already_registered_template(notify_db,
|
||||
notify_db_session):
|
||||
user = sample_user(notify_db, notify_db_session)
|
||||
service = Service.query.get(current_app.config['NOTIFY_SERVICE_ID'])
|
||||
if not service:
|
||||
data = {
|
||||
'id': current_app.config['NOTIFY_SERVICE_ID'],
|
||||
'name': 'Notify Service',
|
||||
'message_limit': 1000,
|
||||
'active': True,
|
||||
'restricted': False,
|
||||
'email_from': 'notify.service',
|
||||
'created_by': user
|
||||
}
|
||||
service = Service(**data)
|
||||
db.session.add(service)
|
||||
|
||||
template = Template.query.get(current_app.config['ALREADY_REGISTERED_EMAIL_TEMPLATE_ID'])
|
||||
if not template:
|
||||
data = {
|
||||
'id': current_app.config['ALREADY_REGISTERED_EMAIL_TEMPLATE_ID'],
|
||||
'name': 'ALREADY_REGISTERED_EMAIL_TEMPLATE_ID',
|
||||
'template_type': 'email',
|
||||
'content': """Sign in here: ((signin_url)) If you’ve forgotten your password,
|
||||
you can reset it here: ((forgot_password_url)) feedback:((feedback_url))""",
|
||||
'service': service,
|
||||
'created_by': user,
|
||||
'archived': False
|
||||
}
|
||||
template = Template(**data)
|
||||
db.session.add(template)
|
||||
return template
|
||||
|
||||
@@ -455,3 +455,35 @@ def test_send_user_reset_password_should_return_400_when_data_is_not_email_addre
|
||||
|
||||
assert resp.status_code == 400
|
||||
assert json.loads(resp.get_data(as_text=True))['message'] == {'email': ['Not a valid email address']}
|
||||
|
||||
|
||||
@freeze_time("2016-01-01 11:09:00.061258")
|
||||
def test_send_already_registered_email(notify_api, sample_user, already_registered_template, mocker):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
data = json.dumps({'to': sample_user.email_address})
|
||||
auth_header = create_authorization_header()
|
||||
mocker.patch('app.celery.tasks.send_email.apply_async')
|
||||
mocker.patch('uuid.uuid4', return_value='some_uuid') # for the notification id
|
||||
|
||||
resp = client.post(
|
||||
url_for('user.send_already_registered_email', user_id=str(sample_user.id)),
|
||||
data=data,
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
assert resp.status_code == 204
|
||||
message = {
|
||||
'template': str(already_registered_template.id),
|
||||
'template_version': already_registered_template.version,
|
||||
'to': sample_user.email_address,
|
||||
'personalisation': {
|
||||
'signin_url': current_app.config['ADMIN_BASE_URL'] + '/sign-in',
|
||||
'forgot_password_url': current_app.config['ADMIN_BASE_URL'] + '/forgot-password',
|
||||
'feedback_url': current_app.config['ADMIN_BASE_URL'] + '/feedback'
|
||||
}
|
||||
}
|
||||
app.celery.tasks.send_email.apply_async.assert_called_once_with(
|
||||
(str(current_app.config['NOTIFY_SERVICE_ID']),
|
||||
'some_uuid',
|
||||
app.encryption.encrypt(message),
|
||||
"2016-01-01T11:09:00.061258"),
|
||||
queue="email-already-registered")
|
||||
|
||||
Reference in New Issue
Block a user