Update tests to focus on US numbers

This commit is contained in:
Ryan Ahearn
2023-01-04 16:35:25 -05:00
parent abc7b09d0d
commit 82df01653f
21 changed files with 172 additions and 201 deletions

View File

@@ -122,7 +122,7 @@ def test_persist_notification_with_optionals(sample_job, sample_api_key):
persist_notification(
template_id=sample_job.template.id,
template_version=sample_job.template.version,
recipient='+447111111111',
recipient='+12028675309',
service=sample_job.service,
personalisation=None,
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.reference is None
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.created_by_id == sample_job.created_by_id
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", [
("+447700900000", "sms", True),
("+447700900111", "sms", True),
("+447700900222", "sms", True),
("07700900000", "sms", True),
("7700900111", "sms", True),
("+12028675000", "sms", True),
("+12028675111", "sms", True),
("+12028675222", "sms", True),
("2028675000", "sms", True),
("2028675111", "sms", True),
("simulate-delivered@notifications.service.gov.uk", "email", True),
("simulate-delivered-2@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)
])
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'
)
SIMULATED_SMS_NUMBERS = ('+447700900000', '+447700900111', '+447700900222')
SIMULATED_SMS_NUMBERS = ('+12028675000', '+12028675111', '+12028675222')
"""
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', [
('7900900123', False, '44', 1), # UK
('+447900900123', False, '44', 1), # UK
('07700910222', True, '44', 1), # UK (Jersey)
('07700900222', False, '44', 1), # TV number
('73122345678', True, '7', 1), # Russia
('360623400400', True, '36', 3)] # Hungary
('+447900900123', True, '44', 1), # UK
('+73122345678', True, '7', 1), # Russia
('+360623400400', True, '36', 1), # Hungary
('2028675309', False, '1', 1)] # USA
)
def test_persist_notification_with_international_info_stores_correct_info(
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', [
('7900900123', '447900900123'),
('+447900 900 123', '447900900123'),
(' 07700900222', '447700900222'),
('07700900222', '447700900222'),
(' 73122345678', '73122345678'),
('360623400400', '360623400400'),
('-077-00900222-', '447700900222'),
('(360623(400400)', '360623400400')
('+4407900900123', '+447900900123'),
('202-867-5309', '+12028675309'),
('1 202-867-5309', '+12028675309'),
('+1 (202) 867-5309', '+12028675309'),
('(202) 867-5309', '+12028675309'),
('2028675309', '+12028675309')
])
def test_persist_sms_notification_stores_normalised_number(
sample_job,

View File

@@ -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")
prom_counter_labels_mock = mocker.patch('app.notifications.receive_notifications.INBOUND_SMS_COUNTER.labels')
data = {
"originationNumber": "+15558675309",
"originationNumber": "+12028675309",
"destinationNumber": sample_service_full_permissions.get_inbound_number(),
"messageKeyword": "JOIN",
"messageBody": "EXAMPLE",
@@ -241,9 +241,9 @@ def test_receive_notification_error_if_not_single_matching_service(client, notif
@pytest.mark.parametrize(
'number, expected',
[
('15558675309', '5558675309'),
('+15558675309', '5558675309'),
('5558675309', '5558675309'),
('12028675309', '2028675309'),
('+12028675309', '2028675309'),
('2028675309', '2028675309'),
('15111111111', '5111111111')
]
)

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', [
['0048601234567', '+486 012 34567'],
['07513332413', '(07513) 332413'],
['+12028675309', '202-867-5309'],
['+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
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', [
['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
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",
'team',
sample_service) is None
create_service_guest_list(sample_service, mobile_number='07513332413')
assert service_can_send_to_recipient('07513332413',
create_service_guest_list(sample_service, mobile_number='2028675309')
assert service_can_send_to_recipient('2028675309',
'team',
sample_service) is None
@pytest.mark.parametrize('recipient', [
{"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(
notify_db_session,
@@ -234,7 +234,7 @@ def test_service_can_send_to_recipient_fails_when_ignoring_guest_list(
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',
[('team', 'Cant send to this recipient using a team-only API key'),
('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_model = SerialisedService.from_id(service.id)
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.message == 'Cannot send to international mobile numbers'
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(
key_type, sample_service_full_permissions):
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)
assert result == '201212341234'
result = validate_and_format_recipient('+4407513332413', key_type, service_model, SMS_TYPE)
assert result == '+447513332413'
def test_validate_and_format_recipient_fails_when_no_recipient():