mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-19 05:58:53 -04:00
Update tests to focus on US numbers
This commit is contained in:
@@ -83,7 +83,8 @@ def test_should_reject_bad_phone_numbers(notify_api, sample_template, mocker):
|
||||
mocked.assert_not_called()
|
||||
assert json_resp['result'] == 'error'
|
||||
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
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
data = {
|
||||
'to': '07700 900 855',
|
||||
'to': '202 867 5309',
|
||||
'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')
|
||||
|
||||
data = {
|
||||
'to': '07123123123',
|
||||
'to': '2028675300',
|
||||
'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)
|
||||
|
||||
data = {
|
||||
'to': '07811111111',
|
||||
'to': '2028675300',
|
||||
'template': sample_template.id
|
||||
}
|
||||
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', [
|
||||
'07700 900000',
|
||||
'07700 900111',
|
||||
'07700 900222'
|
||||
'2028675000',
|
||||
'2028675111',
|
||||
'+12028675222'
|
||||
])
|
||||
def test_should_not_persist_notification_or_send_sms_if_simulated_number(
|
||||
client,
|
||||
@@ -788,7 +789,7 @@ def test_should_not_persist_notification_or_send_sms_if_simulated_number(
|
||||
KEY_TYPE_NORMAL, KEY_TYPE_TEAM
|
||||
])
|
||||
@pytest.mark.parametrize('notification_type, to', [
|
||||
(SMS_TYPE, '07827992635'),
|
||||
(SMS_TYPE, '2028675300'),
|
||||
(EMAIL_TYPE, 'non_guest_list_recipient@mail.com')]
|
||||
)
|
||||
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
|
||||
])
|
||||
@pytest.mark.parametrize('notification_type, to', [
|
||||
(SMS_TYPE, '07123123123'),
|
||||
(SMS_TYPE, '2028675300'),
|
||||
(EMAIL_TYPE, 'guest_list_recipient@mail.com')]
|
||||
)
|
||||
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(
|
||||
'notification_type, template_type, to', [
|
||||
(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(
|
||||
client,
|
||||
@@ -966,7 +967,7 @@ def test_create_template_raises_invalid_request_when_content_too_large(
|
||||
|
||||
|
||||
@pytest.mark.parametrize("notification_type, send_to",
|
||||
[("sms", "07700 900 855"),
|
||||
[("sms", "2028675309"),
|
||||
("email", "sample@email.com")])
|
||||
def test_send_notification_uses_priority_queue_when_template_is_marked_as_priority(
|
||||
client,
|
||||
@@ -999,7 +1000,7 @@ def test_send_notification_uses_priority_queue_when_template_is_marked_as_priori
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"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(
|
||||
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')
|
||||
|
||||
data = {
|
||||
'to': '+(44) 7700-900 855',
|
||||
'to': '(202) 867-5309',
|
||||
'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
|
||||
notifications = Notification.query.all()
|
||||
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(
|
||||
@@ -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')
|
||||
|
||||
data = {
|
||||
'to': '20-12-1234-1234',
|
||||
'to': '+(44) 7700-900 855',
|
||||
'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'
|
||||
|
||||
|
||||
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(
|
||||
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)
|
||||
|
||||
data = {
|
||||
'to': '20-12-1234-1234',
|
||||
'to': '+(44) 7700-900 855',
|
||||
'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')
|
||||
|
||||
data = {
|
||||
'to': '+447700900986',
|
||||
'to': '+12028675309',
|
||||
'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",
|
||||
[("sms", '07700 900 855'),
|
||||
[("sms", '2028675309'),
|
||||
("email", "test@gov.uk")
|
||||
]
|
||||
)
|
||||
|
||||
@@ -50,7 +50,7 @@ def test_send_one_off_notification_calls_celery_correctly(persist_mock, celery_m
|
||||
|
||||
post_data = {
|
||||
'template_id': str(template.id),
|
||||
'to': '07700 900 001',
|
||||
'to': '202-867-5309',
|
||||
'created_by': str(service.created_by_id)
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ def test_send_one_off_notification_calls_persist_correctly_for_sms(
|
||||
|
||||
post_data = {
|
||||
'template_id': str(template.id),
|
||||
'to': '07700 900 001',
|
||||
'to': '202-867-5309',
|
||||
'personalisation': {'name': 'foo'},
|
||||
'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 = {
|
||||
'template_id': str(template.id),
|
||||
'to': '+1 555 0100',
|
||||
'to': '+(44) 7700-900 855',
|
||||
'personalisation': {'name': 'foo'},
|
||||
'created_by': str(service.created_by_id)
|
||||
}
|
||||
|
||||
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(
|
||||
@@ -223,7 +223,7 @@ def test_send_one_off_notification_honors_research_mode(notify_db_session, persi
|
||||
|
||||
post_data = {
|
||||
'template_id': str(template.id),
|
||||
'to': '07700 900 001',
|
||||
'to': '202-867-5309',
|
||||
'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 = {
|
||||
'template_id': str(template.id),
|
||||
'to': '07700 900 001',
|
||||
'to': '202-867-5309',
|
||||
'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', [
|
||||
'07700 900 001', # not in team or guest_list
|
||||
'07700900123', # in guest_list
|
||||
'+447700-900-123', # in guest_list in different format
|
||||
'2028675300', # not in team or guest_list
|
||||
'2028765309', # in guest_list
|
||||
'+1-202-876-5309', # in guest_list in different format
|
||||
])
|
||||
def test_send_one_off_notification_raises_if_cant_send_to_recipient(
|
||||
notify_db_session,
|
||||
@@ -274,7 +274,7 @@ def test_send_one_off_notification_raises_if_cant_send_to_recipient(
|
||||
service = create_service(restricted=True)
|
||||
template = create_template(service=service)
|
||||
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 = {
|
||||
@@ -331,7 +331,7 @@ def test_send_one_off_notification_fails_if_created_by_other_service(sample_temp
|
||||
|
||||
post_data = {
|
||||
'template_id': str(sample_template.id),
|
||||
'to': '07700 900 001',
|
||||
'to': '202-867-5309',
|
||||
'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)
|
||||
sms_sender = create_service_sms_sender(
|
||||
service=sample_service,
|
||||
sms_sender='07123123123',
|
||||
sms_sender='2028675309',
|
||||
is_default=False
|
||||
)
|
||||
|
||||
data = {
|
||||
'to': '07111111111',
|
||||
'to': '2028675000',
|
||||
'template_id': str(template.id),
|
||||
'created_by': str(sample_service.created_by_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
|
||||
)
|
||||
|
||||
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):
|
||||
@@ -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
|
||||
create_service_sms_sender(
|
||||
service=sample_service,
|
||||
sms_sender='07123123456',
|
||||
sms_sender='2028675309',
|
||||
is_default=True
|
||||
)
|
||||
|
||||
data = {
|
||||
'to': '07111111111',
|
||||
'to': '2028675000',
|
||||
'template_id': str(template.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
|
||||
)
|
||||
|
||||
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(
|
||||
@@ -481,7 +481,7 @@ def test_send_one_off_notification_should_throw_exception_if_sms_sender_id_doesn
|
||||
sample_template
|
||||
):
|
||||
data = {
|
||||
'to': '07700 900 001',
|
||||
'to': '2028675000',
|
||||
'template_id': str(sample_template.id),
|
||||
'sender_id': str(uuid.uuid4()),
|
||||
'created_by': str(sample_template.service.created_by_id)
|
||||
|
||||
Reference in New Issue
Block a user