Updated notifications_utils version and associated code. Added email subject formatting for placeholders.

This commit is contained in:
Nicholas Staples
2016-04-14 12:00:55 +01:00
parent 33cc90488c
commit 3865c722fc
17 changed files with 35 additions and 23 deletions

View File

@@ -45,14 +45,22 @@ def service_json(id_, name, users, message_limit=1000, active=False, restricted=
}
def template_json(service_id, id_, name="sample template", type_="sms", content="template content"):
return {
def template_json(service_id,
id_,
name="sample template",
type_="sms",
content="template content",
subject=None):
template = {
'id': id_,
'name': name,
'template_type': type_,
'content': content,
'service': service_id
}
if subject is not None:
template['subject'] = subject
return template
def api_key_json(id_, name, expiry_date=None):

View File

@@ -2,7 +2,7 @@ import json
from datetime import datetime
from flask import url_for
from utils.url_safe_token import generate_token
from notifications_utils.url_safe_token import generate_token
def test_should_render_new_password_template(app_,

View File

@@ -76,7 +76,7 @@ def test_verify_email_redirects_to_verify_if_token_valid(app_,
mock_check_verify_code):
import json
token_data = {"user_id": api_user_pending.id, "secret_code": 12345}
mocker.patch('utils.url_safe_token.check_token', return_value=json.dumps(token_data))
mocker.patch('app.main.views.verify.check_token', return_value=json.dumps(token_data))
with app_.test_request_context():
with app_.test_client() as client:
@@ -94,7 +94,7 @@ def test_verify_email_redirects_to_email_sent_if_token_expired(app_,
api_user_pending,
mock_check_verify_code):
from itsdangerous import SignatureExpired
mocker.patch('utils.url_safe_token.check_token', side_effect=SignatureExpired('expired'))
mocker.patch('app.main.views.verify.check_token', side_effect=SignatureExpired('expired'))
with app_.test_request_context():
with app_.test_client() as client:
@@ -114,7 +114,7 @@ def test_verify_email_redirects_to_email_sent_if_token_used(app_,
mock_send_verify_code,
mock_check_verify_code_code_expired):
from itsdangerous import SignatureExpired
mocker.patch('utils.url_safe_token.check_token', side_effect=SignatureExpired('expired'))
mocker.patch('app.main.views.verify.check_token', side_effect=SignatureExpired('expired'))
with app_.test_request_context():
with app_.test_client() as client:
@@ -135,7 +135,7 @@ def test_verify_email_redirects_to_sign_in_if_user_active(app_,
mock_check_verify_code):
import json
token_data = {"user_id": api_user_active.id, "secret_code": 12345}
mocker.patch('utils.url_safe_token.check_token', return_value=json.dumps(token_data))
mocker.patch('app.main.views.verify.check_token', return_value=json.dumps(token_data))
with app_.test_request_context():
with app_.test_client() as client:

View File

@@ -180,7 +180,11 @@ def mock_get_service_template(mocker):
def mock_get_service_email_template(mocker):
def _create(service_id, template_id):
template = template_json(
service_id, template_id, "Two week reminder", "email", "Your vehicle tax is about to expire")
service_id,
template_id,
"Two week reminder",
"email",
"Your vehicle tax is about to expire", "Subject")
return {'data': template}
return mocker.patch(