2016-01-11 15:00:51 +00:00
|
|
|
|
from io import BytesIO
|
2016-05-05 15:41:11 +01:00
|
|
|
|
from os import path
|
|
|
|
|
|
from glob import glob
|
2016-11-02 16:53:40 +00:00
|
|
|
|
import re
|
|
|
|
|
|
from itertools import repeat
|
2016-06-24 10:15:20 +01:00
|
|
|
|
from functools import partial
|
2016-11-02 16:53:40 +00:00
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
from bs4 import BeautifulSoup
|
2016-01-14 16:00:13 +00:00
|
|
|
|
from flask import url_for
|
2016-11-02 16:53:40 +00:00
|
|
|
|
|
2016-06-17 11:54:01 +01:00
|
|
|
|
from tests import validate_route_permission
|
2015-12-17 16:21:34 +00:00
|
|
|
|
|
2016-02-22 17:17:18 +00:00
|
|
|
|
template_types = ['email', 'sms']
|
2015-12-17 16:21:34 +00:00
|
|
|
|
|
2016-05-05 15:41:11 +01:00
|
|
|
|
# The * ignores hidden files, eg .DS_Store
|
|
|
|
|
|
test_spreadsheet_files = glob(path.join('tests', 'spreadsheet_files', '*'))
|
2016-05-13 21:25:59 +01:00
|
|
|
|
test_non_spreadsheet_files = glob(path.join('tests', 'non_spreadsheet_files', '*'))
|
2016-05-05 15:41:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_that_test_files_exist():
|
|
|
|
|
|
assert len(test_spreadsheet_files) == 8
|
2016-05-13 21:25:59 +01:00
|
|
|
|
assert len(test_non_spreadsheet_files) == 6
|
2016-05-05 15:41:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
2016-05-13 21:25:59 +01:00
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
|
"filename, acceptable_file",
|
|
|
|
|
|
list(zip(
|
|
|
|
|
|
test_spreadsheet_files, repeat(True)
|
|
|
|
|
|
)) +
|
|
|
|
|
|
list(zip(
|
|
|
|
|
|
test_non_spreadsheet_files, repeat(False)
|
|
|
|
|
|
))
|
|
|
|
|
|
)
|
2016-05-05 15:41:11 +01:00
|
|
|
|
def test_upload_files_in_different_formats(
|
|
|
|
|
|
filename,
|
2016-05-13 21:25:59 +01:00
|
|
|
|
acceptable_file,
|
2016-05-05 15:41:11 +01:00
|
|
|
|
app_,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
mock_login,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_s3_upload,
|
|
|
|
|
|
mock_has_permissions,
|
|
|
|
|
|
fake_uuid
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
with app_.test_request_context(), app_.test_client() as client, open(filename, 'rb') as uploaded:
|
|
|
|
|
|
client.login(api_user_active)
|
2016-05-13 21:25:59 +01:00
|
|
|
|
response = client.post(
|
2016-05-05 15:41:11 +01:00
|
|
|
|
url_for('main.send_messages', service_id=fake_uuid, template_id=fake_uuid),
|
|
|
|
|
|
data={'file': (BytesIO(uploaded.read()), filename)},
|
|
|
|
|
|
content_type='multipart/form-data'
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2016-05-13 21:25:59 +01:00
|
|
|
|
if acceptable_file:
|
2016-05-15 07:47:50 +01:00
|
|
|
|
assert mock_s3_upload.call_args[0][1]['data'].strip() == (
|
2016-05-13 21:25:59 +01:00
|
|
|
|
"phone number,name,favourite colour,fruit\r\n"
|
|
|
|
|
|
"07739 468 050,Pete,Coral,tomato\r\n"
|
|
|
|
|
|
"07527 125 974,Not Pete,Magenta,Avacado\r\n"
|
|
|
|
|
|
"07512 058 823,Still Not Pete,Crimson,Pear"
|
|
|
|
|
|
)
|
|
|
|
|
|
else:
|
|
|
|
|
|
assert not mock_s3_upload.called
|
|
|
|
|
|
assert (
|
|
|
|
|
|
'Couldn’t read {}. Try using a different file format.'.format(filename)
|
|
|
|
|
|
) in response.get_data(as_text=True)
|
2016-05-05 15:41:11 +01:00
|
|
|
|
|
2016-02-22 17:17:18 +00:00
|
|
|
|
|
2016-03-07 18:47:05 +00:00
|
|
|
|
def test_upload_csvfile_with_errors_shows_check_page_with_errors(
|
2016-02-22 17:17:18 +00:00
|
|
|
|
app_,
|
|
|
|
|
|
api_user_active,
|
2016-02-26 10:54:06 +00:00
|
|
|
|
mocker,
|
2016-02-22 17:17:18 +00:00
|
|
|
|
mock_login,
|
2016-02-26 12:11:55 +00:00
|
|
|
|
mock_get_service,
|
2016-05-17 09:23:33 +01:00
|
|
|
|
mock_get_service_template_with_placeholders,
|
2016-02-29 17:03:56 +00:00
|
|
|
|
mock_s3_upload,
|
2016-04-04 14:28:52 +01:00
|
|
|
|
mock_has_permissions,
|
2016-04-12 14:19:51 +01:00
|
|
|
|
mock_get_users_by_service,
|
2016-07-25 14:16:34 +01:00
|
|
|
|
mock_get_detailed_service_for_today,
|
2016-04-12 14:19:51 +01:00
|
|
|
|
fake_uuid
|
2016-02-22 17:17:18 +00:00
|
|
|
|
):
|
2016-01-13 22:34:36 +00:00
|
|
|
|
|
2016-05-17 09:23:33 +01:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.s3download',
|
|
|
|
|
|
return_value="""
|
|
|
|
|
|
phone number,name
|
|
|
|
|
|
+447700900986
|
|
|
|
|
|
+447700900986
|
|
|
|
|
|
"""
|
|
|
|
|
|
)
|
2015-12-17 16:21:34 +00:00
|
|
|
|
|
2016-01-15 15:15:35 +00:00
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
with app_.test_client() as client:
|
2016-01-27 12:22:32 +00:00
|
|
|
|
client.login(api_user_active)
|
2016-04-05 08:55:43 +01:00
|
|
|
|
initial_upload = client.post(
|
2016-04-12 14:19:51 +01:00
|
|
|
|
url_for('main.send_messages', service_id=fake_uuid, template_id=fake_uuid),
|
2016-05-17 09:23:33 +01:00
|
|
|
|
data={'file': (BytesIO(''.encode('utf-8')), 'invalid.csv')},
|
2016-03-10 20:03:53 +00:00
|
|
|
|
content_type='multipart/form-data',
|
2016-02-22 17:17:18 +00:00
|
|
|
|
follow_redirects=True
|
|
|
|
|
|
)
|
2016-04-05 08:55:43 +01:00
|
|
|
|
reupload = client.post(
|
2016-04-12 14:19:51 +01:00
|
|
|
|
url_for('main.check_messages', service_id=fake_uuid, template_type='sms', upload_id='abc123'),
|
2016-05-17 09:23:33 +01:00
|
|
|
|
data={'file': (BytesIO(''.encode('utf-8')), 'invalid.csv')},
|
2016-04-05 08:55:43 +01:00
|
|
|
|
content_type='multipart/form-data',
|
|
|
|
|
|
follow_redirects=True
|
|
|
|
|
|
)
|
|
|
|
|
|
for response in [initial_upload, reupload]:
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
|
content = response.get_data(as_text=True)
|
2016-06-03 13:52:15 +01:00
|
|
|
|
assert 'There is a problem with your data' in content
|
2016-05-17 09:23:33 +01:00
|
|
|
|
assert '+447700900986' in content
|
|
|
|
|
|
assert 'Missing' in content
|
2016-04-05 08:55:43 +01:00
|
|
|
|
assert 'Re-upload your file' in content
|
2016-02-26 10:54:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-04-29 15:40:35 +01:00
|
|
|
|
def test_upload_csv_invalid_extension(app_,
|
|
|
|
|
|
api_user_active,
|
2016-06-17 11:54:01 +01:00
|
|
|
|
mocker,
|
2016-04-29 15:40:35 +01:00
|
|
|
|
mock_login,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_s3_upload,
|
|
|
|
|
|
mock_has_permissions,
|
|
|
|
|
|
mock_get_users_by_service,
|
2016-07-25 14:16:34 +01:00
|
|
|
|
mock_get_detailed_service_for_today,
|
2016-04-29 15:40:35 +01:00
|
|
|
|
fake_uuid):
|
2016-06-17 11:54:01 +01:00
|
|
|
|
|
2016-04-29 15:40:35 +01:00
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
with app_.test_client() as client:
|
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
|
resp = client.post(
|
|
|
|
|
|
url_for('main.send_messages', service_id=fake_uuid, template_id=fake_uuid),
|
2016-05-13 21:25:59 +01:00
|
|
|
|
data={'file': (BytesIO('contents'.encode('utf-8')), 'invalid.txt')},
|
2016-04-29 15:40:35 +01:00
|
|
|
|
content_type='multipart/form-data',
|
|
|
|
|
|
follow_redirects=True
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert resp.status_code == 200
|
2016-05-13 21:25:59 +01:00
|
|
|
|
assert "invalid.txt isn’t a spreadsheet that Notify can read" in resp.get_data(as_text=True)
|
2016-04-29 15:40:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
2016-05-05 08:39:36 +01:00
|
|
|
|
def test_send_test_sms_message(
|
2016-02-18 17:03:32 +00:00
|
|
|
|
app_,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_login,
|
2016-02-26 12:11:55 +00:00
|
|
|
|
mock_get_service,
|
2016-02-26 10:54:06 +00:00
|
|
|
|
mock_get_service_template,
|
2016-02-29 17:03:56 +00:00
|
|
|
|
mock_s3_upload,
|
2016-04-04 14:28:52 +01:00
|
|
|
|
mock_has_permissions,
|
2016-04-12 14:19:51 +01:00
|
|
|
|
mock_get_users_by_service,
|
2016-07-25 14:16:34 +01:00
|
|
|
|
mock_get_detailed_service_for_today,
|
2016-04-12 14:19:51 +01:00
|
|
|
|
fake_uuid
|
2016-02-18 17:03:32 +00:00
|
|
|
|
):
|
|
|
|
|
|
|
2016-05-12 11:22:14 +01:00
|
|
|
|
expected_data = {'data': 'phone number\r\n07700 900 762\r\n', 'file_name': 'Test message'}
|
2016-03-01 09:41:08 +00:00
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value='phone number\r\n+4412341234')
|
2016-02-26 10:54:06 +00:00
|
|
|
|
|
2016-02-18 17:03:32 +00:00
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
with app_.test_client() as client:
|
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
|
response = client.get(
|
2016-05-05 08:39:36 +01:00
|
|
|
|
url_for('main.send_test', service_id=fake_uuid, template_id=fake_uuid),
|
2016-02-18 17:03:32 +00:00
|
|
|
|
follow_redirects=True
|
|
|
|
|
|
)
|
|
|
|
|
|
assert response.status_code == 200
|
2016-05-15 07:47:50 +01:00
|
|
|
|
mock_s3_upload.assert_called_with(fake_uuid, expected_data, 'eu-west-1')
|
2016-02-18 17:03:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-05-05 08:39:36 +01:00
|
|
|
|
def test_send_test_email_message(
|
2016-03-02 17:02:41 +00:00
|
|
|
|
app_,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_login,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
mock_get_service_email_template,
|
2016-03-03 09:30:30 +00:00
|
|
|
|
mock_s3_upload,
|
2016-04-04 14:28:52 +01:00
|
|
|
|
mock_has_permissions,
|
2016-04-12 14:19:51 +01:00
|
|
|
|
mock_get_users_by_service,
|
2016-07-25 14:16:34 +01:00
|
|
|
|
mock_get_detailed_service_for_today,
|
2016-04-12 14:19:51 +01:00
|
|
|
|
fake_uuid
|
2016-03-02 17:02:41 +00:00
|
|
|
|
):
|
|
|
|
|
|
|
2016-05-12 11:22:14 +01:00
|
|
|
|
expected_data = {'data': 'email address\r\ntest@user.gov.uk\r\n', 'file_name': 'Test message'}
|
2016-03-02 17:02:41 +00:00
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value='email address\r\ntest@user.gov.uk')
|
|
|
|
|
|
|
|
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
with app_.test_client() as client:
|
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
|
response = client.get(
|
2016-05-05 08:39:36 +01:00
|
|
|
|
url_for('main.send_test', service_id=fake_uuid, template_id=fake_uuid),
|
2016-03-02 17:02:41 +00:00
|
|
|
|
follow_redirects=True
|
|
|
|
|
|
)
|
|
|
|
|
|
assert response.status_code == 200
|
2016-05-15 07:47:50 +01:00
|
|
|
|
mock_s3_upload.assert_called_with(fake_uuid, expected_data, 'eu-west-1')
|
2016-03-02 17:02:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-05-05 08:39:36 +01:00
|
|
|
|
def test_send_test_sms_message_with_placeholders(
|
|
|
|
|
|
app_,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_login,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
mock_get_service_template_with_placeholders,
|
|
|
|
|
|
mock_s3_upload,
|
|
|
|
|
|
mock_has_permissions,
|
|
|
|
|
|
mock_get_users_by_service,
|
2016-07-25 14:16:34 +01:00
|
|
|
|
mock_get_detailed_service_for_today,
|
2016-05-05 08:39:36 +01:00
|
|
|
|
fake_uuid
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
expected_data = {
|
|
|
|
|
|
'data': 'phone number,name\r\n07700 900 762,Jo\r\n',
|
2016-05-12 11:22:14 +01:00
|
|
|
|
'file_name': 'Test message'
|
2016-05-05 08:39:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value='phone number\r\n+4412341234')
|
|
|
|
|
|
|
|
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
with app_.test_client() as client:
|
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
|
response = client.post(
|
|
|
|
|
|
url_for(
|
|
|
|
|
|
'main.send_test',
|
|
|
|
|
|
service_id=fake_uuid,
|
|
|
|
|
|
template_id=fake_uuid
|
|
|
|
|
|
),
|
|
|
|
|
|
data={'name': 'Jo'},
|
|
|
|
|
|
follow_redirects=True
|
|
|
|
|
|
)
|
|
|
|
|
|
assert response.status_code == 200
|
2016-05-15 07:47:50 +01:00
|
|
|
|
mock_s3_upload.assert_called_with(fake_uuid, expected_data, 'eu-west-1')
|
2016-05-05 08:39:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_api_info_page(
|
2016-03-15 06:53:06 +00:00
|
|
|
|
app_,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_login,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
mock_get_service_email_template,
|
|
|
|
|
|
mock_s3_upload,
|
2016-04-12 14:19:51 +01:00
|
|
|
|
mock_has_permissions,
|
|
|
|
|
|
fake_uuid
|
2016-03-15 06:53:06 +00:00
|
|
|
|
):
|
|
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
with app_.test_client() as client:
|
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
|
response = client.get(
|
2016-04-12 14:19:51 +01:00
|
|
|
|
url_for('main.send_from_api', service_id=fake_uuid, template_id=fake_uuid),
|
2016-03-15 06:53:06 +00:00
|
|
|
|
follow_redirects=True
|
|
|
|
|
|
)
|
|
|
|
|
|
assert response.status_code == 200
|
2016-08-10 10:09:04 +01:00
|
|
|
|
assert 'API info' in response.get_data(as_text=True)
|
2016-03-15 06:53:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-02-18 17:03:32 +00:00
|
|
|
|
def test_download_example_csv(
|
|
|
|
|
|
app_,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_login,
|
2016-02-26 12:11:55 +00:00
|
|
|
|
mock_get_service,
|
2016-02-29 17:03:56 +00:00
|
|
|
|
mock_get_service_template,
|
2016-04-12 14:19:51 +01:00
|
|
|
|
mock_has_permissions,
|
|
|
|
|
|
fake_uuid
|
2016-02-18 17:03:32 +00:00
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
with app_.test_client() as client:
|
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
|
response = client.get(
|
2016-04-12 14:19:51 +01:00
|
|
|
|
url_for('main.get_example_csv', service_id=fake_uuid, template_id=fake_uuid),
|
2016-02-18 17:03:32 +00:00
|
|
|
|
follow_redirects=True
|
|
|
|
|
|
)
|
|
|
|
|
|
assert response.status_code == 200
|
2016-05-05 08:39:36 +01:00
|
|
|
|
assert response.get_data(as_text=True) == 'phone number\r\n07700 900321\r\n'
|
2016-02-18 17:03:32 +00:00
|
|
|
|
assert 'text/csv' in response.headers['Content-Type']
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-22 17:17:18 +00:00
|
|
|
|
def test_upload_csvfile_with_valid_phone_shows_all_numbers(
|
|
|
|
|
|
app_,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_login,
|
2016-02-26 12:11:55 +00:00
|
|
|
|
mock_get_service,
|
2016-02-26 10:54:06 +00:00
|
|
|
|
mock_get_service_template,
|
2016-02-29 17:03:56 +00:00
|
|
|
|
mock_s3_upload,
|
2016-04-04 14:28:52 +01:00
|
|
|
|
mock_has_permissions,
|
2016-04-12 14:19:51 +01:00
|
|
|
|
mock_get_users_by_service,
|
2016-07-25 14:16:34 +01:00
|
|
|
|
mock_get_detailed_service_for_today,
|
2016-04-12 14:19:51 +01:00
|
|
|
|
fake_uuid
|
2016-02-22 17:17:18 +00:00
|
|
|
|
):
|
2016-01-13 22:34:36 +00:00
|
|
|
|
|
2016-03-07 18:47:05 +00:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.s3download',
|
2016-04-07 14:30:51 +01:00
|
|
|
|
return_value='\n'.join(['phone number'] + [
|
|
|
|
|
|
'07700 9007{0:02d}'.format(final_two) for final_two in range(0, 53)
|
|
|
|
|
|
])
|
2016-03-07 18:47:05 +00:00
|
|
|
|
)
|
2016-01-11 15:00:51 +00:00
|
|
|
|
|
2016-01-15 15:15:35 +00:00
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
with app_.test_client() as client:
|
2016-01-27 12:22:32 +00:00
|
|
|
|
client.login(api_user_active)
|
2016-03-07 18:47:05 +00:00
|
|
|
|
response = client.post(
|
2016-04-12 14:19:51 +01:00
|
|
|
|
url_for('main.send_messages', service_id=fake_uuid, template_id=fake_uuid),
|
2016-03-10 20:03:53 +00:00
|
|
|
|
data={'file': (BytesIO(''.encode('utf-8')), 'valid.csv')},
|
|
|
|
|
|
content_type='multipart/form-data',
|
2016-03-07 18:47:05 +00:00
|
|
|
|
follow_redirects=True
|
|
|
|
|
|
)
|
2016-02-22 14:52:16 +00:00
|
|
|
|
with client.session_transaction() as sess:
|
2016-04-12 14:19:51 +01:00
|
|
|
|
assert sess['upload_data']['template_id'] == fake_uuid
|
2016-02-22 14:52:16 +00:00
|
|
|
|
assert sess['upload_data']['original_file_name'] == 'valid.csv'
|
2016-04-07 14:30:51 +01:00
|
|
|
|
assert sess['upload_data']['notification_count'] == 53
|
2016-01-11 15:00:51 +00:00
|
|
|
|
|
2016-02-22 14:52:16 +00:00
|
|
|
|
content = response.get_data(as_text=True)
|
|
|
|
|
|
assert response.status_code == 200
|
2016-04-04 14:28:52 +01:00
|
|
|
|
assert '07700 900701' in content
|
2016-04-07 14:30:51 +01:00
|
|
|
|
assert '07700 900749' in content
|
|
|
|
|
|
assert '07700 900750' not in content
|
2016-06-03 13:52:15 +01:00
|
|
|
|
assert 'Only showing the first 50 rows' in content
|
2016-01-11 15:00:51 +00:00
|
|
|
|
|
2016-07-25 14:16:34 +01:00
|
|
|
|
mock_get_detailed_service_for_today.assert_called_once_with(fake_uuid)
|
2016-06-17 11:54:01 +01:00
|
|
|
|
|
2016-01-11 15:00:51 +00:00
|
|
|
|
|
2016-08-30 09:27:24 +01:00
|
|
|
|
def test_test_message_can_only_be_sent_now(
|
|
|
|
|
|
app_,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_login,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_s3_download,
|
|
|
|
|
|
mock_has_permissions,
|
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_detailed_service_for_today,
|
|
|
|
|
|
fake_uuid
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
with app_.test_request_context(), app_.test_client() as client:
|
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
|
with client.session_transaction() as session:
|
|
|
|
|
|
session['upload_data'] = {
|
|
|
|
|
|
'original_file_name': 'Test message',
|
|
|
|
|
|
'template_id': fake_uuid,
|
|
|
|
|
|
'notification_count': 1,
|
|
|
|
|
|
'valid': True
|
|
|
|
|
|
}
|
|
|
|
|
|
response = client.get(url_for(
|
|
|
|
|
|
'main.check_messages',
|
|
|
|
|
|
service_id=fake_uuid,
|
|
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
template_type='sms',
|
|
|
|
|
|
from_test=True
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
content = response.get_data(as_text=True)
|
|
|
|
|
|
assert 'name="scheduled_for"' not in content
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-08-07 09:17:49 +01:00
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
|
'when', [
|
|
|
|
|
|
'', '2016-08-25T13:04:21.767198'
|
|
|
|
|
|
]
|
|
|
|
|
|
)
|
2016-02-22 17:17:18 +00:00
|
|
|
|
def test_create_job_should_call_api(
|
|
|
|
|
|
app_,
|
|
|
|
|
|
service_one,
|
2016-05-11 11:57:31 +01:00
|
|
|
|
active_user_with_permissions,
|
2016-02-22 17:17:18 +00:00
|
|
|
|
mock_create_job,
|
|
|
|
|
|
mock_get_job,
|
2016-03-02 15:37:35 +00:00
|
|
|
|
mock_get_notifications,
|
2016-02-29 17:03:56 +00:00
|
|
|
|
mock_get_service_template,
|
2016-05-24 12:34:29 +01:00
|
|
|
|
mocker,
|
2016-08-07 09:17:49 +01:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
when
|
2016-02-22 17:17:18 +00:00
|
|
|
|
):
|
2016-01-29 12:19:50 +00:00
|
|
|
|
service_id = service_one['id']
|
2016-05-24 12:34:29 +01:00
|
|
|
|
data = mock_get_job(service_one['id'], fake_uuid)['data']
|
|
|
|
|
|
job_id = data['id']
|
|
|
|
|
|
original_file_name = data['original_file_name']
|
|
|
|
|
|
template_id = data['template']
|
|
|
|
|
|
notification_count = data['notification_count']
|
2016-08-25 13:27:24 +01:00
|
|
|
|
with app_.test_request_context(), app_.test_client() as client:
|
|
|
|
|
|
client.login(active_user_with_permissions, mocker, service_one)
|
|
|
|
|
|
with client.session_transaction() as session:
|
|
|
|
|
|
session['upload_data'] = {
|
|
|
|
|
|
'original_file_name': original_file_name,
|
|
|
|
|
|
'template_id': template_id,
|
|
|
|
|
|
'notification_count': notification_count,
|
|
|
|
|
|
'valid': True
|
|
|
|
|
|
}
|
|
|
|
|
|
url = url_for('main.start_job', service_id=service_one['id'], upload_id=job_id)
|
|
|
|
|
|
response = client.post(url, data={'scheduled_for': when}, follow_redirects=True)
|
2016-01-29 10:27:23 +00:00
|
|
|
|
|
2016-08-25 13:27:24 +01:00
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
|
assert original_file_name in response.get_data(as_text=True)
|
|
|
|
|
|
mock_create_job.assert_called_with(
|
|
|
|
|
|
job_id,
|
|
|
|
|
|
service_id,
|
|
|
|
|
|
template_id,
|
|
|
|
|
|
original_file_name,
|
|
|
|
|
|
notification_count,
|
|
|
|
|
|
scheduled_for=when
|
|
|
|
|
|
)
|
2016-03-03 15:26:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_messages_should_revalidate_file_when_uploading_file(
|
|
|
|
|
|
app_,
|
|
|
|
|
|
service_one,
|
2016-05-11 11:57:31 +01:00
|
|
|
|
active_user_with_permissions,
|
2016-03-03 15:26:52 +00:00
|
|
|
|
mock_create_job,
|
2016-05-24 12:34:29 +01:00
|
|
|
|
mock_get_job,
|
2016-05-17 09:23:33 +01:00
|
|
|
|
mock_get_service_template_with_placeholders,
|
2016-03-03 15:26:52 +00:00
|
|
|
|
mock_s3_upload,
|
2016-03-03 15:39:15 +00:00
|
|
|
|
mocker,
|
2016-04-04 14:28:52 +01:00
|
|
|
|
mock_has_permissions,
|
2016-07-25 14:16:34 +01:00
|
|
|
|
mock_get_detailed_service_for_today,
|
2016-05-24 12:34:29 +01:00
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
fake_uuid
|
2016-03-03 15:26:52 +00:00
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
service_id = service_one['id']
|
|
|
|
|
|
|
2016-03-07 18:47:05 +00:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.main.views.send.s3download',
|
2016-03-10 20:03:53 +00:00
|
|
|
|
return_value="""
|
|
|
|
|
|
phone number,name,,,
|
2016-05-17 09:23:33 +01:00
|
|
|
|
+447700900986,,,,
|
|
|
|
|
|
+447700900986,,,,
|
2016-03-10 20:03:53 +00:00
|
|
|
|
"""
|
2016-03-07 18:47:05 +00:00
|
|
|
|
)
|
2016-05-24 12:34:29 +01:00
|
|
|
|
data = mock_get_job(service_one['id'], fake_uuid)['data']
|
2016-03-03 15:26:52 +00:00
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
with app_.test_client() as client:
|
2016-05-11 11:57:31 +01:00
|
|
|
|
client.login(active_user_with_permissions, mocker, service_one)
|
2016-03-03 15:26:52 +00:00
|
|
|
|
with client.session_transaction() as session:
|
|
|
|
|
|
session['upload_data'] = {'original_file_name': 'invalid.csv',
|
2016-05-24 12:34:29 +01:00
|
|
|
|
'template_id': data['template'],
|
|
|
|
|
|
'notification_count': data['notification_count'],
|
2016-03-10 20:03:53 +00:00
|
|
|
|
'valid': True}
|
2016-03-07 18:47:05 +00:00
|
|
|
|
response = client.post(
|
2016-05-24 12:34:29 +01:00
|
|
|
|
url_for('main.start_job', service_id=service_id, upload_id=data['id']),
|
2016-03-10 20:03:53 +00:00
|
|
|
|
data={'file': (BytesIO(''.encode('utf-8')), 'invalid.csv')},
|
|
|
|
|
|
content_type='multipart/form-data',
|
2016-03-07 18:47:05 +00:00
|
|
|
|
follow_redirects=True
|
|
|
|
|
|
)
|
2016-03-03 15:26:52 +00:00
|
|
|
|
assert response.status_code == 200
|
2016-06-03 13:52:15 +01:00
|
|
|
|
assert 'There is a problem with your data' in response.get_data(as_text=True)
|
2016-03-09 12:10:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
2016-11-02 16:53:40 +00:00
|
|
|
|
@pytest.mark.parametrize('route, response_code', [
|
|
|
|
|
|
('main.choose_template', 200),
|
|
|
|
|
|
('main.send_messages', 200),
|
|
|
|
|
|
('main.get_example_csv', 200),
|
|
|
|
|
|
('main.send_test', 302)
|
|
|
|
|
|
])
|
2016-03-09 12:10:50 +00:00
|
|
|
|
def test_route_permissions(mocker,
|
|
|
|
|
|
app_,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_service_template,
|
2016-03-09 14:11:24 +00:00
|
|
|
|
mock_get_service_templates,
|
2016-03-09 12:10:50 +00:00
|
|
|
|
mock_get_jobs,
|
|
|
|
|
|
mock_get_notifications,
|
|
|
|
|
|
mock_create_job,
|
2016-04-12 14:19:51 +01:00
|
|
|
|
mock_s3_upload,
|
2016-11-02 16:53:40 +00:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
route,
|
|
|
|
|
|
response_code):
|
2016-03-09 12:10:50 +00:00
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
validate_route_permission(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
app_,
|
|
|
|
|
|
"GET",
|
2016-11-02 16:53:40 +00:00
|
|
|
|
response_code,
|
2016-03-09 12:10:50 +00:00
|
|
|
|
url_for(
|
2016-11-02 16:53:40 +00:00
|
|
|
|
route,
|
2016-03-09 12:10:50 +00:00
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_type='sms',
|
2016-04-12 14:19:51 +01:00
|
|
|
|
template_id=fake_uuid),
|
2016-03-09 12:10:50 +00:00
|
|
|
|
['send_texts', 'send_emails', 'send_letters'],
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one)
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-11-02 16:53:40 +00:00
|
|
|
|
@pytest.mark.parametrize('route', [
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
'main.send_messages',
|
|
|
|
|
|
'main.get_example_csv',
|
|
|
|
|
|
'main.send_test'
|
|
|
|
|
|
])
|
2016-03-09 12:10:50 +00:00
|
|
|
|
def test_route_invalid_permissions(mocker,
|
|
|
|
|
|
app_,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_service_template,
|
2016-03-09 14:11:24 +00:00
|
|
|
|
mock_get_service_templates,
|
2016-03-09 12:10:50 +00:00
|
|
|
|
mock_get_jobs,
|
|
|
|
|
|
mock_get_notifications,
|
2016-04-12 14:19:51 +01:00
|
|
|
|
mock_create_job,
|
2016-11-02 16:53:40 +00:00
|
|
|
|
fake_uuid,
|
|
|
|
|
|
route):
|
2016-03-09 12:10:50 +00:00
|
|
|
|
with app_.test_request_context():
|
2016-11-02 16:53:40 +00:00
|
|
|
|
validate_route_permission(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
app_,
|
|
|
|
|
|
"GET",
|
|
|
|
|
|
403,
|
|
|
|
|
|
url_for(
|
|
|
|
|
|
route,
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_type='sms',
|
|
|
|
|
|
template_id=fake_uuid),
|
|
|
|
|
|
['blah'],
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one)
|
2016-03-09 13:51:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_route_choose_template_manage_service_permissions(mocker,
|
|
|
|
|
|
app_,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_login,
|
|
|
|
|
|
mock_get_user,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
mock_check_verify_code,
|
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
|
mock_get_jobs):
|
|
|
|
|
|
with app_.test_request_context():
|
|
|
|
|
|
template_id = mock_get_service_templates(service_one['id'])['data'][0]['id']
|
|
|
|
|
|
resp = validate_route_permission(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
app_,
|
|
|
|
|
|
"GET",
|
|
|
|
|
|
200,
|
|
|
|
|
|
url_for(
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_type='sms'),
|
|
|
|
|
|
['manage_users', 'manage_templates', 'manage_settings'],
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one)
|
|
|
|
|
|
page = resp.get_data(as_text=True)
|
|
|
|
|
|
assert url_for(
|
|
|
|
|
|
"main.send_messages",
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=template_id) not in page
|
|
|
|
|
|
assert url_for(
|
2016-05-05 08:39:36 +01:00
|
|
|
|
"main.send_test",
|
2016-03-09 13:51:56 +00:00
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=template_id) not in page
|
|
|
|
|
|
assert url_for(
|
|
|
|
|
|
"main.edit_service_template",
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=template_id) in page
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_route_choose_template_send_messages_permissions(mocker,
|
|
|
|
|
|
app_,
|
2016-03-18 16:20:37 +00:00
|
|
|
|
active_user_with_permissions,
|
2016-03-09 13:51:56 +00:00
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
mock_check_verify_code,
|
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
|
mock_get_jobs):
|
|
|
|
|
|
with app_.test_request_context():
|
2016-04-12 14:19:51 +01:00
|
|
|
|
template_id = None
|
|
|
|
|
|
for temp in mock_get_service_templates(service_one['id'])['data']:
|
|
|
|
|
|
if temp['template_type'] == 'sms':
|
|
|
|
|
|
template_id = temp['id']
|
|
|
|
|
|
assert template_id
|
2016-03-09 13:51:56 +00:00
|
|
|
|
resp = validate_route_permission(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
app_,
|
|
|
|
|
|
"GET",
|
|
|
|
|
|
200,
|
|
|
|
|
|
url_for(
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_type='sms'),
|
|
|
|
|
|
['send_texts', 'send_emails', 'send_letters'],
|
2016-03-18 16:20:37 +00:00
|
|
|
|
active_user_with_permissions,
|
2016-03-09 13:51:56 +00:00
|
|
|
|
service_one)
|
|
|
|
|
|
page = resp.get_data(as_text=True)
|
|
|
|
|
|
assert url_for(
|
|
|
|
|
|
"main.send_messages",
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=template_id) in page
|
|
|
|
|
|
assert url_for(
|
|
|
|
|
|
"main.edit_service_template",
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=template_id) not in page
|
2016-03-18 14:43:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_route_choose_template_manage_api_keys_permissions(mocker,
|
|
|
|
|
|
app_,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one,
|
|
|
|
|
|
mock_get_user,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
mock_check_verify_code,
|
|
|
|
|
|
mock_get_service_templates,
|
|
|
|
|
|
mock_get_jobs):
|
|
|
|
|
|
with app_.test_request_context():
|
2016-04-12 14:19:51 +01:00
|
|
|
|
template_id = None
|
|
|
|
|
|
for temp in mock_get_service_templates(service_one['id'])['data']:
|
|
|
|
|
|
if temp['template_type'] == 'sms':
|
|
|
|
|
|
template_id = temp['id']
|
|
|
|
|
|
assert template_id
|
2016-03-18 14:43:03 +00:00
|
|
|
|
resp = validate_route_permission(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
app_,
|
|
|
|
|
|
"GET",
|
|
|
|
|
|
200,
|
|
|
|
|
|
url_for(
|
|
|
|
|
|
'main.choose_template',
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_type='sms'),
|
2016-03-29 17:33:12 +01:00
|
|
|
|
['manage_api_keys'],
|
2016-03-18 14:43:03 +00:00
|
|
|
|
api_user_active,
|
|
|
|
|
|
service_one)
|
|
|
|
|
|
page = resp.get_data(as_text=True)
|
|
|
|
|
|
assert url_for(
|
2016-05-05 08:39:36 +01:00
|
|
|
|
"main.send_test",
|
2016-03-18 14:43:03 +00:00
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=template_id) not in page
|
|
|
|
|
|
assert url_for(
|
|
|
|
|
|
"main.edit_service_template",
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=template_id) not in page
|
2016-04-12 14:19:51 +01:00
|
|
|
|
page = BeautifulSoup(resp.data.decode('utf-8'), 'html.parser')
|
|
|
|
|
|
links = page.findAll('a', href=re.compile('^' + url_for(
|
|
|
|
|
|
"main.send_from_api",
|
|
|
|
|
|
service_id=service_one['id'],
|
|
|
|
|
|
template_id=template_id)))
|
|
|
|
|
|
assert len(links) == 1
|
2016-06-06 16:38:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
2016-06-24 10:15:20 +01:00
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
|
'extra_args,expected_url',
|
|
|
|
|
|
[
|
|
|
|
|
|
(
|
|
|
|
|
|
dict(),
|
|
|
|
|
|
partial(url_for, '.send_test')
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
dict(help='0'),
|
|
|
|
|
|
partial(url_for, '.send_test')
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
dict(help='2'),
|
|
|
|
|
|
partial(url_for, '.send_test', help='1')
|
|
|
|
|
|
)
|
|
|
|
|
|
]
|
|
|
|
|
|
)
|
2016-06-24 10:25:35 +01:00
|
|
|
|
def test_check_messages_back_link(
|
|
|
|
|
|
app_,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_login,
|
|
|
|
|
|
mock_get_user_by_email,
|
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
mock_get_service_template_with_placeholders,
|
|
|
|
|
|
mock_has_permissions,
|
2016-07-25 14:16:34 +01:00
|
|
|
|
mock_get_detailed_service_for_today,
|
2016-06-24 10:25:35 +01:00
|
|
|
|
mock_s3_download,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
extra_args,
|
|
|
|
|
|
expected_url
|
|
|
|
|
|
):
|
|
|
|
|
|
with app_.test_request_context(), app_.test_client() as client:
|
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
|
with client.session_transaction() as session:
|
|
|
|
|
|
session['upload_data'] = {'original_file_name': 'valid.csv',
|
|
|
|
|
|
'template_id': fake_uuid,
|
|
|
|
|
|
'notification_count': 1,
|
|
|
|
|
|
'valid': True}
|
|
|
|
|
|
response = client.get(url_for(
|
|
|
|
|
|
'main.check_messages',
|
|
|
|
|
|
service_id=fake_uuid,
|
|
|
|
|
|
upload_id=fake_uuid,
|
|
|
|
|
|
template_type='sms',
|
|
|
|
|
|
from_test=True,
|
|
|
|
|
|
**extra_args
|
|
|
|
|
|
))
|
2016-06-06 16:38:55 +01:00
|
|
|
|
assert response.status_code == 200
|
2016-06-24 10:15:20 +01:00
|
|
|
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
|
|
|
|
|
assert (
|
|
|
|
|
|
page.findAll('a', {'class': 'page-footer-back-link'})[0]['href']
|
|
|
|
|
|
) == expected_url(service_id=fake_uuid, template_id=fake_uuid)
|
2016-06-17 11:54:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
2016-07-01 10:49:54 +01:00
|
|
|
|
def test_go_to_dashboard_after_tour(
|
|
|
|
|
|
app_,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_login,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
mock_has_permissions,
|
|
|
|
|
|
mock_delete_service_template,
|
|
|
|
|
|
fake_uuid
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
|
|
|
|
with app_.test_request_context(), app_.test_client() as client:
|
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
|
|
|
|
|
|
|
resp = client.get(
|
|
|
|
|
|
url_for('main.go_to_dashboard_after_tour', service_id=fake_uuid, example_template_id=fake_uuid)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
assert resp.status_code == 302
|
|
|
|
|
|
assert resp.location == url_for("main.service_dashboard", service_id=fake_uuid, _external=True)
|
|
|
|
|
|
mock_delete_service_template.assert_called_once_with(fake_uuid, fake_uuid)
|
2016-07-21 15:39:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
2016-08-10 15:55:13 +01:00
|
|
|
|
@pytest.mark.parametrize('num_requested,expected_msg', [
|
2016-07-21 15:39:00 +01:00
|
|
|
|
(0, '‘valid.csv’ contains 100 phone numbers.'),
|
|
|
|
|
|
(1, 'You can still send 49 messages today, but ‘valid.csv’ contains 100 phone numbers.')
|
|
|
|
|
|
], ids=['none_sent', 'some_sent'])
|
|
|
|
|
|
def test_check_messages_shows_too_many_messages_errors(
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
app_,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_login,
|
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
mock_get_service_template,
|
|
|
|
|
|
mock_has_permissions,
|
|
|
|
|
|
fake_uuid,
|
2016-07-25 14:16:34 +01:00
|
|
|
|
num_requested,
|
2016-08-10 15:55:13 +01:00
|
|
|
|
expected_msg
|
2016-07-21 15:39:00 +01:00
|
|
|
|
):
|
|
|
|
|
|
# csv with 100 phone numbers
|
|
|
|
|
|
mocker.patch('app.main.views.send.s3download', return_value=',\n'.join(
|
|
|
|
|
|
['phone number'] + ([mock_get_users_by_service(None)[0]._mobile_number]*100)
|
|
|
|
|
|
))
|
2016-07-25 14:16:34 +01:00
|
|
|
|
mocker.patch('app.service_api_client.get_detailed_service_for_today', return_value={
|
|
|
|
|
|
'data': {
|
|
|
|
|
|
'statistics': {
|
|
|
|
|
|
'sms': {'requested': num_requested, 'delivered': 0, 'failed': 0},
|
|
|
|
|
|
'email': {'requested': 0, 'delivered': 0, 'failed': 0}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-07-21 15:39:00 +01:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
with app_.test_request_context(), app_.test_client() as client:
|
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
|
with client.session_transaction() as session:
|
|
|
|
|
|
session['upload_data'] = {'original_file_name': 'valid.csv',
|
|
|
|
|
|
'template_id': fake_uuid,
|
|
|
|
|
|
'notification_count': 1,
|
|
|
|
|
|
'valid': True}
|
|
|
|
|
|
response = client.get(url_for(
|
|
|
|
|
|
'main.check_messages',
|
|
|
|
|
|
service_id=fake_uuid,
|
|
|
|
|
|
template_type='sms',
|
|
|
|
|
|
upload_id=fake_uuid
|
|
|
|
|
|
))
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
|
|
|
|
|
assert page.find('h1').text.strip() == 'Too many recipients'
|
|
|
|
|
|
assert page.find('div', class_='banner-dangerous').find('a').text.strip() == 'trial mode'
|
|
|
|
|
|
|
|
|
|
|
|
# remove excess whitespace from element
|
|
|
|
|
|
details = page.find('div', class_='banner-dangerous').findAll('p')[1]
|
|
|
|
|
|
details = ' '.join([line.strip() for line in details.text.split('\n') if line.strip() != ''])
|
2016-08-10 15:55:13 +01:00
|
|
|
|
assert details == expected_msg
|
2016-10-14 10:44:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_messages_shows_over_max_row_error(
|
|
|
|
|
|
client,
|
|
|
|
|
|
app_,
|
|
|
|
|
|
api_user_active,
|
|
|
|
|
|
mock_login,
|
|
|
|
|
|
mock_get_users_by_service,
|
|
|
|
|
|
mock_get_service,
|
|
|
|
|
|
mock_get_service_template_with_placeholders,
|
|
|
|
|
|
mock_has_permissions,
|
|
|
|
|
|
mock_get_detailed_service_for_today,
|
|
|
|
|
|
mock_s3_download,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mocker
|
|
|
|
|
|
):
|
|
|
|
|
|
mock_recipients = mocker.patch('app.main.views.send.RecipientCSV').return_value
|
|
|
|
|
|
mock_recipients.max_rows = 11111
|
|
|
|
|
|
mock_recipients.__len__.return_value = 99999
|
2016-10-17 10:20:14 +01:00
|
|
|
|
mock_recipients.too_many_rows.return_value = True
|
2016-10-14 10:44:28 +01:00
|
|
|
|
|
|
|
|
|
|
client.login(api_user_active)
|
|
|
|
|
|
with client.session_transaction() as session:
|
|
|
|
|
|
session['upload_data'] = {'template_id': fake_uuid}
|
|
|
|
|
|
response = client.get(url_for(
|
|
|
|
|
|
'main.check_messages',
|
|
|
|
|
|
service_id=fake_uuid,
|
|
|
|
|
|
template_type='sms',
|
|
|
|
|
|
upload_id=fake_uuid
|
|
|
|
|
|
))
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
|
|
|
|
|
assert ' '.join(
|
|
|
|
|
|
page.find('div', class_='banner-dangerous').text.split()
|
|
|
|
|
|
) == (
|
|
|
|
|
|
'Your file has too many rows '
|
|
|
|
|
|
'Notify can process up to 11,111 rows at once. '
|
|
|
|
|
|
'Your file has 99,999 rows.'
|
|
|
|
|
|
)
|