Files
notifications-admin/tests/app/main/views/test_sms.py

132 lines
6.1 KiB
Python
Raw Normal View History

from io import BytesIO
from flask import url_for
import moto
2016-01-21 11:33:53 +00:00
def test_upload_empty_csvfile_returns_to_upload_page(app_, db_, db_session,
mock_api_user,
mock_user_loader,
mock_user_dao_get_by_email):
2016-01-15 15:15:35 +00:00
with app_.test_request_context():
with app_.test_client() as client:
2016-01-21 11:33:53 +00:00
client.login(mock_api_user)
upload_data = {'file': (BytesIO(''.encode('utf-8')), 'emtpy.csv')}
2016-01-19 09:49:01 +00:00
response = client.post(url_for('main.send_sms', service_id=123),
data=upload_data, follow_redirects=True)
assert response.status_code == 200
content = response.get_data(as_text=True)
assert 'The file emtpy.csv contained no data' in content
@moto.mock_s3
2016-01-19 09:49:01 +00:00
def test_upload_csvfile_with_invalid_phone_shows_check_page_with_errors(app_,
db_,
db_session,
mocker,
2016-01-21 11:33:53 +00:00
mock_api_user,
mock_user_loader,
mock_user_dao_get_by_email):
2016-01-13 22:34:36 +00:00
contents = 'phone\n+44 123\n+44 456'
file_data = (BytesIO(contents.encode('utf-8')), 'invalid.csv')
2016-01-15 15:15:35 +00:00
with app_.test_request_context():
with app_.test_client() as client:
2016-01-21 11:33:53 +00:00
client.login(mock_api_user)
2016-01-13 22:34:36 +00:00
upload_data = {'file': file_data}
2016-01-19 09:49:01 +00:00
response = client.post(url_for('main.send_sms', service_id=123),
data=upload_data,
follow_redirects=True)
assert response.status_code == 200
content = response.get_data(as_text=True)
assert 'The following numbers are invalid' in content
assert '+44 123' in content
assert '+44 456' in content
assert 'Go back and resolve errors' in content
@moto.mock_s3
2016-01-19 09:49:01 +00:00
def test_upload_csvfile_with_valid_phone_shows_first3_and_last3_numbers(app_,
db_,
db_session,
mocker,
2016-01-21 11:33:53 +00:00
mock_api_user,
mock_user_loader,
mock_user_dao_get_by_email):
2016-01-13 22:34:36 +00:00
contents = 'phone\n+44 7700 900981\n+44 7700 900982\n+44 7700 900983\n+44 7700 900984\n+44 7700 900985\n+44 7700 900986\n+44 7700 900987\n+44 7700 900988\n+44 7700 900989' # noqa
file_data = (BytesIO(contents.encode('utf-8')), 'valid.csv')
2016-01-15 15:15:35 +00:00
with app_.test_request_context():
with app_.test_client() as client:
2016-01-21 11:33:53 +00:00
client.login(mock_api_user)
2016-01-13 22:34:36 +00:00
upload_data = {'file': file_data}
2016-01-19 09:49:01 +00:00
response = client.post(url_for('main.send_sms', service_id=123),
data=upload_data,
follow_redirects=True)
content = response.get_data(as_text=True)
assert response.status_code == 200
assert 'Check and confirm' in content
assert 'First three message in file' in content
assert 'Last three messages in file' in content
assert '+44 7700 900981' in content
assert '+44 7700 900982' in content
assert '+44 7700 900983' in content
assert '+44 7700 900984' not in content
assert '+44 7700 900985' not in content
assert '+44 7700 900986' not in content
assert '+44 7700 900987' in content
assert '+44 7700 900988' in content
assert '+44 7700 900989' in content
@moto.mock_s3
2016-01-19 09:49:01 +00:00
def test_upload_csvfile_with_valid_phone_shows_all_if_6_or_less_numbers(app_,
db_,
db_session,
mocker,
2016-01-21 11:33:53 +00:00
mock_api_user,
mock_user_loader,
mock_user_dao_get_by_email):
2016-01-13 22:34:36 +00:00
contents = 'phone\n+44 7700 900981\n+44 7700 900982\n+44 7700 900983\n+44 7700 900984\n+44 7700 900985\n+44 7700 900986' # noqa
file_data = (BytesIO(contents.encode('utf-8')), 'valid.csv')
2016-01-15 15:15:35 +00:00
with app_.test_request_context():
with app_.test_client() as client:
2016-01-21 11:33:53 +00:00
client.login(mock_api_user)
2016-01-13 22:34:36 +00:00
upload_data = {'file': file_data}
2016-01-19 09:49:01 +00:00
response = client.post(url_for('main.send_sms', service_id=123),
data=upload_data,
follow_redirects=True)
content = response.get_data(as_text=True)
assert response.status_code == 200
assert 'Check and confirm' in content
assert 'All messages in file' in content
assert '+44 7700 900981' in content
assert '+44 7700 900982' in content
assert '+44 7700 900983' in content
assert '+44 7700 900984' in content
assert '+44 7700 900985' in content
assert '+44 7700 900986' in content
@moto.mock_s3
2016-01-21 11:33:53 +00:00
def test_should_redirect_to_job(app_, db_, db_session, mocker, mock_api_user,
mock_user_loader, mock_user_dao_get_by_email):
2016-01-15 15:15:35 +00:00
with app_.test_request_context():
with app_.test_client() as client:
2016-01-21 11:33:53 +00:00
client.login(mock_api_user)
2016-01-19 09:49:01 +00:00
response = client.post(url_for('main.check_sms',
service_id=123,
upload_id='someid'))
assert response.status_code == 302