Update tests to focus on US numbers

This commit is contained in:
Ryan Ahearn
2023-01-05 11:06:12 -05:00
parent abc7b09d0d
commit 82df01653f
21 changed files with 172 additions and 201 deletions
+5 -5
View File
@@ -31,11 +31,11 @@ def test_make_sns_callback(notify_api, rmock):
endpoint, endpoint,
json={"status": "success"}, json={"status": "success"},
status_code=200) status_code=200)
send_sms_response("sns", "1234", "5558675309") send_sms_response("sns", "1234", "2028675309")
assert rmock.called assert rmock.called
assert rmock.request_history[0].url == endpoint assert rmock.request_history[0].url == endpoint
assert json.loads(rmock.request_history[0].text)['MSISDN'] == '5558675309' assert json.loads(rmock.request_history[0].text)['MSISDN'] == '2028675309'
@pytest.mark.skip(reason="Re-enable when SMS receipts exist") @pytest.mark.skip(reason="Re-enable when SMS receipts exist")
@@ -70,7 +70,7 @@ def test_make_ses_callback(notify_api, mocker):
@pytest.mark.skip(reason="Re-enable when SNS delivery receipts exist") @pytest.mark.skip(reason="Re-enable when SNS delivery receipts exist")
def test_delievered_sns_callback(): def test_delievered_sns_callback():
phone_number = "5558675309" phone_number = "2028675309"
data = json.loads(sns_callback("1234", phone_number)) data = json.loads(sns_callback("1234", phone_number))
assert data['MSISDN'] == phone_number assert data['MSISDN'] == phone_number
assert data['status'] == "3" assert data['status'] == "3"
@@ -80,7 +80,7 @@ def test_delievered_sns_callback():
@pytest.mark.skip(reason="Re-enable when SNS delivery receipts exist") @pytest.mark.skip(reason="Re-enable when SNS delivery receipts exist")
def test_perm_failure_sns_callback(): def test_perm_failure_sns_callback():
phone_number = "5558675302" phone_number = "2028675302"
data = json.loads(sns_callback("1234", phone_number)) data = json.loads(sns_callback("1234", phone_number))
assert data['MSISDN'] == phone_number assert data['MSISDN'] == phone_number
assert data['status'] == "5" assert data['status'] == "5"
@@ -90,7 +90,7 @@ def test_perm_failure_sns_callback():
@pytest.mark.skip(reason="Re-enable when SNS delivery receipts exist") @pytest.mark.skip(reason="Re-enable when SNS delivery receipts exist")
def test_temp_failure_sns_callback(): def test_temp_failure_sns_callback():
phone_number = "5558675303" phone_number = "2028675303"
data = json.loads(sns_callback("1234", phone_number)) data = json.loads(sns_callback("1234", phone_number))
assert data['MSISDN'] == phone_number assert data['MSISDN'] == phone_number
assert data['status'] == "4" assert data['status'] == "4"
+11 -11
View File
@@ -502,10 +502,10 @@ def test_should_put_save_sms_task_in_research_mode_queue_if_research_mode_servic
def test_should_save_sms_if_restricted_service_and_valid_number(notify_db_session, mocker): def test_should_save_sms_if_restricted_service_and_valid_number(notify_db_session, mocker):
user = create_user(mobile_number="07700 900890") user = create_user(mobile_number="202-867-5309")
service = create_service(user=user, restricted=True) service = create_service(user=user, restricted=True)
template = create_template(service=service) template = create_template(service=service)
notification = _notification_json(template, "+447700900890") # The users own number, but in a different format notification = _notification_json(template, "+12028675309") # The users own number, but in a different format
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async') mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
@@ -518,7 +518,7 @@ def test_should_save_sms_if_restricted_service_and_valid_number(notify_db_sessio
) )
persisted_notification = Notification.query.one() persisted_notification = Notification.query.one()
assert persisted_notification.to == '+447700900890' assert persisted_notification.to == '+12028675309'
assert persisted_notification.template_id == template.id assert persisted_notification.template_id == template.id
assert persisted_notification.template_version == template.version assert persisted_notification.template_version == template.version
assert persisted_notification.status == 'created' assert persisted_notification.status == 'created'
@@ -553,11 +553,11 @@ def test_save_email_should_save_default_email_reply_to_text_on_notification(noti
assert persisted_notification.reply_to_text == 'reply_to@digital.gov.uk' assert persisted_notification.reply_to_text == 'reply_to@digital.gov.uk'
def test_save_sms_should_save_default_smm_sender_notification_reply_to_text_on(notify_db_session, mocker): def test_save_sms_should_save_default_sms_sender_notification_reply_to_text_on(notify_db_session, mocker):
service = create_service_with_defined_sms_sender(sms_sender_value='12345') service = create_service_with_defined_sms_sender(sms_sender_value='12345')
template = create_template(service=service) template = create_template(service=service)
notification = _notification_json(template, to="07700 900205") notification = _notification_json(template, to="2028675309")
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async') mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
notification_id = uuid.uuid4() notification_id = uuid.uuid4()
@@ -1204,10 +1204,10 @@ def test_save_letter_uses_template_reply_to_text(mocker, notify_db_session):
def test_save_sms_uses_sms_sender_reply_to_text(mocker, notify_db_session): def test_save_sms_uses_sms_sender_reply_to_text(mocker, notify_db_session):
service = create_service_with_defined_sms_sender(sms_sender_value='07123123123') service = create_service_with_defined_sms_sender(sms_sender_value='2028675309')
template = create_template(service=service) template = create_template(service=service)
notification = _notification_json(template, to="07700 900205") notification = _notification_json(template, to="2028675301")
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async') mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
notification_id = uuid.uuid4() notification_id = uuid.uuid4()
@@ -1218,15 +1218,15 @@ def test_save_sms_uses_sms_sender_reply_to_text(mocker, notify_db_session):
) )
persisted_notification = Notification.query.one() persisted_notification = Notification.query.one()
assert persisted_notification.reply_to_text == '447123123123' assert persisted_notification.reply_to_text == '+12028675309'
def test_save_sms_uses_non_default_sms_sender_reply_to_text_if_provided(mocker, notify_db_session): def test_save_sms_uses_non_default_sms_sender_reply_to_text_if_provided(mocker, notify_db_session):
service = create_service_with_defined_sms_sender(sms_sender_value='07123123123') service = create_service_with_defined_sms_sender(sms_sender_value='2028675309')
template = create_template(service=service) template = create_template(service=service)
new_sender = service_sms_sender_dao.dao_add_sms_sender_for_service(service.id, 'new-sender', False) new_sender = service_sms_sender_dao.dao_add_sms_sender_for_service(service.id, 'new-sender', False)
notification = _notification_json(template, to="07700 900205") notification = _notification_json(template, to="202-867-5301")
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async') mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
notification_id = uuid.uuid4() notification_id = uuid.uuid4()
@@ -1918,7 +1918,7 @@ def test_save_api_email_dont_retry_if_notification_already_exists(sample_service
), ( ), (
save_sms, save_sms,
'app.celery.provider_tasks.deliver_sms.apply_async', 'app.celery.provider_tasks.deliver_sms.apply_async',
'07700 900890', '202-867-5309',
{'template_type': 'sms'} {'template_type': 'sms'}
), ),
)) ))
@@ -1080,16 +1080,14 @@ def test_dao_get_notifications_by_reference_escapes_special_character(
@pytest.mark.parametrize('search_term', [ @pytest.mark.parametrize('search_term', [
'001', '309',
'100', '530',
'09001', '8675309',
'077009001', '202867',
'07700 9001', '202 867',
'(0)7700 9001', '202-867-5309',
'4477009001', '2028675309',
'+4477009001', '+12028675309',
pytest.param('+44077009001', marks=pytest.mark.skip(reason='No easy way to normalise this')),
pytest.param('+44(0)77009001', marks=pytest.mark.skip(reason='No easy way to normalise this')),
]) ])
def test_dao_get_notifications_by_recipient_matches_partial_phone_numbers( def test_dao_get_notifications_by_recipient_matches_partial_phone_numbers(
sample_template, sample_template,
@@ -1098,13 +1096,13 @@ def test_dao_get_notifications_by_recipient_matches_partial_phone_numbers(
notification_1 = create_notification( notification_1 = create_notification(
template=sample_template, template=sample_template,
to_field='+447700900100', to_field='202-867-5309',
normalised_to='447700900100', normalised_to='+12028675309',
) )
notification_2 = create_notification( notification_2 = create_notification(
template=sample_template, template=sample_template,
to_field='+447700900200', to_field='202-678-5000',
normalised_to='447700900200', normalised_to='+12026785000',
) )
results = dao_get_notifications_by_recipient_or_reference( results = dao_get_notifications_by_recipient_or_reference(
notification_1.service_id, search_term, notification_type='sms' notification_1.service_id, search_term, notification_type='sms'
@@ -1156,7 +1154,7 @@ def test_dao_get_notifications_by_recipient_ignores_spaces(sample_template):
@pytest.mark.parametrize('phone_search', ( @pytest.mark.parametrize('phone_search', (
'077', '7-7', '+44(0)7711 111111' '202', '7-5', '+1 (202) 867-5309'
)) ))
@pytest.mark.parametrize('email_search', ( @pytest.mark.parametrize('email_search', (
'example', 'eXaMpLe', 'example', 'eXaMpLe',
@@ -1169,9 +1167,9 @@ def test_dao_get_notifications_by_recipient_searches_across_notification_types(
service = create_service() service = create_service()
sms_template = create_template(service=service) sms_template = create_template(service=service)
email_template = create_template(service=service, template_type='email') email_template = create_template(service=service, template_type='email')
sms = create_notification(template=sms_template, to_field='07711111111', normalised_to='447711111111') sms = create_notification(template=sms_template, to_field='202-867-5309', normalised_to='+12028675309')
email = create_notification( email = create_notification(
template=email_template, to_field='077@example.com', normalised_to='077@example.com' template=email_template, to_field='202@example.com', normalised_to='202@example.com'
) )
results = dao_get_notifications_by_recipient_or_reference( results = dao_get_notifications_by_recipient_or_reference(
@@ -1186,7 +1184,7 @@ def test_dao_get_notifications_by_recipient_searches_across_notification_types(
assert len(results.items) == 1 assert len(results.items) == 1
assert results.items[0].id == email.id assert results.items[0].id == email.id
results = dao_get_notifications_by_recipient_or_reference(service.id, '77') results = dao_get_notifications_by_recipient_or_reference(service.id, '202')
assert len(results.items) == 2 assert len(results.items) == 2
assert results.items[0].id == email.id assert results.items[0].id == email.id
assert results.items[1].id == sms.id assert results.items[1].id == sms.id
+5 -5
View File
@@ -258,7 +258,7 @@ def test_should_add_user_to_service(notify_db_session):
name='Test User', name='Test User',
email_address='new_user@digital.cabinet-office.gov.uk', email_address='new_user@digital.cabinet-office.gov.uk',
password='password', password='password',
mobile_number='+447700900986' mobile_number='+12028675309'
) )
save_model_user(new_user, validated_email_access=True) save_model_user(new_user, validated_email_access=True)
dao_add_user_to_service(service, new_user) dao_add_user_to_service(service, new_user)
@@ -327,7 +327,7 @@ def test_should_remove_user_from_service(notify_db_session):
name='Test User', name='Test User',
email_address='new_user@digital.cabinet-office.gov.uk', email_address='new_user@digital.cabinet-office.gov.uk',
password='password', password='password',
mobile_number='+447700900986' mobile_number='+12028675309'
) )
save_model_user(new_user, validated_email_access=True) save_model_user(new_user, validated_email_access=True)
dao_add_user_to_service(service, new_user) dao_add_user_to_service(service, new_user)
@@ -428,7 +428,7 @@ def test_get_all_user_services_only_returns_services_user_has_access_to(notify_d
name='Test User', name='Test User',
email_address='new_user@digital.cabinet-office.gov.uk', email_address='new_user@digital.cabinet-office.gov.uk',
password='password', password='password',
mobile_number='+447700900986' mobile_number='+12028675309'
) )
save_model_user(new_user, validated_email_access=True) save_model_user(new_user, validated_email_access=True)
dao_add_user_to_service(service_3, new_user) dao_add_user_to_service(service_3, new_user)
@@ -486,7 +486,7 @@ def test_dao_fetch_live_services_data(sample_user):
assert results == [ assert results == [
{'service_id': mock.ANY, 'service_name': 'Sample service', 'organisation_name': 'test_org_1', {'service_id': mock.ANY, 'service_name': 'Sample service', 'organisation_name': 'test_org_1',
'organisation_type': 'federal', 'consent_to_research': None, 'contact_name': 'Test User', 'organisation_type': 'federal', 'consent_to_research': None, 'contact_name': 'Test User',
'contact_email': 'notify@digital.cabinet-office.gov.uk', 'contact_mobile': '+447700900986', 'contact_email': 'notify@digital.cabinet-office.gov.uk', 'contact_mobile': '+12028675309',
'live_date': datetime(2014, 4, 20, 10, 0), 'sms_volume_intent': None, 'email_volume_intent': None, 'live_date': datetime(2014, 4, 20, 10, 0), 'sms_volume_intent': None, 'email_volume_intent': None,
'letter_volume_intent': None, 'sms_totals': 2, 'email_totals': 1, 'letter_totals': 1, 'letter_volume_intent': None, 'sms_totals': 2, 'email_totals': 1, 'letter_totals': 1,
'free_sms_fragment_limit': 100}, 'free_sms_fragment_limit': 100},
@@ -498,7 +498,7 @@ def test_dao_fetch_live_services_data(sample_user):
'free_sms_fragment_limit': 200}, 'free_sms_fragment_limit': 200},
{'service_id': mock.ANY, 'service_name': 'second', 'organisation_name': None, 'consent_to_research': None, {'service_id': mock.ANY, 'service_name': 'second', 'organisation_name': None, 'consent_to_research': None,
'contact_name': 'Test User', 'contact_email': 'notify@digital.cabinet-office.gov.uk', 'contact_name': 'Test User', 'contact_email': 'notify@digital.cabinet-office.gov.uk',
'contact_mobile': '+447700900986', 'live_date': datetime(2017, 4, 20, 10, 0), 'sms_volume_intent': None, 'contact_mobile': '+12028675309', 'live_date': datetime(2017, 4, 20, 10, 0), 'sms_volume_intent': None,
'organisation_type': None, 'email_volume_intent': None, 'letter_volume_intent': None, 'organisation_type': None, 'email_volume_intent': None, 'letter_volume_intent': None,
'sms_totals': 0, 'email_totals': 0, 'letter_totals': 1, 'sms_totals': 0, 'email_totals': 0, 'letter_totals': 1,
'free_sms_fragment_limit': 300} 'free_sms_fragment_limit': 300}
+1 -1
View File
@@ -38,7 +38,7 @@ from tests.app.db import (
@freeze_time('2020-01-28T12:00:00') @freeze_time('2020-01-28T12:00:00')
@pytest.mark.parametrize('phone_number', [ @pytest.mark.parametrize('phone_number', [
'+447700900986', '+12028675309',
'+1-800-555-5555', '+1-800-555-5555',
]) ])
def test_create_user(notify_db_session, phone_number): def test_create_user(notify_db_session, phone_number):
+1 -1
View File
@@ -72,7 +72,7 @@ from app.models import (
def create_user( def create_user(
*, *,
mobile_number="+447700900986", mobile_number="+12028675309",
email=None, email=None,
state='active', state='active',
id_=None, id_=None,
+8 -8
View File
@@ -117,10 +117,10 @@ def test_should_send_personalised_template_to_correct_sms_provider_and_persist(
mocker mocker
): ):
db_notification = create_notification(template=sample_sms_template_with_html, db_notification = create_notification(template=sample_sms_template_with_html,
to_field="5558675309", personalisation={"name": "Jo"}, to_field="2028675309", personalisation={"name": "Jo"},
status='created', status='created',
reply_to_text=sample_sms_template_with_html.service.get_default_sms_sender(), reply_to_text=sample_sms_template_with_html.service.get_default_sms_sender(),
normalised_to="5558675309" normalised_to="2028675309"
) )
mocker.patch('app.aws_sns_client.send_sms') mocker.patch('app.aws_sns_client.send_sms')
@@ -130,7 +130,7 @@ def test_should_send_personalised_template_to_correct_sms_provider_and_persist(
) )
aws_sns_client.send_sms.assert_called_once_with( aws_sns_client.send_sms.assert_called_once_with(
to="5558675309", to="2028675309",
content="Sample service: Hello Jo\nHere is <em>some HTML</em> & entities", content="Sample service: Hello Jo\nHere is <em>some HTML</em> & entities",
reference=str(db_notification.id), reference=str(db_notification.id),
sender=current_app.config['FROM_NUMBER'], sender=current_app.config['FROM_NUMBER'],
@@ -210,9 +210,9 @@ def test_should_not_send_sms_message_when_service_is_inactive_notification_is_in
def test_send_sms_should_use_template_version_from_notification_not_latest( def test_send_sms_should_use_template_version_from_notification_not_latest(
sample_template, sample_template,
mocker): mocker):
db_notification = create_notification(template=sample_template, to_field='5558675309', status='created', db_notification = create_notification(template=sample_template, to_field='2028675309', status='created',
reply_to_text=sample_template.service.get_default_sms_sender(), reply_to_text=sample_template.service.get_default_sms_sender(),
normalised_to='5558675309') normalised_to='2028675309')
mocker.patch('app.aws_sns_client.send_sms') mocker.patch('app.aws_sns_client.send_sms')
@@ -234,7 +234,7 @@ def test_send_sms_should_use_template_version_from_notification_not_latest(
) )
aws_sns_client.send_sms.assert_called_once_with( aws_sns_client.send_sms.assert_called_once_with(
to="5558675309", to="2028675309",
content="Sample service: This is a template:\nwith a newline", content="Sample service: This is a template:\nwith a newline",
reference=str(db_notification.id), reference=str(db_notification.id),
sender=current_app.config['FROM_NUMBER'], sender=current_app.config['FROM_NUMBER'],
@@ -737,8 +737,8 @@ def test_send_sms_to_provider_should_use_normalised_to(
): ):
send_mock = mocker.patch('app.aws_sns_client.send_sms') send_mock = mocker.patch('app.aws_sns_client.send_sms')
notification = create_notification(template=sample_template, notification = create_notification(template=sample_template,
to_field='+15558675309', to_field='+12028675309',
normalised_to='5558675309') normalised_to='2028675309')
send_to_providers.send_sms_to_provider(notification) send_to_providers.send_sms_to_provider(notification)
send_mock.assert_called_once_with(to=notification.normalised_to, send_mock.assert_called_once_with(to=notification.normalised_to,
content=ANY, content=ANY,
@@ -122,7 +122,7 @@ def test_persist_notification_with_optionals(sample_job, sample_api_key):
persist_notification( persist_notification(
template_id=sample_job.template.id, template_id=sample_job.template.id,
template_version=sample_job.template.version, template_version=sample_job.template.version,
recipient='+447111111111', recipient='+12028675309',
service=sample_job.service, service=sample_job.service,
personalisation=None, personalisation=None,
notification_type='sms', notification_type='sms',
@@ -146,7 +146,7 @@ def test_persist_notification_with_optionals(sample_job, sample_api_key):
assert persisted_notification.client_reference == "ref from client" assert persisted_notification.client_reference == "ref from client"
assert persisted_notification.reference is None assert persisted_notification.reference is None
assert persisted_notification.international is False assert persisted_notification.international is False
assert persisted_notification.phone_prefix == '44' assert persisted_notification.phone_prefix == '1'
assert persisted_notification.rate_multiplier == 1 assert persisted_notification.rate_multiplier == 1
assert persisted_notification.created_by_id == sample_job.created_by_id assert persisted_notification.created_by_id == sample_job.created_by_id
assert not persisted_notification.reply_to_text assert not persisted_notification.reply_to_text
@@ -297,15 +297,15 @@ def test_send_notification_to_queue_throws_exception_deletes_notification(sample
@pytest.mark.parametrize("to_address, notification_type, expected", [ @pytest.mark.parametrize("to_address, notification_type, expected", [
("+447700900000", "sms", True), ("+12028675000", "sms", True),
("+447700900111", "sms", True), ("+12028675111", "sms", True),
("+447700900222", "sms", True), ("+12028675222", "sms", True),
("07700900000", "sms", True), ("2028675000", "sms", True),
("7700900111", "sms", True), ("2028675111", "sms", True),
("simulate-delivered@notifications.service.gov.uk", "email", True), ("simulate-delivered@notifications.service.gov.uk", "email", True),
("simulate-delivered-2@notifications.service.gov.uk", "email", True), ("simulate-delivered-2@notifications.service.gov.uk", "email", True),
("simulate-delivered-3@notifications.service.gov.uk", "email", True), ("simulate-delivered-3@notifications.service.gov.uk", "email", True),
("07515896969", "sms", False), ("2028675309", "sms", False),
("valid_email@test.com", "email", False) ("valid_email@test.com", "email", False)
]) ])
def test_simulated_recipient(notify_api, to_address, notification_type, expected): def test_simulated_recipient(notify_api, to_address, notification_type, expected):
@@ -317,7 +317,7 @@ def test_simulated_recipient(notify_api, to_address, notification_type, expected
'simulate-delivered-2@notifications.service.gov.uk', 'simulate-delivered-2@notifications.service.gov.uk',
'simulate-delivered-2@notifications.service.gov.uk' 'simulate-delivered-2@notifications.service.gov.uk'
) )
SIMULATED_SMS_NUMBERS = ('+447700900000', '+447700900111', '+447700900222') SIMULATED_SMS_NUMBERS = ('+12028675000', '+12028675111', '+12028675222')
""" """
formatted_address = None formatted_address = None
@@ -332,12 +332,10 @@ def test_simulated_recipient(notify_api, to_address, notification_type, expected
@pytest.mark.parametrize('recipient, expected_international, expected_prefix, expected_units', [ @pytest.mark.parametrize('recipient, expected_international, expected_prefix, expected_units', [
('7900900123', False, '44', 1), # UK ('+447900900123', True, '44', 1), # UK
('+447900900123', False, '44', 1), # UK ('+73122345678', True, '7', 1), # Russia
('07700910222', True, '44', 1), # UK (Jersey) ('+360623400400', True, '36', 1), # Hungary
('07700900222', False, '44', 1), # TV number ('2028675309', False, '1', 1)] # USA
('73122345678', True, '7', 1), # Russia
('360623400400', True, '36', 3)] # Hungary
) )
def test_persist_notification_with_international_info_stores_correct_info( def test_persist_notification_with_international_info_stores_correct_info(
sample_job, sample_job,
@@ -394,15 +392,12 @@ def test_persist_notification_with_international_info_does_not_store_for_email(
@pytest.mark.parametrize('recipient, expected_recipient_normalised', [ @pytest.mark.parametrize('recipient, expected_recipient_normalised', [
('7900900123', '447900900123'), ('+4407900900123', '+447900900123'),
('+447900 900 123', '447900900123'), ('202-867-5309', '+12028675309'),
(' 07700900222', '447700900222'), ('1 202-867-5309', '+12028675309'),
('07700900222', '447700900222'), ('+1 (202) 867-5309', '+12028675309'),
(' 73122345678', '73122345678'), ('(202) 867-5309', '+12028675309'),
('360623400400', '360623400400'), ('2028675309', '+12028675309')
('-077-00900222-', '447700900222'),
('(360623(400400)', '360623400400')
]) ])
def test_persist_sms_notification_stores_normalised_number( def test_persist_sms_notification_stores_normalised_number(
sample_job, sample_job,
@@ -40,7 +40,7 @@ def test_receive_notification_returns_received_to_sns(client, mocker, sample_ser
mocked = mocker.patch("app.notifications.receive_notifications.tasks.send_inbound_sms_to_service.apply_async") mocked = mocker.patch("app.notifications.receive_notifications.tasks.send_inbound_sms_to_service.apply_async")
prom_counter_labels_mock = mocker.patch('app.notifications.receive_notifications.INBOUND_SMS_COUNTER.labels') prom_counter_labels_mock = mocker.patch('app.notifications.receive_notifications.INBOUND_SMS_COUNTER.labels')
data = { data = {
"originationNumber": "+15558675309", "originationNumber": "+12028675309",
"destinationNumber": sample_service_full_permissions.get_inbound_number(), "destinationNumber": sample_service_full_permissions.get_inbound_number(),
"messageKeyword": "JOIN", "messageKeyword": "JOIN",
"messageBody": "EXAMPLE", "messageBody": "EXAMPLE",
@@ -241,9 +241,9 @@ def test_receive_notification_error_if_not_single_matching_service(client, notif
@pytest.mark.parametrize( @pytest.mark.parametrize(
'number, expected', 'number, expected',
[ [
('15558675309', '5558675309'), ('12028675309', '2028675309'),
('+15558675309', '5558675309'), ('+12028675309', '2028675309'),
('5558675309', '5558675309'), ('2028675309', '2028675309'),
('15111111111', '5111111111') ('15111111111', '5111111111')
] ]
) )
+11 -11
View File
@@ -167,10 +167,10 @@ def test_service_can_send_to_recipient_passes(key_type, notify_db_session):
@pytest.mark.parametrize('user_number, recipient_number', [ @pytest.mark.parametrize('user_number, recipient_number', [
['0048601234567', '+486 012 34567'], ['+12028675309', '202-867-5309'],
['07513332413', '(07513) 332413'], ['+447513332413', '+44 (07513) 332413'],
]) ])
def test_service_can_send_to_recipient_passes_with_non_normalised_number(sample_service, user_number, recipient_number): def test_service_can_send_to_recipient_passes_with_non_normalized_number(sample_service, user_number, recipient_number):
sample_service.users[0].mobile_number = user_number sample_service.users[0].mobile_number = user_number
serialised_service = SerialisedService.from_id(sample_service.id) serialised_service = SerialisedService.from_id(sample_service.id)
@@ -181,7 +181,7 @@ def test_service_can_send_to_recipient_passes_with_non_normalised_number(sample_
@pytest.mark.parametrize('user_email, recipient_email', [ @pytest.mark.parametrize('user_email, recipient_email', [
['test@example.com', 'TeSt@EXAMPLE.com'], ['test@example.com', 'TeSt@EXAMPLE.com'],
]) ])
def test_service_can_send_to_recipient_passes_with_non_normalised_email(sample_service, user_email, recipient_email): def test_service_can_send_to_recipient_passes_with_non_normalized_email(sample_service, user_email, recipient_email):
sample_service.users[0].email_address = user_email sample_service.users[0].email_address = user_email
serialised_service = SerialisedService.from_id(sample_service.id) serialised_service = SerialisedService.from_id(sample_service.id)
@@ -206,15 +206,15 @@ def test_service_can_send_to_recipient_passes_for_guest_list_recipient_passes(sa
assert service_can_send_to_recipient("some_other_email@test.com", assert service_can_send_to_recipient("some_other_email@test.com",
'team', 'team',
sample_service) is None sample_service) is None
create_service_guest_list(sample_service, mobile_number='07513332413') create_service_guest_list(sample_service, mobile_number='2028675309')
assert service_can_send_to_recipient('07513332413', assert service_can_send_to_recipient('2028675309',
'team', 'team',
sample_service) is None sample_service) is None
@pytest.mark.parametrize('recipient', [ @pytest.mark.parametrize('recipient', [
{"email_address": "some_other_email@test.com"}, {"email_address": "some_other_email@test.com"},
{"mobile_number": "07513332413"}, {"mobile_number": "2028675300"},
]) ])
def test_service_can_send_to_recipient_fails_when_ignoring_guest_list( def test_service_can_send_to_recipient_fails_when_ignoring_guest_list(
notify_db_session, notify_db_session,
@@ -234,7 +234,7 @@ def test_service_can_send_to_recipient_fails_when_ignoring_guest_list(
assert exec_info.value.fields == [] assert exec_info.value.fields == []
@pytest.mark.parametrize('recipient', ['07513332413', 'some_other_email@test.com']) @pytest.mark.parametrize('recipient', ['2028675300', 'some_other_email@test.com'])
@pytest.mark.parametrize('key_type, error_message', @pytest.mark.parametrize('key_type, error_message',
[('team', 'Cant send to this recipient using a team-only API key'), [('team', 'Cant send to this recipient using a team-only API key'),
('normal', ('normal',
@@ -482,7 +482,7 @@ def test_validate_and_format_recipient_fails_when_international_number_and_servi
service = create_service(service_permissions=[SMS_TYPE]) service = create_service(service_permissions=[SMS_TYPE])
service_model = SerialisedService.from_id(service.id) service_model = SerialisedService.from_id(service.id)
with pytest.raises(BadRequestError) as e: with pytest.raises(BadRequestError) as e:
validate_and_format_recipient('20-12-1234-1234', key_type, service_model, SMS_TYPE) validate_and_format_recipient('+20-12-1234-1234', key_type, service_model, SMS_TYPE)
assert e.value.status_code == 400 assert e.value.status_code == 400
assert e.value.message == 'Cannot send to international mobile numbers' assert e.value.message == 'Cannot send to international mobile numbers'
assert e.value.fields == [] assert e.value.fields == []
@@ -492,8 +492,8 @@ def test_validate_and_format_recipient_fails_when_international_number_and_servi
def test_validate_and_format_recipient_succeeds_with_international_numbers_if_service_does_allow_int_sms( def test_validate_and_format_recipient_succeeds_with_international_numbers_if_service_does_allow_int_sms(
key_type, sample_service_full_permissions): key_type, sample_service_full_permissions):
service_model = SerialisedService.from_id(sample_service_full_permissions.id) service_model = SerialisedService.from_id(sample_service_full_permissions.id)
result = validate_and_format_recipient('20-12-1234-1234', key_type, service_model, SMS_TYPE) result = validate_and_format_recipient('+4407513332413', key_type, service_model, SMS_TYPE)
assert result == '201212341234' assert result == '+447513332413'
def test_validate_and_format_recipient_fails_when_no_recipient(): def test_validate_and_format_recipient_fails_when_no_recipient():
@@ -24,7 +24,7 @@ def test_post_sms_contract(client, mocker, sample_template):
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async') mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
response_json = return_json_from_response(_post_notification( response_json = return_json_from_response(_post_notification(
client, sample_template, url='/notifications/sms', to='07700 900 855' client, sample_template, url='/notifications/sms', to='202-867-5309'
)) ))
validate_v0(response_json, 'POST_notification_return_sms.json') validate_v0(response_json, 'POST_notification_return_sms.json')
@@ -83,7 +83,8 @@ def test_should_reject_bad_phone_numbers(notify_api, sample_template, mocker):
mocked.assert_not_called() mocked.assert_not_called()
assert json_resp['result'] == 'error' assert json_resp['result'] == 'error'
assert len(json_resp['message'].keys()) == 1 assert len(json_resp['message'].keys()) == 1
assert 'Invalid phone number: Must not contain letters or symbols' in json_resp['message']['to'] assert 'Invalid phone number: The string supplied did not seem to be a phone number.' \
in json_resp['message']['to']
assert response.status_code == 400 assert response.status_code == 400
@@ -338,7 +339,7 @@ def test_should_allow_valid_sms_notification(notify_api, sample_template, mocker
mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async') mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
data = { data = {
'to': '07700 900 855', 'to': '202 867 5309',
'template': str(sample_template.id) 'template': str(sample_template.id)
} }
@@ -497,7 +498,7 @@ def test_should_not_send_sms_if_team_api_key_and_not_a_service_user(client, samp
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async') mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
data = { data = {
'to': '07123123123', 'to': '2028675300',
'template': str(sample_template.id), 'template': str(sample_template.id),
} }
@@ -550,7 +551,7 @@ def test_should_send_sms_to_anyone_with_test_key(
mocker.patch('app.notifications.process_notifications.uuid.uuid4', return_value=fake_uuid) mocker.patch('app.notifications.process_notifications.uuid.uuid4', return_value=fake_uuid)
data = { data = {
'to': '07811111111', 'to': '2028675300',
'template': sample_template.id 'template': sample_template.id
} }
sample_template.service.restricted = restricted sample_template.service.restricted = restricted
@@ -756,9 +757,9 @@ def test_should_not_persist_notification_or_send_email_if_simulated_email(
@pytest.mark.parametrize('to_sms', [ @pytest.mark.parametrize('to_sms', [
'07700 900000', '2028675000',
'07700 900111', '2028675111',
'07700 900222' '+12028675222'
]) ])
def test_should_not_persist_notification_or_send_sms_if_simulated_number( def test_should_not_persist_notification_or_send_sms_if_simulated_number(
client, client,
@@ -788,7 +789,7 @@ def test_should_not_persist_notification_or_send_sms_if_simulated_number(
KEY_TYPE_NORMAL, KEY_TYPE_TEAM KEY_TYPE_NORMAL, KEY_TYPE_TEAM
]) ])
@pytest.mark.parametrize('notification_type, to', [ @pytest.mark.parametrize('notification_type, to', [
(SMS_TYPE, '07827992635'), (SMS_TYPE, '2028675300'),
(EMAIL_TYPE, 'non_guest_list_recipient@mail.com')] (EMAIL_TYPE, 'non_guest_list_recipient@mail.com')]
) )
def test_should_not_send_notification_to_non_guest_list_recipient_in_trial_mode( def test_should_not_send_notification_to_non_guest_list_recipient_in_trial_mode(
@@ -842,7 +843,7 @@ def test_should_not_send_notification_to_non_guest_list_recipient_in_trial_mode(
KEY_TYPE_NORMAL, KEY_TYPE_TEAM KEY_TYPE_NORMAL, KEY_TYPE_TEAM
]) ])
@pytest.mark.parametrize('notification_type, to', [ @pytest.mark.parametrize('notification_type, to', [
(SMS_TYPE, '07123123123'), (SMS_TYPE, '2028675300'),
(EMAIL_TYPE, 'guest_list_recipient@mail.com')] (EMAIL_TYPE, 'guest_list_recipient@mail.com')]
) )
def test_should_send_notification_to_guest_list_recipient( def test_should_send_notification_to_guest_list_recipient(
@@ -893,7 +894,7 @@ def test_should_send_notification_to_guest_list_recipient(
@pytest.mark.parametrize( @pytest.mark.parametrize(
'notification_type, template_type, to', [ 'notification_type, template_type, to', [
(EMAIL_TYPE, SMS_TYPE, 'notify@digital.cabinet-office.gov.uk'), (EMAIL_TYPE, SMS_TYPE, 'notify@digital.cabinet-office.gov.uk'),
(SMS_TYPE, EMAIL_TYPE, '+447700900986') (SMS_TYPE, EMAIL_TYPE, '+12028675309')
]) ])
def test_should_error_if_notification_type_does_not_match_template_type( def test_should_error_if_notification_type_does_not_match_template_type(
client, client,
@@ -966,7 +967,7 @@ def test_create_template_raises_invalid_request_when_content_too_large(
@pytest.mark.parametrize("notification_type, send_to", @pytest.mark.parametrize("notification_type, send_to",
[("sms", "07700 900 855"), [("sms", "2028675309"),
("email", "sample@email.com")]) ("email", "sample@email.com")])
def test_send_notification_uses_priority_queue_when_template_is_marked_as_priority( def test_send_notification_uses_priority_queue_when_template_is_marked_as_priority(
client, client,
@@ -999,7 +1000,7 @@ def test_send_notification_uses_priority_queue_when_template_is_marked_as_priori
@pytest.mark.parametrize( @pytest.mark.parametrize(
"notification_type, send_to", "notification_type, send_to",
[("sms", "07700 900 855"), ("email", "sample@email.com")] [("sms", "2028675309"), ("email", "sample@email.com")]
) )
def test_returns_a_429_limit_exceeded_if_rate_limit_exceeded( def test_returns_a_429_limit_exceeded_if_rate_limit_exceeded(
client, client,
@@ -1042,7 +1043,7 @@ def test_should_allow_store_original_number_on_sms_notification(client, sample_t
mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async') mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
data = { data = {
'to': '+(44) 7700-900 855', 'to': '(202) 867-5309',
'template': str(sample_template.id) 'template': str(sample_template.id)
} }
@@ -1061,7 +1062,7 @@ def test_should_allow_store_original_number_on_sms_notification(client, sample_t
assert notification_id assert notification_id
notifications = Notification.query.all() notifications = Notification.query.all()
assert len(notifications) == 1 assert len(notifications) == 1
assert '+(44) 7700-900 855' == notifications[0].to assert '(202) 867-5309' == notifications[0].to
def test_should_not_allow_sending_to_international_number_without_international_permission( def test_should_not_allow_sending_to_international_number_without_international_permission(
@@ -1070,7 +1071,7 @@ def test_should_not_allow_sending_to_international_number_without_international_
mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async') mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
data = { data = {
'to': '20-12-1234-1234', 'to': '+(44) 7700-900 855',
'template': str(sample_template.id) 'template': str(sample_template.id)
} }
@@ -1088,29 +1089,6 @@ def test_should_not_allow_sending_to_international_number_without_international_
assert error_json['message'] == 'Cannot send to international mobile numbers' assert error_json['message'] == 'Cannot send to international mobile numbers'
def test_should_allow_sending_to_crown_dependency_number_without_international_permission(
client, mocker, notify_db_session
):
service = create_service()
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
template = create_template(service)
data = {
'to': '07700-900-123',
'template': str(template.id)
}
auth_header = create_service_authorization_header(service_id=service.id)
response = client.post(
path='/notifications/sms',
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 201
def test_should_allow_sending_to_international_number_with_international_permission( def test_should_allow_sending_to_international_number_with_international_permission(
client, sample_service_full_permissions, mocker client, sample_service_full_permissions, mocker
): ):
@@ -1118,7 +1096,7 @@ def test_should_allow_sending_to_international_number_with_international_permiss
template = create_template(sample_service_full_permissions) template = create_template(sample_service_full_permissions)
data = { data = {
'to': '20-12-1234-1234', 'to': '+(44) 7700-900 855',
'template': str(template.id) 'template': str(template.id)
} }
@@ -1140,7 +1118,7 @@ def test_should_not_allow_sms_notifications_if_service_permission_not_set(
mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async') mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
data = { data = {
'to': '+447700900986', 'to': '+12028675309',
'template': str(sample_template_without_sms_permission.id) 'template': str(sample_template_without_sms_permission.id)
} }
@@ -1201,7 +1179,7 @@ def test_should_throw_exception_if_notification_type_is_invalid(client, sample_s
@pytest.mark.parametrize("notification_type, recipient", @pytest.mark.parametrize("notification_type, recipient",
[("sms", '07700 900 855'), [("sms", '2028675309'),
("email", "test@gov.uk") ("email", "test@gov.uk")
] ]
) )
@@ -50,7 +50,7 @@ def test_send_one_off_notification_calls_celery_correctly(persist_mock, celery_m
post_data = { post_data = {
'template_id': str(template.id), 'template_id': str(template.id),
'to': '07700 900 001', 'to': '202-867-5309',
'created_by': str(service.created_by_id) 'created_by': str(service.created_by_id)
} }
@@ -81,7 +81,7 @@ def test_send_one_off_notification_calls_persist_correctly_for_sms(
post_data = { post_data = {
'template_id': str(template.id), 'template_id': str(template.id),
'to': '07700 900 001', 'to': '202-867-5309',
'personalisation': {'name': 'foo'}, 'personalisation': {'name': 'foo'},
'created_by': str(service.created_by_id) 'created_by': str(service.created_by_id)
} }
@@ -118,14 +118,14 @@ def test_send_one_off_notification_calls_persist_correctly_for_international_sms
post_data = { post_data = {
'template_id': str(template.id), 'template_id': str(template.id),
'to': '+1 555 0100', 'to': '+(44) 7700-900 855',
'personalisation': {'name': 'foo'}, 'personalisation': {'name': 'foo'},
'created_by': str(service.created_by_id) 'created_by': str(service.created_by_id)
} }
send_one_off_notification(service.id, post_data) send_one_off_notification(service.id, post_data)
assert persist_mock.call_args[1]['recipient'] == '+1 555 0100' assert persist_mock.call_args[1]['recipient'] == '+(44) 7700-900 855'
def test_send_one_off_notification_calls_persist_correctly_for_email( def test_send_one_off_notification_calls_persist_correctly_for_email(
@@ -223,7 +223,7 @@ def test_send_one_off_notification_honors_research_mode(notify_db_session, persi
post_data = { post_data = {
'template_id': str(template.id), 'template_id': str(template.id),
'to': '07700 900 001', 'to': '202-867-5309',
'created_by': str(service.created_by_id) 'created_by': str(service.created_by_id)
} }
@@ -239,7 +239,7 @@ def test_send_one_off_notification_honors_priority(notify_db_session, persist_mo
post_data = { post_data = {
'template_id': str(template.id), 'template_id': str(template.id),
'to': '07700 900 001', 'to': '202-867-5309',
'created_by': str(service.created_by_id) 'created_by': str(service.created_by_id)
} }
@@ -263,9 +263,9 @@ def test_send_one_off_notification_raises_if_invalid_recipient(notify_db_session
@pytest.mark.parametrize('recipient', [ @pytest.mark.parametrize('recipient', [
'07700 900 001', # not in team or guest_list '2028675300', # not in team or guest_list
'07700900123', # in guest_list '2028765309', # in guest_list
'+447700-900-123', # in guest_list in different format '+1-202-876-5309', # in guest_list in different format
]) ])
def test_send_one_off_notification_raises_if_cant_send_to_recipient( def test_send_one_off_notification_raises_if_cant_send_to_recipient(
notify_db_session, notify_db_session,
@@ -274,7 +274,7 @@ def test_send_one_off_notification_raises_if_cant_send_to_recipient(
service = create_service(restricted=True) service = create_service(restricted=True)
template = create_template(service=service) template = create_template(service=service)
dao_add_and_commit_guest_list_contacts([ dao_add_and_commit_guest_list_contacts([
ServiceGuestList.from_string(service.id, MOBILE_TYPE, '07700900123'), ServiceGuestList.from_string(service.id, MOBILE_TYPE, '2028765309'),
]) ])
post_data = { post_data = {
@@ -331,7 +331,7 @@ def test_send_one_off_notification_fails_if_created_by_other_service(sample_temp
post_data = { post_data = {
'template_id': str(sample_template.id), 'template_id': str(sample_template.id),
'to': '07700 900 001', 'to': '202-867-5309',
'created_by': str(user_not_in_service.id) 'created_by': str(user_not_in_service.id)
} }
@@ -414,12 +414,12 @@ def test_send_one_off_sms_notification_should_use_sms_sender_reply_to_text(sampl
template = create_template(service=sample_service, template_type=SMS_TYPE) template = create_template(service=sample_service, template_type=SMS_TYPE)
sms_sender = create_service_sms_sender( sms_sender = create_service_sms_sender(
service=sample_service, service=sample_service,
sms_sender='07123123123', sms_sender='2028675309',
is_default=False is_default=False
) )
data = { data = {
'to': '07111111111', 'to': '2028675000',
'template_id': str(template.id), 'template_id': str(template.id),
'created_by': str(sample_service.created_by_id), 'created_by': str(sample_service.created_by_id),
'sender_id': str(sms_sender.id), 'sender_id': str(sms_sender.id),
@@ -433,7 +433,7 @@ def test_send_one_off_sms_notification_should_use_sms_sender_reply_to_text(sampl
queue=None queue=None
) )
assert notification.reply_to_text == "447123123123" assert notification.reply_to_text == "+12028675309"
def test_send_one_off_sms_notification_should_use_default_service_reply_to_text(sample_service, celery_mock): def test_send_one_off_sms_notification_should_use_default_service_reply_to_text(sample_service, celery_mock):
@@ -441,12 +441,12 @@ def test_send_one_off_sms_notification_should_use_default_service_reply_to_text(
sample_service.service_sms_senders[0].is_default = False sample_service.service_sms_senders[0].is_default = False
create_service_sms_sender( create_service_sms_sender(
service=sample_service, service=sample_service,
sms_sender='07123123456', sms_sender='2028675309',
is_default=True is_default=True
) )
data = { data = {
'to': '07111111111', 'to': '2028675000',
'template_id': str(template.id), 'template_id': str(template.id),
'created_by': str(sample_service.created_by_id), 'created_by': str(sample_service.created_by_id),
} }
@@ -459,7 +459,7 @@ def test_send_one_off_sms_notification_should_use_default_service_reply_to_text(
queue=None queue=None
) )
assert notification.reply_to_text == "447123123456" assert notification.reply_to_text == "+12028675309"
def test_send_one_off_notification_should_throw_exception_if_reply_to_id_doesnot_exist( def test_send_one_off_notification_should_throw_exception_if_reply_to_id_doesnot_exist(
@@ -481,7 +481,7 @@ def test_send_one_off_notification_should_throw_exception_if_sms_sender_id_doesn
sample_template sample_template
): ):
data = { data = {
'to': '07700 900 001', 'to': '2028675000',
'template_id': str(sample_template.id), 'template_id': str(sample_template.id),
'sender_id': str(uuid.uuid4()), 'sender_id': str(uuid.uuid4()),
'created_by': str(sample_template.service.created_by_id) 'created_by': str(sample_template.service.created_by_id)
+3 -3
View File
@@ -204,7 +204,7 @@ def test_get_live_services_data(sample_user, admin_request):
{ {
'consent_to_research': None, 'consent_to_research': None,
'contact_email': 'notify@digital.cabinet-office.gov.uk', 'contact_email': 'notify@digital.cabinet-office.gov.uk',
'contact_mobile': '+447700900986', 'contact_mobile': '+12028675309',
'contact_name': 'Test User', 'contact_name': 'Test User',
'email_totals': 1, 'email_totals': 1,
'email_volume_intent': None, 'email_volume_intent': None,
@@ -222,7 +222,7 @@ def test_get_live_services_data(sample_user, admin_request):
{ {
'consent_to_research': None, 'consent_to_research': None,
'contact_email': 'notify@digital.cabinet-office.gov.uk', 'contact_email': 'notify@digital.cabinet-office.gov.uk',
'contact_mobile': '+447700900986', 'contact_mobile': '+12028675309',
'contact_name': 'Test User', 'contact_name': 'Test User',
'email_totals': 0, 'email_totals': 0,
'email_volume_intent': None, 'email_volume_intent': None,
@@ -2474,7 +2474,7 @@ def test_send_one_off_notification(sample_service, admin_request, mocker):
service_id=sample_service.id, service_id=sample_service.id,
_data={ _data={
'template_id': str(template.id), 'template_id': str(template.id),
'to': '07700900001', 'to': '2028675309',
'created_by': str(sample_service.created_by_id) 'created_by': str(sample_service.created_by_id)
}, },
_expected_status=201 _expected_status=201
+6 -6
View File
@@ -22,8 +22,8 @@ def test_get_guest_list_returns_data(client, sample_service_guest_list):
def test_get_guest_list_separates_emails_and_phones(client, sample_service): def test_get_guest_list_separates_emails_and_phones(client, sample_service):
dao_add_and_commit_guest_list_contacts([ dao_add_and_commit_guest_list_contacts([
ServiceGuestList.from_string(sample_service.id, EMAIL_TYPE, 'service@example.com'), ServiceGuestList.from_string(sample_service.id, EMAIL_TYPE, 'service@example.com'),
ServiceGuestList.from_string(sample_service.id, MOBILE_TYPE, '07123456789'), ServiceGuestList.from_string(sample_service.id, MOBILE_TYPE, '2028675309'),
ServiceGuestList.from_string(sample_service.id, MOBILE_TYPE, '+1800-555-555'), ServiceGuestList.from_string(sample_service.id, MOBILE_TYPE, '+1800-555-5555'),
]) ])
response = client.get( response = client.get(
@@ -32,7 +32,7 @@ def test_get_guest_list_separates_emails_and_phones(client, sample_service):
assert response.status_code == 200 assert response.status_code == 200
json_resp = json.loads(response.get_data(as_text=True)) json_resp = json.loads(response.get_data(as_text=True))
assert json_resp['email_addresses'] == ['service@example.com'] assert json_resp['email_addresses'] == ['service@example.com']
assert sorted(json_resp['phone_numbers']) == sorted(['+1800-555-555', '07123456789']) assert sorted(json_resp['phone_numbers']) == sorted(['+1800-555-5555', '2028675309'])
def test_get_guest_list_404s_with_unknown_service_id(client): def test_get_guest_list_404s_with_unknown_service_id(client):
@@ -57,7 +57,7 @@ def test_get_guest_list_returns_no_data(client, sample_service):
def test_update_guest_list_replaces_old_guest_list(client, sample_service_guest_list): def test_update_guest_list_replaces_old_guest_list(client, sample_service_guest_list):
data = { data = {
'email_addresses': ['foo@bar.com'], 'email_addresses': ['foo@bar.com'],
'phone_numbers': ['07123456789'] 'phone_numbers': ['2028765309']
} }
response = client.put( response = client.put(
@@ -69,7 +69,7 @@ def test_update_guest_list_replaces_old_guest_list(client, sample_service_guest_
assert response.status_code == 204 assert response.status_code == 204
guest_list = ServiceGuestList.query.order_by(ServiceGuestList.recipient).all() guest_list = ServiceGuestList.query.order_by(ServiceGuestList.recipient).all()
assert len(guest_list) == 2 assert len(guest_list) == 2
assert guest_list[0].recipient == '07123456789' assert guest_list[0].recipient == '2028765309'
assert guest_list[1].recipient == 'foo@bar.com' assert guest_list[1].recipient == 'foo@bar.com'
@@ -77,7 +77,7 @@ def test_update_guest_list_doesnt_remove_old_guest_list_if_error(client, sample_
data = { data = {
'email_addresses': [''], 'email_addresses': [''],
'phone_numbers': ['07123456789'] 'phone_numbers': ['2028675309']
} }
response = client.put( response = client.put(
+1 -1
View File
@@ -19,7 +19,7 @@ def test_create_test_user_command(notify_db_session, notify_api):
notify_api.test_cli_runner().invoke( notify_api.test_cli_runner().invoke(
create_test_user, [ create_test_user, [
'--email', 'somebody@fake.gov', '--email', 'somebody@fake.gov',
'--mobile_number', '555-555-5555', '--mobile_number', '202-555-5555',
'--password', 'correct horse battery staple', '--password', 'correct horse battery staple',
'--name', 'Fake Personson', '--name', 'Fake Personson',
# '--auth_type', 'sms_auth', # this is the default # '--auth_type', 'sms_auth', # this is the default
+3 -3
View File
@@ -32,8 +32,8 @@ from tests.app.db import (
@pytest.mark.parametrize('mobile_number', [ @pytest.mark.parametrize('mobile_number', [
'5558675309', '2348675309',
'+15558675309' '+12348675309'
]) ])
def test_should_build_service_guest_list_from_mobile_number(mobile_number): def test_should_build_service_guest_list_from_mobile_number(mobile_number):
service_guest_list = ServiceGuestList.from_string('service_id', MOBILE_TYPE, mobile_number) service_guest_list = ServiceGuestList.from_string('service_id', MOBILE_TYPE, mobile_number)
@@ -93,7 +93,7 @@ def test_status_conversion(initial_statuses, expected_statuses):
@freeze_time("2016-01-01 11:09:00.000000") @freeze_time("2016-01-01 11:09:00.000000")
@pytest.mark.parametrize('template_type, recipient', [ @pytest.mark.parametrize('template_type, recipient', [
('sms', '+15558675309'), ('sms', '+12028675309'),
('email', 'foo@bar.com'), ('email', 'foo@bar.com'),
]) ])
def test_notification_for_csv_returns_correct_type(sample_service, template_type, recipient): def test_notification_for_csv_returns_correct_type(sample_service, template_type, recipient):
+10 -10
View File
@@ -107,7 +107,7 @@ def test_post_user(admin_request, notify_db_session):
"name": "Test User", "name": "Test User",
"email_address": "user@digital.cabinet-office.gov.uk", "email_address": "user@digital.cabinet-office.gov.uk",
"password": "password", "password": "password",
"mobile_number": "+447700900986", "mobile_number": "+12028675309",
"logged_in_at": None, "logged_in_at": None,
"state": "active", "state": "active",
"failed_login_count": 0, "failed_login_count": 0,
@@ -130,7 +130,7 @@ def test_post_user_without_auth_type(admin_request, notify_db_session):
"name": "Test User", "name": "Test User",
"email_address": "user@digital.cabinet-office.gov.uk", "email_address": "user@digital.cabinet-office.gov.uk",
"password": "password", "password": "password",
"mobile_number": "+447700900986", "mobile_number": "+12028675309",
"permissions": {}, "permissions": {},
} }
@@ -149,7 +149,7 @@ def test_post_user_missing_attribute_email(admin_request, notify_db_session):
data = { data = {
"name": "Test User", "name": "Test User",
"password": "password", "password": "password",
"mobile_number": "+447700900986", "mobile_number": "+12028675309",
"logged_in_at": None, "logged_in_at": None,
"state": "active", "state": "active",
"failed_login_count": 0, "failed_login_count": 0,
@@ -169,7 +169,7 @@ def test_create_user_missing_attribute_password(admin_request, notify_db_session
data = { data = {
"name": "Test User", "name": "Test User",
"email_address": "user@digital.cabinet-office.gov.uk", "email_address": "user@digital.cabinet-office.gov.uk",
"mobile_number": "+447700900986", "mobile_number": "+12028675309",
"logged_in_at": None, "logged_in_at": None,
"state": "active", "state": "active",
"failed_login_count": 0, "failed_login_count": 0,
@@ -224,7 +224,7 @@ def test_cannot_create_user_with_empty_strings(admin_request, notify_db_session)
) )
assert resp['message'] == { assert resp['message'] == {
'email_address': ['Not a valid email address'], 'email_address': ['Not a valid email address'],
'mobile_number': ['Invalid phone number: Not enough digits'], 'mobile_number': ['Invalid phone number: The string supplied did not seem to be a phone number.'],
'name': ['Invalid name'] 'name': ['Invalid name']
} }
@@ -883,7 +883,8 @@ def test_cannot_update_user_with_mobile_number_as_empty_string(admin_request, sa
_data={'mobile_number': ''}, _data={'mobile_number': ''},
_expected_status=400 _expected_status=400
) )
assert resp['message']['mobile_number'] == ['Invalid phone number: Not enough digits'] assert resp['message']['mobile_number'] == [
'Invalid phone number: The string supplied did not seem to be a phone number.']
def test_cannot_update_user_password_using_attributes_method(admin_request, sample_user): def test_cannot_update_user_password_using_attributes_method(admin_request, sample_user):
@@ -1100,10 +1101,9 @@ def test_search_for_users_by_email_handles_incorrect_data_format(notify_db_sessi
@pytest.mark.parametrize('number, expected_reply_to', @pytest.mark.parametrize('number, expected_reply_to',
[ [
("1-403-123-4567", "notify_international_sender"), ("403-123-4567", "Notify"),
("27 123 4569 2312", "notify_international_sender"), ("+30 123 4567 7890", "Notify"),
("30 123 4567 7890", "Notify"), ("+27 123 4569 2312", "notify_international_sender"),
("+20 123 4567 7890", "Notify"),
]) ])
def test_get_sms_reply_to_for_notify_service(team_member_mobile_edit_template, number, expected_reply_to): def test_get_sms_reply_to_for_notify_service(team_member_mobile_edit_template, number, expected_reply_to):
# need to import locally to avoid db session errors, # need to import locally to avoid db session errors,
+1 -1
View File
@@ -522,7 +522,7 @@ def test_user_verify_email_code_fails_if_code_already_used(admin_request, sample
def test_send_user_2fa_code_sends_from_number_for_international_numbers( def test_send_user_2fa_code_sends_from_number_for_international_numbers(
client, sample_user, mocker, sms_code_template client, sample_user, mocker, sms_code_template
): ):
sample_user.mobile_number = "601117224412" sample_user.mobile_number = "+601117224412"
auth_header = create_admin_authorization_header() auth_header = create_admin_authorization_header()
mocker.patch('app.user.rest.create_secret_code', return_value='11111') mocker.patch('app.user.rest.create_secret_code', return_value='11111')
mocker.patch('app.user.rest.send_notification_to_queue') mocker.patch('app.user.rest.send_notification_to_queue')
@@ -102,11 +102,11 @@ def test_get_notifications_request_invalid_statuses_and_template_types():
.format(invalid_template_type) in error_messages .format(invalid_template_type) in error_messages
valid_json = {"phone_number": "07515111111", valid_json = {"phone_number": "2028675309",
"template_id": str(uuid.uuid4()) "template_id": str(uuid.uuid4())
} }
valid_json_with_optionals = { valid_json_with_optionals = {
"phone_number": "07515111111", "phone_number": "2028675309",
"template_id": str(uuid.uuid4()), "template_id": str(uuid.uuid4()),
"reference": "reference from caller", "reference": "reference from caller",
"personalisation": {"key": "value"} "personalisation": {"key": "value"}
@@ -130,7 +130,7 @@ def test_post_sms_schema_is_valid(input):
def test_post_sms_json_schema_bad_uuid(template_id): def test_post_sms_json_schema_bad_uuid(template_id):
j = { j = {
"template_id": template_id, "template_id": template_id,
"phone_number": "07515111111" "phone_number": "2028675309"
} }
with pytest.raises(ValidationError) as e: with pytest.raises(ValidationError) as e:
validate(j, post_sms_request_schema) validate(j, post_sms_request_schema)
@@ -158,7 +158,7 @@ def test_post_sms_json_schema_bad_uuid_and_missing_phone_number():
def test_post_sms_schema_with_personalisation_that_is_not_a_dict(): def test_post_sms_schema_with_personalisation_that_is_not_a_dict():
j = { j = {
"phone_number": "07515111111", "phone_number": "2028675309",
"template_id": str(uuid.uuid4()), "template_id": str(uuid.uuid4()),
"reference": "reference from caller", "reference": "reference from caller",
"personalisation": "not_a_dict" "personalisation": "not_a_dict"
@@ -174,9 +174,9 @@ def test_post_sms_schema_with_personalisation_that_is_not_a_dict():
@pytest.mark.parametrize('invalid_phone_number, err_msg', [ @pytest.mark.parametrize('invalid_phone_number, err_msg', [
('08515111111', 'phone_number Not a UK mobile number'), ('08515111111', 'phone_number Phone number is not possible'),
('07515111*11', 'phone_number Must not contain letters or symbols'), ('07515111*11', 'phone_number Not enough digits'),
('notaphoneumber', 'phone_number Must not contain letters or symbols'), ('notaphoneumber', 'phone_number The string supplied did not seem to be a phone number.'),
(7700900001, 'phone_number 7700900001 is not of type string'), (7700900001, 'phone_number 7700900001 is not of type string'),
(None, 'phone_number None is not of type string'), (None, 'phone_number None is not of type string'),
([], 'phone_number [] is not of type string'), ([], 'phone_number [] is not of type string'),
@@ -194,13 +194,13 @@ def test_post_sms_request_schema_invalid_phone_number(invalid_phone_number, err_
def test_post_sms_request_schema_invalid_phone_number_and_missing_template(): def test_post_sms_request_schema_invalid_phone_number_and_missing_template():
j = {"phone_number": '08515111111', j = {"phone_number": '5558675309',
} }
with pytest.raises(ValidationError) as e: with pytest.raises(ValidationError) as e:
validate(j, post_sms_request_schema) validate(j, post_sms_request_schema)
errors = json.loads(str(e.value)).get('errors') errors = json.loads(str(e.value)).get('errors')
assert len(errors) == 2 assert len(errors) == 2
assert {"error": "ValidationError", "message": "phone_number Not a UK mobile number"} in errors assert {"error": "ValidationError", "message": "phone_number Phone number range is not in use"} in errors
assert {"error": "ValidationError", "message": "template_id is a required property"} in errors assert {"error": "ValidationError", "message": "template_id is a required property"} in errors
@@ -269,7 +269,7 @@ def test_post_schema_valid_scheduled_for(schema):
if schema == post_email_request_schema: if schema == post_email_request_schema:
j.update({"email_address": "joe@gmail.com"}) j.update({"email_address": "joe@gmail.com"})
else: else:
j.update({"phone_number": "07515111111"}) j.update({"phone_number": "2028675309"})
assert validate(j, schema) == j assert validate(j, schema) == j
@@ -286,7 +286,7 @@ def test_post_email_schema_invalid_scheduled_for(invalid_datetime, schema):
if schema == post_email_request_schema: if schema == post_email_request_schema:
j.update({"email_address": "joe@gmail.com"}) j.update({"email_address": "joe@gmail.com"})
else: else:
j.update({"phone_number": "07515111111"}) j.update({"phone_number": "2028675309"})
with pytest.raises(ValidationError) as e: with pytest.raises(ValidationError) as e:
validate(j, schema) validate(j, schema)
error = json.loads(str(e.value)) error = json.loads(str(e.value))
@@ -299,7 +299,7 @@ def test_post_email_schema_invalid_scheduled_for(invalid_datetime, schema):
@freeze_time("2017-05-12 13:00:00") @freeze_time("2017-05-12 13:00:00")
def test_scheduled_for_raises_validation_error_when_in_the_past(): def test_scheduled_for_raises_validation_error_when_in_the_past():
j = {"phone_number": "07515111111", j = {"phone_number": "2028675309",
"template_id": str(uuid.uuid4()), "template_id": str(uuid.uuid4()),
"scheduled_for": "2017-05-12 10:00"} "scheduled_for": "2017-05-12 10:00"}
with pytest.raises(ValidationError) as e: with pytest.raises(ValidationError) as e:
@@ -312,7 +312,7 @@ def test_scheduled_for_raises_validation_error_when_in_the_past():
@freeze_time("2017-05-12 13:00:00") @freeze_time("2017-05-12 13:00:00")
def test_scheduled_for_raises_validation_error_when_more_than_24_hours_in_the_future(): def test_scheduled_for_raises_validation_error_when_more_than_24_hours_in_the_future():
j = {"phone_number": "07515111111", j = {"phone_number": "2028675309",
"template_id": str(uuid.uuid4()), "template_id": str(uuid.uuid4()),
"scheduled_for": "2017-05-13 14:00"} "scheduled_for": "2017-05-13 14:00"}
with pytest.raises(ValidationError) as e: with pytest.raises(ValidationError) as e:
@@ -102,7 +102,7 @@ def test_post_sms_notification_uses_inbound_number_as_sender(client, notify_db_s
def test_post_sms_notification_uses_inbound_number_reply_to_as_sender(client, notify_db_session, mocker): def test_post_sms_notification_uses_inbound_number_reply_to_as_sender(client, notify_db_session, mocker):
service = create_service_with_inbound_number(inbound_number='07123123123') service = create_service_with_inbound_number(inbound_number='2028675309')
template = create_template(service=service, content="Hello (( Name))\nYour thing is due soon") template = create_template(service=service, content="Hello (( Name))\nYour thing is due soon")
mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async') mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
@@ -124,8 +124,8 @@ def test_post_sms_notification_uses_inbound_number_reply_to_as_sender(client, no
assert len(notifications) == 1 assert len(notifications) == 1
notification_id = notifications[0].id notification_id = notifications[0].id
assert resp_json['id'] == str(notification_id) assert resp_json['id'] == str(notification_id)
assert resp_json['content']['from_number'] == '447123123123' assert resp_json['content']['from_number'] == '+12028675309'
assert notifications[0].reply_to_text == '447123123123' assert notifications[0].reply_to_text == '+12028675309'
mocked.assert_called_once_with([str(notification_id)], queue='send-sms-tasks') mocked.assert_called_once_with([str(notification_id)], queue='send-sms-tasks')
@@ -159,7 +159,7 @@ def test_post_sms_notification_returns_201_with_sms_sender_id(
def test_post_sms_notification_uses_sms_sender_id_reply_to( def test_post_sms_notification_uses_sms_sender_id_reply_to(
client, sample_template_with_placeholders, mocker client, sample_template_with_placeholders, mocker
): ):
sms_sender = create_service_sms_sender(service=sample_template_with_placeholders.service, sms_sender='07123123123') sms_sender = create_service_sms_sender(service=sample_template_with_placeholders.service, sms_sender='2028675309')
mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async') mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
data = { data = {
'phone_number': '+447700900855', 'phone_number': '+447700900855',
@@ -176,10 +176,10 @@ def test_post_sms_notification_uses_sms_sender_id_reply_to(
assert response.status_code == 201 assert response.status_code == 201
resp_json = json.loads(response.get_data(as_text=True)) resp_json = json.loads(response.get_data(as_text=True))
assert validate(resp_json, post_sms_response) == resp_json assert validate(resp_json, post_sms_response) == resp_json
assert resp_json['content']['from_number'] == '447123123123' assert resp_json['content']['from_number'] == '+12028675309'
notifications = Notification.query.all() notifications = Notification.query.all()
assert len(notifications) == 1 assert len(notifications) == 1
assert notifications[0].reply_to_text == '447123123123' assert notifications[0].reply_to_text == '+12028675309'
mocked.assert_called_once_with([resp_json['id']], queue='send-sms-tasks') mocked.assert_called_once_with([resp_json['id']], queue='send-sms-tasks')
@@ -189,7 +189,7 @@ def test_notification_reply_to_text_is_original_value_if_sender_is_changed_after
sms_sender = create_service_sms_sender(service=sample_template.service, sms_sender='123456', is_default=False) sms_sender = create_service_sms_sender(service=sample_template.service, sms_sender='123456', is_default=False)
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async') mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
data = { data = {
'phone_number': '+447700900855', 'phone_number': '+12028675309',
'template_id': str(sample_template.id), 'template_id': str(sample_template.id),
'sms_sender_id': str(sms_sender.id) 'sms_sender_id': str(sms_sender.id)
} }
@@ -220,7 +220,7 @@ def test_should_cache_template_lookups_in_memory(mocker, client, sample_template
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async') mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
data = { data = {
'phone_number': '+447700900855', 'phone_number': '2028675309',
'template_id': str(sample_template.id), 'template_id': str(sample_template.id),
} }
@@ -455,9 +455,9 @@ def test_post_email_notification_returns_201(client, sample_email_template_with_
('simulate-delivered@notifications.service.gov.uk', EMAIL_TYPE), ('simulate-delivered@notifications.service.gov.uk', EMAIL_TYPE),
('simulate-delivered-2@notifications.service.gov.uk', EMAIL_TYPE), ('simulate-delivered-2@notifications.service.gov.uk', EMAIL_TYPE),
('simulate-delivered-3@notifications.service.gov.uk', EMAIL_TYPE), ('simulate-delivered-3@notifications.service.gov.uk', EMAIL_TYPE),
('07700 900000', 'sms'), ('2028675000', 'sms'),
('07700 900111', 'sms'), ('2028675111', 'sms'),
('07700 900222', 'sms') ('2028675222', 'sms')
]) ])
def test_should_not_persist_or_send_notification_if_simulated_recipient( def test_should_not_persist_or_send_notification_if_simulated_recipient(
client, client,
@@ -493,7 +493,7 @@ def test_should_not_persist_or_send_notification_if_simulated_recipient(
@pytest.mark.parametrize("notification_type, key_send_to, send_to", @pytest.mark.parametrize("notification_type, key_send_to, send_to",
[("sms", "phone_number", "07700 900 855"), [("sms", "phone_number", "2028675309"),
("email", "email_address", "sample@email.com")]) ("email", "email_address", "sample@email.com")])
def test_send_notification_uses_priority_queue_when_template_is_marked_as_priority( def test_send_notification_uses_priority_queue_when_template_is_marked_as_priority(
client, client,
@@ -532,7 +532,7 @@ def test_send_notification_uses_priority_queue_when_template_is_marked_as_priori
@pytest.mark.parametrize( @pytest.mark.parametrize(
"notification_type, key_send_to, send_to", "notification_type, key_send_to, send_to",
[("sms", "phone_number", "07700 900 855"), ("email", "email_address", "sample@email.com")] [("sms", "phone_number", "2028675309"), ("email", "email_address", "sample@email.com")]
) )
def test_returns_a_429_limit_exceeded_if_rate_limit_exceeded( def test_returns_a_429_limit_exceeded_if_rate_limit_exceeded(
client, client,
@@ -581,7 +581,7 @@ def test_post_sms_notification_returns_400_if_not_allowed_to_send_int_sms(
template = create_template(service=service) template = create_template(service=service)
data = { data = {
'phone_number': '20-12-1234-1234', 'phone_number': '+20-12-1234-1234',
'template_id': template.id 'template_id': template.id
} }
auth_header = create_service_authorization_header(service_id=service.id) auth_header = create_service_authorization_header(service_id=service.id)
@@ -627,7 +627,7 @@ def test_post_sms_notification_with_archived_reply_to_id_returns_400(client, sam
@pytest.mark.parametrize('recipient,label,permission_type, notification_type,expected_error', [ @pytest.mark.parametrize('recipient,label,permission_type, notification_type,expected_error', [
('07700 900000', 'phone_number', 'email', 'sms', 'text messages'), ('2028675309', 'phone_number', 'email', 'sms', 'text messages'),
('someone@test.com', 'email_address', 'sms', 'email', 'emails')]) ('someone@test.com', 'email_address', 'sms', 'email', 'emails')])
def test_post_sms_notification_returns_400_if_not_allowed_to_send_notification( def test_post_sms_notification_returns_400_if_not_allowed_to_send_notification(
notify_db_session, client, recipient, label, permission_type, notification_type, expected_error notify_db_session, client, recipient, label, permission_type, notification_type, expected_error
@@ -691,7 +691,7 @@ def test_post_sms_notification_returns_201_if_allowed_to_send_int_sms(
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async') mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
data = { data = {
'phone_number': '20-12-1234-1234', 'phone_number': '+20-12-1234-1234',
'template_id': sample_template.id 'template_id': sample_template.id
} }
auth_header = create_service_authorization_header(service_id=sample_service.id) auth_header = create_service_authorization_header(service_id=sample_service.id)