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

@@ -102,11 +102,11 @@ def test_get_notifications_request_invalid_statuses_and_template_types():
.format(invalid_template_type) in error_messages
valid_json = {"phone_number": "07515111111",
valid_json = {"phone_number": "2028675309",
"template_id": str(uuid.uuid4())
}
valid_json_with_optionals = {
"phone_number": "07515111111",
"phone_number": "2028675309",
"template_id": str(uuid.uuid4()),
"reference": "reference from caller",
"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):
j = {
"template_id": template_id,
"phone_number": "07515111111"
"phone_number": "2028675309"
}
with pytest.raises(ValidationError) as e:
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():
j = {
"phone_number": "07515111111",
"phone_number": "2028675309",
"template_id": str(uuid.uuid4()),
"reference": "reference from caller",
"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', [
('08515111111', 'phone_number Not a UK mobile number'),
('07515111*11', 'phone_number Must not contain letters or symbols'),
('notaphoneumber', 'phone_number Must not contain letters or symbols'),
('08515111111', 'phone_number Phone number is not possible'),
('07515111*11', 'phone_number Not enough digits'),
('notaphoneumber', 'phone_number The string supplied did not seem to be a phone number.'),
(7700900001, 'phone_number 7700900001 is not of type string'),
(None, 'phone_number None 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():
j = {"phone_number": '08515111111',
j = {"phone_number": '5558675309',
}
with pytest.raises(ValidationError) as e:
validate(j, post_sms_request_schema)
errors = json.loads(str(e.value)).get('errors')
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
@@ -269,7 +269,7 @@ def test_post_schema_valid_scheduled_for(schema):
if schema == post_email_request_schema:
j.update({"email_address": "joe@gmail.com"})
else:
j.update({"phone_number": "07515111111"})
j.update({"phone_number": "2028675309"})
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:
j.update({"email_address": "joe@gmail.com"})
else:
j.update({"phone_number": "07515111111"})
j.update({"phone_number": "2028675309"})
with pytest.raises(ValidationError) as e:
validate(j, schema)
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")
def test_scheduled_for_raises_validation_error_when_in_the_past():
j = {"phone_number": "07515111111",
j = {"phone_number": "2028675309",
"template_id": str(uuid.uuid4()),
"scheduled_for": "2017-05-12 10:00"}
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")
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()),
"scheduled_for": "2017-05-13 14:00"}
with pytest.raises(ValidationError) as e:

View File

@@ -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):
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")
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
notification_id = notifications[0].id
assert resp_json['id'] == str(notification_id)
assert resp_json['content']['from_number'] == '447123123123'
assert notifications[0].reply_to_text == '447123123123'
assert resp_json['content']['from_number'] == '+12028675309'
assert notifications[0].reply_to_text == '+12028675309'
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(
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')
data = {
'phone_number': '+447700900855',
@@ -176,10 +176,10 @@ def test_post_sms_notification_uses_sms_sender_id_reply_to(
assert response.status_code == 201
resp_json = json.loads(response.get_data(as_text=True))
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()
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')
@@ -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)
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
data = {
'phone_number': '+447700900855',
'phone_number': '+12028675309',
'template_id': str(sample_template.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')
data = {
'phone_number': '+447700900855',
'phone_number': '2028675309',
'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-2@notifications.service.gov.uk', EMAIL_TYPE),
('simulate-delivered-3@notifications.service.gov.uk', EMAIL_TYPE),
('07700 900000', 'sms'),
('07700 900111', 'sms'),
('07700 900222', 'sms')
('2028675000', 'sms'),
('2028675111', 'sms'),
('2028675222', 'sms')
])
def test_should_not_persist_or_send_notification_if_simulated_recipient(
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",
[("sms", "phone_number", "07700 900 855"),
[("sms", "phone_number", "2028675309"),
("email", "email_address", "sample@email.com")])
def test_send_notification_uses_priority_queue_when_template_is_marked_as_priority(
client,
@@ -532,7 +532,7 @@ def test_send_notification_uses_priority_queue_when_template_is_marked_as_priori
@pytest.mark.parametrize(
"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(
client,
@@ -581,7 +581,7 @@ def test_post_sms_notification_returns_400_if_not_allowed_to_send_int_sms(
template = create_template(service=service)
data = {
'phone_number': '20-12-1234-1234',
'phone_number': '+20-12-1234-1234',
'template_id': template.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', [
('07700 900000', 'phone_number', 'email', 'sms', 'text messages'),
('2028675309', 'phone_number', 'email', 'sms', 'text messages'),
('someone@test.com', 'email_address', 'sms', 'email', 'emails')])
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
@@ -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')
data = {
'phone_number': '20-12-1234-1234',
'phone_number': '+20-12-1234-1234',
'template_id': sample_template.id
}
auth_header = create_service_authorization_header(service_id=sample_service.id)