From 2a9f9dcc577ca646c13cfb079dbef2560ade5d42 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 18 Feb 2016 07:44:50 +0000 Subject: [PATCH 1/3] Add a hint about how to use placeholders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since placeholders (almost) work now, it’s worth telling people what the syntax is. This commit also removes the ‘template type’ picker, since you can only create SMS templates at the moment. This will be revisited when we start looking at how you add an email template. --- app/main/views/templates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main/views/templates.py b/app/main/views/templates.py index a8453f9e5..c52c90d8a 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -48,7 +48,7 @@ def add_service_template(service_id): if form.validate_on_submit(): tdao.insert_service_template( - form.name.data, form.template_content.data, service_id) + form.name.data, 'sms', form.template_content.data, service_id) return redirect(url_for( '.manage_service_templates', service_id=service_id)) return render_template( From eec56c277889324a6b1e272d9c236b99bf9eb614 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Fri, 12 Feb 2016 10:55:21 +0000 Subject: [PATCH 2/3] Add flow for sending yourself a text message This commit adds a shortcut, which (in the background) does the creation and uploading of a CSV file for you. This enables users to send themselves a test message without having to fiddle about with CSV files. --- .../stylesheets/components/sms-message.scss | 19 ++++++++++++--- app/main/views/sms.py | 23 +++++++++++++++++-- app/main/views/templates.py | 2 +- app/templates/views/choose-sms-template.html | 5 ++-- app/templates/views/job.html | 2 +- app/templates/views/send-sms.html | 2 +- 6 files changed, 43 insertions(+), 10 deletions(-) diff --git a/app/assets/stylesheets/components/sms-message.scss b/app/assets/stylesheets/components/sms-message.scss index 41b0e0dfb..9fbe0b1af 100644 --- a/app/assets/stylesheets/components/sms-message.scss +++ b/app/assets/stylesheets/components/sms-message.scss @@ -36,7 +36,20 @@ z-index: 50; } -.sms-message-use-link { - @include bold-19; - margin-top: 70px; +.sms-message-use-links { + + @include copy-19; + margin-top: 55px; + + a { + + display: block; + margin-bottom: 5px; + + &:first-child { + @include bold-19; + } + + } + } diff --git a/app/main/views/sms.py b/app/main/views/sms.py index 958a549e0..61a6f62cc 100644 --- a/app/main/views/sms.py +++ b/app/main/views/sms.py @@ -1,8 +1,7 @@ import csv +import io import uuid import botocore -import re -import io from datetime import date @@ -102,6 +101,26 @@ def get_example_csv(service_id, template_id): return(output.getvalue(), 200, {'Content-Type': 'text/csv; charset=utf-8'}) +@main.route("/services//sms/send//to-self", methods=['GET']) +@login_required +def send_sms_to_self(service_id, template_id): + output = io.StringIO() + writer = csv.writer(output) + writer.writerow(['phone']) + writer.writerow([current_user.mobile_number]) + filedata = { + 'file_name': 'Test run', + 'data': output.getvalue().splitlines() + } + upload_id = str(uuid.uuid4()) + s3upload(upload_id, service_id, filedata, current_app.config['AWS_REGION']) + session['upload_data'] = {"template_id": template_id, "original_file_name": filedata['file_name']} + + return redirect(url_for('.check_sms', + service_id=service_id, + upload_id=upload_id)) + + @main.route("/services//sms/check/", methods=['GET', 'POST']) @login_required diff --git a/app/main/views/templates.py b/app/main/views/templates.py index c52c90d8a..a8453f9e5 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -48,7 +48,7 @@ def add_service_template(service_id): if form.validate_on_submit(): tdao.insert_service_template( - form.name.data, 'sms', form.template_content.data, service_id) + form.name.data, form.template_content.data, service_id) return redirect(url_for( '.manage_service_templates', service_id=service_id)) return render_template( diff --git a/app/templates/views/choose-sms-template.html b/app/templates/views/choose-sms-template.html index 383d34834..d069c8b13 100644 --- a/app/templates/views/choose-sms-template.html +++ b/app/templates/views/choose-sms-template.html @@ -20,8 +20,9 @@ {{ sms_message(template.formatted_as_markup, name=template.name) }}
- {% endfor %} diff --git a/app/templates/views/job.html b/app/templates/views/job.html index 40af13526..0c038141c 100644 --- a/app/templates/views/job.html +++ b/app/templates/views/job.html @@ -52,7 +52,7 @@ {% call(item) list_table( [ - {'row': 1, 'phone': '+447700 900995', 'template': template['name'], 'status': 'queued'} + {'row': 1, 'phone': '+447700 900995', 'template': template['name'], 'status': 'sent'} ], caption=uploaded_file_name, caption_visible=False, diff --git a/app/templates/views/send-sms.html b/app/templates/views/send-sms.html index 15671cc60..097fe142e 100644 --- a/app/templates/views/send-sms.html +++ b/app/templates/views/send-sms.html @@ -10,7 +10,7 @@ {% block maincolumn_content %} -

Send text messages

+

Add recipients

From a5945969c98aaaa1ca3349095d8c0b4b50dc7dba Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 18 Feb 2016 17:03:32 +0000 Subject: [PATCH 3/3] Add tests for new routes --- tests/app/main/views/test_sms.py | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/app/main/views/test_sms.py b/tests/app/main/views/test_sms.py index d3609afb4..470847848 100644 --- a/tests/app/main/views/test_sms.py +++ b/tests/app/main/views/test_sms.py @@ -69,6 +69,53 @@ def test_upload_csvfile_with_invalid_phone_shows_check_page_with_errors(app_, assert 'Choose a CSV file' in content +@moto.mock_s3 +def test_send_test_message_to_self( + app_, + mocker, + api_user_active, + mock_login, + mock_get_user, + mock_get_user_by_email, + mock_get_service_template +): + + with app_.test_request_context(): + with app_.test_client() as client: + client.login(api_user_active) + response = client.get( + url_for('main.send_sms_to_self', service_id=12345, template_id=54321), + follow_redirects=True + ) + assert response.status_code == 200 + content = response.get_data(as_text=True) + assert 'Test run' in content + assert '+4412341234' in content + + +@moto.mock_s3 +def test_download_example_csv( + app_, + mocker, + api_user_active, + mock_login, + mock_get_user, + mock_get_user_by_email, + mock_get_service_template +): + + with app_.test_request_context(): + with app_.test_client() as client: + client.login(api_user_active) + response = client.get( + url_for('main.get_example_csv', service_id=12345, template_id=54321), + follow_redirects=True + ) + assert response.status_code == 200 + assert response.get_data(as_text=True) == 'phone\r\n+4412341234\r\n' + assert 'text/csv' in response.headers['Content-Type'] + + @moto.mock_s3 def test_upload_csvfile_with_valid_phone_shows_all_numbers(app_, mocker,