Validate CSVs against rows with empty messages

This commit is contained in:
Pea Tyczynska
2019-11-21 12:12:04 +00:00
parent 512094c52c
commit f265dde8ab
6 changed files with 205 additions and 12 deletions

View File

@@ -8,41 +8,44 @@ MockRecipients = namedtuple(
'RecipientCSV',
[
'rows_with_bad_recipients',
'rows_with_missing_data'
'rows_with_missing_data',
'rows_with_message_too_long',
'rows_with_empty_message'
]
)
@pytest.mark.parametrize(
"rows_with_bad_recipients,rows_with_missing_data,template_type,expected_errors",
"rows_with_bad_recipients, rows_with_missing_data, "
"rows_with_message_too_long, rows_with_empty_message, template_type, expected_errors",
[
(
[], [],
[], [], [], [],
'sms',
[]
),
(
{2}, [],
{2}, [], [], [],
'sms',
['fix 1 phone number']
),
(
{2, 4, 6}, [],
{2, 4, 6}, [], [], [],
'sms',
['fix 3 phone numbers']
),
(
{1}, [],
{1}, [], [], [],
'email',
['fix 1 email address']
),
(
{2, 4, 6}, [],
{2, 4, 6}, [], [], [],
'email',
['fix 3 email addresses']
),
(
{2}, {3},
{2}, {3}, [], [],
'sms',
[
'fix 1 phone number',
@@ -50,21 +53,35 @@ MockRecipients = namedtuple(
]
),
(
{2, 4, 6, 8}, {3, 6, 9, 12},
{2, 4, 6, 8}, {3, 6, 9, 12}, [], [],
'sms',
[
'fix 4 phone numbers',
'enter missing data in 4 rows'
]
)
),
(
{}, {}, {3}, [],
'sms',
[
'shorten your message in 1 row'
]
),
(
{}, {}, {}, {2},
'sms',
[
'add content to empty message in 1 row'
]
),
]
)
def test_get_errors_for_csv(
rows_with_bad_recipients, rows_with_missing_data,
rows_with_bad_recipients, rows_with_missing_data, rows_with_message_too_long, rows_with_empty_message,
template_type,
expected_errors
):
assert get_errors_for_csv(
MockRecipients(rows_with_bad_recipients, rows_with_missing_data),
MockRecipients(rows_with_bad_recipients, rows_with_missing_data, rows_with_message_too_long, rows_with_empty_message),
template_type
) == expected_errors

View File

@@ -420,6 +420,44 @@ def test_upload_csv_file_with_errors_shows_check_page_with_errors(
assert 'Upload your file again' in content
def test_upload_csv_file_with_empty_message_shows_check_page_with_errors(
logged_in_client,
service_one,
mocker,
mock_get_empty_service_template_with_optional_placeholder,
mock_s3_upload,
mock_get_users_by_service,
mock_get_service_statistics,
mock_get_job_doesnt_exist,
mock_get_jobs,
fake_uuid,
):
mocker.patch(
'app.main.views.send.s3download',
return_value="""
phone number, show_placeholder
+447700900986, yes
+447700900986, no
"""
)
response = logged_in_client.post(
url_for('main.send_messages', service_id=service_one['id'], template_id=fake_uuid),
data={'file': (BytesIO(''.encode('utf-8')), 'invalid.csv')},
content_type='multipart/form-data',
follow_redirects=True
)
with logged_in_client.session_transaction() as session:
assert 'file_uploads' not in session
assert response.status_code == 200
content = response.get_data(as_text=True)
assert 'There is a problem with invalid.csv' in content
assert 'add content to empty message in 1 row' in content
@pytest.mark.parametrize('file_contents, expected_error,', [
(
"""