diff --git a/app/main/views/_templates.py b/app/main/views/_templates.py deleted file mode 100644 index 6d20217ce..000000000 --- a/app/main/views/_templates.py +++ /dev/null @@ -1,12 +0,0 @@ -templates = [ - { - 'type': 'sms', - 'name': 'Confirmation with details Jan 2016', - 'body': '((name)), we’ve received your ((thing)). We’ll contact you again within 1 week.' - }, - { - 'type': 'sms', - 'name': 'Confirmation Jan 2016', - 'body': 'We’ve received your payment. We’ll contact you again within 1 week.' - } -] diff --git a/app/main/views/sms.py b/app/main/views/sms.py index 9e937bea7..65f0c6fe3 100644 --- a/app/main/views/sms.py +++ b/app/main/views/sms.py @@ -24,12 +24,7 @@ from app.main.uploader import ( s3upload, s3download ) - -from ._templates import templates - -sms_templates = [ - template for template in templates if template['type'] == 'sms' -] +from app.main.dao import templates_dao @main.route("/services//sms/send", methods=['GET', 'POST']) @@ -51,8 +46,16 @@ def send_sms(service_id): flash(str(e)) return redirect(url_for('.send_sms', service_id=service_id)) + try: + templates = templates_dao.get_service_templates(service_id)['data'] + except HTTPError as e: + if e.status_code == 404: + abort(404) + else: + raise e + return render_template('views/send-sms.html', - message_templates=sms_templates, + templates=templates, form=form, service_id=service_id) @@ -69,7 +72,9 @@ def check_sms(service_id, upload_id): 'views/check-sms.html', upload_result=upload_result, filename='someupload_file_name.csv', - message_template=sms_templates[0]['body'], + message_template=''' + ((name)), we’ve received your ((thing)). We’ll contact you again within 1 week. + ''', service_id=service_id ) elif request.method == 'POST': diff --git a/app/templates/components/sms-message.html b/app/templates/components/sms-message.html index f526d696d..21efc76d7 100644 --- a/app/templates/components/sms-message.html +++ b/app/templates/components/sms-message.html @@ -14,7 +14,7 @@ {% endif %} {% if input_name %} - + {% endif %}
{{ body|placeholders }} diff --git a/app/templates/views/send-sms.html b/app/templates/views/send-sms.html index bde6433ba..4ec63b201 100644 --- a/app/templates/views/send-sms.html +++ b/app/templates/views/send-sms.html @@ -17,9 +17,9 @@
1. Choose text message template - {% for template in message_templates %} + {% for template in templates %} {{ sms_message( - template.body, name=template.name, input_name='template', input_index=loop.index + template.content, name=template.name, input_name='template', input_index=template.id ) }} {% endfor %}
diff --git a/tests/app/main/views/test_sms.py b/tests/app/main/views/test_sms.py index 4bb8ccabe..7285b4b0d 100644 --- a/tests/app/main/views/test_sms.py +++ b/tests/app/main/views/test_sms.py @@ -4,12 +4,32 @@ from flask import url_for import moto +def test_choose_template_page(app_, + db_, + db_session, + mock_send_sms, + mock_active_user, + mock_get_by_email, + mock_get_service_templates): + with app_.test_request_context(): + with app_.test_client() as client: + client.login(mock_active_user) + upload_data = {'file': (BytesIO(''.encode('utf-8')), 'emtpy.csv')} + response = client.get(url_for('main.send_sms', service_id=123)) + + assert response.status_code == 200 + content = response.get_data(as_text=True) + assert 'template_one' in content + assert 'template one content' in content + + def test_upload_empty_csvfile_returns_to_upload_page(app_, db_, db_session, mock_send_sms, mock_active_user, - mock_get_by_email): + mock_get_by_email, + mock_get_service_templates): with app_.test_request_context(): with app_.test_client() as client: client.login(mock_active_user) @@ -25,7 +45,8 @@ def test_upload_empty_csvfile_returns_to_upload_page(app_, @moto.mock_s3 def test_upload_csvfile_with_invalid_phone_shows_check_page_with_errors(app_, mock_active_user, - mock_get_by_email): + mock_get_by_email, + mock_get_service_template): contents = 'phone\n+44 123\n+44 456' file_data = (BytesIO(contents.encode('utf-8')), 'invalid.csv')