Merge pull request #181 from alphagov/test-text

Add flow for sending yourself a text message
This commit is contained in:
Rebecca Law
2016-02-18 17:19:05 +00:00
6 changed files with 89 additions and 9 deletions

View File

@@ -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;
}
}
}

View File

@@ -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/<service_id>/sms/send/<template_id>/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/<service_id>/sms/check/<upload_id>",
methods=['GET', 'POST'])
@login_required

View File

@@ -20,8 +20,9 @@
{{ sms_message(template.formatted_as_markup, name=template.name) }}
</div>
<div class="column-one-third">
<div class="sms-message-use-link">
<a href="{{ url_for(".send_sms", service_id=service_id, template_id=template.id) }}">Use this template</a>
<div class="sms-message-use-links">
<a href="{{ url_for(".send_sms", service_id=service_id, template_id=template.id) }}">Add recipients</a>
<a href="{{ url_for(".send_sms_to_self", service_id=service_id, template_id=template.id) }}">Send yourself a test</a>
</div>
</div>
{% endfor %}

View File

@@ -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,

View File

@@ -10,7 +10,7 @@
{% block maincolumn_content %}
<h1 class="heading-large">Send text messages</h1>
<h1 class="heading-large">Add recipients</h1>
<form method="POST" enctype="multipart/form-data">

View File

@@ -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,