Ensure trial mode error overrides too many rows

Telling users that they can’t send to more than 50 recipients in trial
mode doesn’t apply for letters (they can’t send to _any_ recipients).

So we should make sure that the error message about not being able to
send to any recipients always comes up instead of the 50 recipients one,
whether you’re trying to upload a file with 1 or 111 rows.
This commit is contained in:
Chris Hill-Scott
2017-08-08 10:31:09 +01:00
parent 8f40cbd2bb
commit 4ff674158c
3 changed files with 20 additions and 13 deletions

View File

@@ -457,14 +457,15 @@ def check_messages(service_id, template_type, upload_id):
data['recipients'].too_many_rows or
not data['count_of_recipients'] or
not data['recipients'].has_recipient_columns or
data['recipients'].missing_column_headers
data['recipients'].missing_column_headers or
data['trying_to_send_letters_in_trial_mode']
):
return render_template('views/check/column-errors.html', **data)
if data['row_errors']:
return render_template('views/check/row-errors.html', **data)
if data['errors'] or data['trying_to_send_letters_in_trial_mode']:
if data['errors']:
return render_template('views/check/column-errors.html', **data)
return render_template('views/check/ok.html', **data)

View File

@@ -83,10 +83,6 @@
{% include "partials/check/not-allowed-to-send-to.html" %}
{% endwith %}
{% elif recipients.more_rows_than_can_send %}
{% include "partials/check/too-many-messages.html" %}
{% elif trying_to_send_letters_in_trial_mode %}
<h1 class='banner-title' data-module="track-error" data-error-type="Trying to send letters in trial mode" data-error-label="{{ upload_id }}">
@@ -98,6 +94,10 @@
can only preview how your letters will look
</p>
{% elif recipients.more_rows_than_can_send %}
{% include "partials/check/too-many-messages.html" %}
{% endif %}
{{ skip_to_file_contents() }}

View File

@@ -1583,6 +1583,10 @@ def test_check_messages_shows_trial_mode_error(
(mock_get_service, True),
(mock_get_live_service, False),
])
@pytest.mark.parametrize('number_of_rows, expected_error_message', [
(1, 'You cant send this letter'),
(111, 'You cant send these letters'),
])
def test_check_messages_shows_trial_mode_error_for_letters(
client_request,
api_user_active,
@@ -1593,14 +1597,16 @@ def test_check_messages_shows_trial_mode_error_for_letters(
mocker,
service_mock,
error_should_be_shown,
number_of_rows,
expected_error_message,
):
service_mock(mocker, api_user_active)
mocker.patch('app.main.views.send.s3download', return_value='''
address_line_1,address_line_2,postcode,
First Last, 123 Street, SW1 1AA
''')
mocker.patch('app.main.views.send.s3download', return_value='\n'.join(
['address_line_1,address_line_2,postcode,'] +
['First Last, 123 Street, SW1 1AA'] * number_of_rows
))
with client_request.session_transaction() as session:
session['upload_data'] = {'template_id': ''}
@@ -1617,10 +1623,10 @@ def test_check_messages_shows_trial_mode_error_for_letters(
if error_should_be_shown:
assert normalize_spaces(error[0].text) == (
'You cant send this letter '
'{} '
'In trial mode you can only preview how your letters will look '
'Skip to file contents'
)
).format(expected_error_message)
else:
assert not error
@@ -1668,7 +1674,7 @@ def test_non_ascii_characters_in_letter_recipients_file_shows_error(
api_user_active,
mock_login,
mock_get_users_by_service,
mock_get_service,
mock_get_live_service,
mock_has_permissions,
mock_get_service_letter_template,
mock_get_detailed_service_for_today,