mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-15 07:18:58 -04:00
Merge pull request #1250 from alphagov/validate-international-csv
Allow international phone numbers in spreadsheet
This commit is contained in:
@@ -60,9 +60,7 @@ def get_example_csv_fields(column_headers, use_example_as_example, submitted_fie
|
|||||||
def get_example_csv_rows(template, use_example_as_example=True, submitted_fields=False):
|
def get_example_csv_rows(template, use_example_as_example=True, submitted_fields=False):
|
||||||
return {
|
return {
|
||||||
'email': ['test@example.com'] if use_example_as_example else [current_user.email_address],
|
'email': ['test@example.com'] if use_example_as_example else [current_user.email_address],
|
||||||
'sms': ['07700 900321'] if use_example_as_example else [validate_and_format_phone_number(
|
'sms': ['07700 900321'] if use_example_as_example else [current_user.mobile_number],
|
||||||
current_user.mobile_number, human_readable=True
|
|
||||||
)],
|
|
||||||
'letter': [
|
'letter': [
|
||||||
(submitted_fields or {}).get(
|
(submitted_fields or {}).get(
|
||||||
key, get_example_letter_address(key) if use_example_as_example else key
|
key, get_example_letter_address(key) if use_example_as_example else key
|
||||||
@@ -220,7 +218,6 @@ def _check_messages(service_id, template_type, upload_id, letters_as_pdf=False):
|
|||||||
upload_id=upload_id
|
upload_id=upload_id
|
||||||
) if not letters_as_pdf else None
|
) if not letters_as_pdf else None
|
||||||
)
|
)
|
||||||
|
|
||||||
recipients = RecipientCSV(
|
recipients = RecipientCSV(
|
||||||
contents,
|
contents,
|
||||||
template_type=template.template_type,
|
template_type=template.template_type,
|
||||||
@@ -230,7 +227,8 @@ def _check_messages(service_id, template_type, upload_id, letters_as_pdf=False):
|
|||||||
whitelist=itertools.chain.from_iterable(
|
whitelist=itertools.chain.from_iterable(
|
||||||
[user.name, user.mobile_number, user.email_address] for user in users
|
[user.name, user.mobile_number, user.email_address] for user in users
|
||||||
) if current_service['restricted'] else None,
|
) if current_service['restricted'] else None,
|
||||||
remaining_messages=remaining_messages
|
remaining_messages=remaining_messages,
|
||||||
|
international_sms=current_service['can_send_international_sms'],
|
||||||
)
|
)
|
||||||
|
|
||||||
if request.args.get('from_test'):
|
if request.args.get('from_test'):
|
||||||
|
|||||||
@@ -28,4 +28,4 @@ notifications-python-client>=3.1,<3.2
|
|||||||
awscli>=1.11,<1.12
|
awscli>=1.11,<1.12
|
||||||
awscli-cwlogs>=1.4,<1.5
|
awscli-cwlogs>=1.4,<1.5
|
||||||
|
|
||||||
git+https://github.com/alphagov/notifications-utils.git@16.0.0#egg=notifications-utils==16.0.0
|
git+https://github.com/alphagov/notifications-utils.git@16.2.0#egg=notifications-utils==16.2.0
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import pytest
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
from notifications_utils.template import LetterPreviewTemplate
|
from notifications_utils.template import LetterPreviewTemplate
|
||||||
|
from notifications_utils.recipients import RecipientCSV
|
||||||
|
|
||||||
from app.main.views.send import get_check_messages_back_url
|
from app.main.views.send import get_check_messages_back_url
|
||||||
|
|
||||||
@@ -18,6 +19,8 @@ from tests.conftest import (
|
|||||||
mock_get_service_template,
|
mock_get_service_template,
|
||||||
mock_get_service_template_with_placeholders,
|
mock_get_service_template_with_placeholders,
|
||||||
mock_get_service_letter_template,
|
mock_get_service_letter_template,
|
||||||
|
mock_get_service,
|
||||||
|
mock_get_international_service,
|
||||||
)
|
)
|
||||||
|
|
||||||
template_types = ['email', 'sms']
|
template_types = ['email', 'sms']
|
||||||
@@ -293,7 +296,7 @@ def test_send_test_sms_message(
|
|||||||
fake_uuid
|
fake_uuid
|
||||||
):
|
):
|
||||||
|
|
||||||
expected_data = {'data': 'phone number\r\n07700 900 762\r\n', 'file_name': 'Test message'}
|
expected_data = {'data': 'phone number\r\n07700 900762\r\n', 'file_name': 'Test message'}
|
||||||
mocker.patch('app.main.views.send.s3download', return_value='phone number\r\n+4412341234')
|
mocker.patch('app.main.views.send.s3download', return_value='phone number\r\n+4412341234')
|
||||||
|
|
||||||
response = logged_in_client.get(
|
response = logged_in_client.get(
|
||||||
@@ -344,7 +347,7 @@ def test_send_test_sms_message_with_placeholders(
|
|||||||
):
|
):
|
||||||
|
|
||||||
expected_data = {
|
expected_data = {
|
||||||
'data': 'phone number,name\r\n07700 900 762,Jo\r\n',
|
'data': 'phone number,name\r\n07700 900762,Jo\r\n',
|
||||||
'file_name': 'Test message'
|
'file_name': 'Test message'
|
||||||
}
|
}
|
||||||
mocker.patch('app.main.views.send.s3download', return_value='phone number\r\n+4412341234')
|
mocker.patch('app.main.views.send.s3download', return_value='phone number\r\n+4412341234')
|
||||||
@@ -424,6 +427,42 @@ def test_upload_csvfile_with_valid_phone_shows_all_numbers(
|
|||||||
mock_get_detailed_service_for_today.assert_called_once_with(fake_uuid)
|
mock_get_detailed_service_for_today.assert_called_once_with(fake_uuid)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('service_mock, should_allow_international', [
|
||||||
|
(mock_get_service, False),
|
||||||
|
(mock_get_international_service, True),
|
||||||
|
])
|
||||||
|
def test_upload_csvfile_with_international_validates(
|
||||||
|
mocker,
|
||||||
|
api_user_active,
|
||||||
|
logged_in_client,
|
||||||
|
mock_get_service_template,
|
||||||
|
mock_s3_upload,
|
||||||
|
mock_has_permissions,
|
||||||
|
mock_get_users_by_service,
|
||||||
|
mock_get_detailed_service_for_today,
|
||||||
|
fake_uuid,
|
||||||
|
service_mock,
|
||||||
|
should_allow_international,
|
||||||
|
):
|
||||||
|
|
||||||
|
service_mock(mocker, api_user_active)
|
||||||
|
mocker.patch('app.main.views.send.s3download', return_value='')
|
||||||
|
mock_recipients = mocker.patch(
|
||||||
|
'app.main.views.send.RecipientCSV',
|
||||||
|
return_value=RecipientCSV("", template_type="sms"),
|
||||||
|
)
|
||||||
|
|
||||||
|
response = logged_in_client.post(
|
||||||
|
url_for('main.send_messages', service_id=fake_uuid, template_id=fake_uuid),
|
||||||
|
data={'file': (BytesIO(''.encode('utf-8')), 'valid.csv')},
|
||||||
|
content_type='multipart/form-data',
|
||||||
|
follow_redirects=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert mock_recipients.call_args[1]['international_sms'] == should_allow_international
|
||||||
|
|
||||||
|
|
||||||
def test_test_message_can_only_be_sent_now(
|
def test_test_message_can_only_be_sent_now(
|
||||||
logged_in_client,
|
logged_in_client,
|
||||||
mocker,
|
mocker,
|
||||||
|
|||||||
@@ -77,6 +77,15 @@ def mock_get_service(mocker, api_user_active):
|
|||||||
return mocker.patch('app.service_api_client.get_service', side_effect=_get)
|
return mocker.patch('app.service_api_client.get_service', side_effect=_get)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='function')
|
||||||
|
def mock_get_international_service(mocker, api_user_active):
|
||||||
|
def _get(service_id):
|
||||||
|
service = service_json(service_id, users=[api_user_active.id], can_send_international_sms=True)
|
||||||
|
return {'data': service}
|
||||||
|
|
||||||
|
return mocker.patch('app.service_api_client.get_service', side_effect=_get)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def mock_get_detailed_service(mocker, api_user_active):
|
def mock_get_detailed_service(mocker, api_user_active):
|
||||||
def _get(service_id):
|
def _get(service_id):
|
||||||
|
|||||||
Reference in New Issue
Block a user