Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Kehl committed Apr 12, 2024
1 parent 906609e commit 0f3cdcf
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 71 deletions.
2 changes: 2 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions test_csv_files/multiple_sms.csv
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
PhoneNumber,Name
+441234123121,chris
+441234123122,chris
+441234123123,chris
+441234123124,chris
+441234123125,chris
+441234123126,chris
+441234123127,chris
+441234123128,chris
+441234123129,chris
+441234123120,chris
+14254147755,chris
+14254147755,chris
+14254147755,chris
+14254147755,chris
+14254147755,chris
+14254147755,chris
+14254147755,chris
+14254147755,chris
+14254147755,chris
+14254147755,chris
2 changes: 1 addition & 1 deletion test_csv_files/sms.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PHONE NUMBER, IGNORE THIS COLUMN
+441234123123, nope
+14254147755, nope
30 changes: 15 additions & 15 deletions tests/app/celery/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ def test_should_process_sms_job(sample_job, mocker):
s3.get_job_and_metadata_from_s3.assert_called_once_with(
service_id=str(sample_job.service.id), job_id=str(sample_job.id)
)
assert encryption.encrypt.call_args[0][0]["to"] == "+441234123123"
assert encryption.encrypt.call_args[0][0]["to"] == "+14254147755"
assert encryption.encrypt.call_args[0][0]["template"] == str(sample_job.template.id)
assert (
encryption.encrypt.call_args[0][0]["template_version"]
== sample_job.template.version
)
assert encryption.encrypt.call_args[0][0]["personalisation"] == {
"phonenumber": "+441234123123"
"phonenumber": "+14254147755"
}
assert encryption.encrypt.call_args[0][0]["row_number"] == 0
tasks.save_sms.apply_async.assert_called_once_with(
Expand Down Expand Up @@ -279,7 +279,7 @@ def test_should_process_all_sms_job(sample_job_with_placeholdered_template, mock
service_id=str(sample_job_with_placeholdered_template.service.id),
job_id=str(sample_job_with_placeholdered_template.id),
)
assert encryption.encrypt.call_args[0][0]["to"] == "+441234123120"
assert encryption.encrypt.call_args[0][0]["to"] == "+14254147755"
assert encryption.encrypt.call_args[0][0]["template"] == str(
sample_job_with_placeholdered_template.template.id
)
Expand All @@ -288,7 +288,7 @@ def test_should_process_all_sms_job(sample_job_with_placeholdered_template, mock
== sample_job_with_placeholdered_template.template.version
) # noqa
assert encryption.encrypt.call_args[0][0]["personalisation"] == {
"phonenumber": "+441234123120",
"phonenumber": "+14254147755",
"name": "chris",
}
assert tasks.save_sms.apply_async.call_count == 10
Expand Down Expand Up @@ -397,7 +397,7 @@ def test_should_send_template_to_correct_sms_task_and_persist(
):
notification = _notification_json(
sample_template_with_placeholders,
to="+447234123123",
to="+14254147755",
personalisation={"name": "Jo"},
)

Expand Down Expand Up @@ -558,7 +558,7 @@ def test_should_not_save_email_if_restricted_service_and_invalid_email_address(
def test_should_save_sms_template_to_and_persist_with_job_id(sample_job, mocker):
notification = _notification_json(
sample_job.template,
to="+447234123123",
to="+14254147755",
job_id=sample_job.id,
row_number=2,
)
Expand Down Expand Up @@ -813,7 +813,7 @@ def test_should_use_email_template_and_persist_without_personalisation(


def test_save_sms_should_go_to_retry_queue_if_database_errors(sample_template, mocker):
notification = _notification_json(sample_template, "+447234123123")
notification = _notification_json(sample_template, "+14254147755")

expected_exception = SQLAlchemyError()

Expand Down Expand Up @@ -1017,7 +1017,7 @@ def test_send_inbound_sms_to_service_post_https_request_to_service(
inbound_sms = create_inbound_sms(
service=sample_service,
notify_number="0751421",
user_number="447700900111",
user_number="+14254147755",
provider_date=datetime(2017, 6, 20),
content="Here is some content",
)
Expand Down Expand Up @@ -1063,7 +1063,7 @@ def test_send_inbound_sms_to_service_does_not_sent_request_when_inbound_api_does
inbound_sms = create_inbound_sms(
service=sample_service,
notify_number="0751421",
user_number="447700900111",
user_number="+14254147755",
provider_date=datetime(2017, 6, 20),
content="Here is some content",
)
Expand All @@ -1084,7 +1084,7 @@ def test_send_inbound_sms_to_service_retries_if_request_returns_500(
inbound_sms = create_inbound_sms(
service=sample_service,
notify_number="0751421",
user_number="447700900111",
user_number="+14254147755",
provider_date=datetime(2017, 6, 20),
content="Here is some content",
)
Expand All @@ -1109,7 +1109,7 @@ def test_send_inbound_sms_to_service_retries_if_request_throws_unknown(
inbound_sms = create_inbound_sms(
service=sample_service,
notify_number="0751421",
user_number="447700900111",
user_number="+14254147755",
provider_date=datetime(2017, 6, 20),
content="Here is some content",
)
Expand All @@ -1134,7 +1134,7 @@ def test_send_inbound_sms_to_service_does_not_retries_if_request_returns_404(
inbound_sms = create_inbound_sms(
service=sample_service,
notify_number="0751421",
user_number="447700900111",
user_number="+14254147755",
provider_date=datetime(2017, 6, 20),
content="Here is some content",
)
Expand Down Expand Up @@ -1429,7 +1429,7 @@ def test_save_api_email_or_sms(mocker, sample_service, notification_type):
data.update({"to": "[email protected]"})
expected_queue = QueueNames.SEND_EMAIL
else:
data.update({"to": "+447700900855"})
data.update({"to": "+14254147755"})
expected_queue = QueueNames.SEND_SMS

encrypted = encryption.encrypt(data)
Expand Down Expand Up @@ -1483,7 +1483,7 @@ def test_save_api_email_dont_retry_if_notification_already_exists(
data.update({"to": "[email protected]"})
expected_queue = QueueNames.SEND_EMAIL
else:
data.update({"to": "+447700900855"})
data.update({"to": "+14254147755"})
expected_queue = QueueNames.SEND_SMS

encrypted = encryption.encrypt(data)
Expand Down Expand Up @@ -1576,7 +1576,7 @@ def test_save_tasks_use_cached_service_and_template(
NotificationType.SMS,
save_api_sms,
QueueNames.SEND_SMS,
"+447700900855",
"+14254147755",
),
(
NotificationType.EMAIL,
Expand Down
14 changes: 7 additions & 7 deletions tests/app/notifications/test_process_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_persist_notification_creates_and_save_to_db(
notification = persist_notification(
template_id=sample_template.id,
template_version=sample_template.version,
recipient="+447111111111",
recipient="+14254147755",
service=sample_template.service,
personalisation={},
notification_type=NotificationType.SMS,
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_persist_notification_throws_exception_when_missing_template(sample_api_
persist_notification(
template_id=None,
template_version=None,
recipient="+447111111111",
recipient="+14254147755",
service=sample_api_key.service,
personalisation=None,
notification_type=NotificationType.SMS,
Expand Down Expand Up @@ -178,7 +178,7 @@ def test_persist_notification_cache_is_not_incremented_on_failure_to_create_noti
persist_notification(
template_id=None,
template_version=None,
recipient="+447111111111",
recipient="+14254147755",
service=sample_api_key.service,
personalisation=None,
notification_type=NotificationType.SMS,
Expand Down Expand Up @@ -321,9 +321,9 @@ def test_simulated_recipient(notify_api, to_address, notification_type, expected
@pytest.mark.parametrize(
"recipient, expected_international, expected_prefix, expected_units",
[
("+447900900123", True, "44", 1), # UK
("+73122345678", True, "7", 1), # Russia
("+360623400400", True, "36", 1), # Hungary
# ("+447900900123", True, "44", 1), # UK
# ("+73122345678", True, "7", 1), # Russia
# ("+360623400400", True, "36", 1), # Hungary
("2028675309", False, "1", 1),
], # USA
)
Expand Down Expand Up @@ -382,7 +382,7 @@ def test_persist_notification_with_international_info_does_not_store_for_email(
@pytest.mark.parametrize(
"recipient, expected_recipient_normalised",
[
("+4407900900123", "+447900900123"),
# ("+4407900900123", "+447900900123"),
("202-867-5309", "+12028675309"),
("1 202-867-5309", "+12028675309"),
("+1 (202) 867-5309", "+12028675309"),
Expand Down
6 changes: 5 additions & 1 deletion tests/app/notifications/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_service_can_send_to_recipient_passes(key_type, notify_db_session):
"user_number, recipient_number",
[
["+12028675309", "202-867-5309"],
["+447513332413", "+44 (07513) 332413"],
# ["+447513332413", "+44 (07513) 332413"],
],
)
def test_service_can_send_to_recipient_passes_with_non_normalized_number(
Expand Down Expand Up @@ -569,6 +569,9 @@ def test_check_rate_limiting_validates_api_rate_limit_and_daily_limit(


@pytest.mark.parametrize("key_type", [KeyType.TEST, KeyType.NORMAL])
@pytest.mark.skip(
"We currently don't support international numbers, our validation fails before here"
)
def test_validate_and_format_recipient_fails_when_international_number_and_service_does_not_allow_int_sms(
key_type,
notify_db_session,
Expand All @@ -588,6 +591,7 @@ def test_validate_and_format_recipient_fails_when_international_number_and_servi


@pytest.mark.parametrize("key_type", [KeyType.TEST, KeyType.NORMAL])
@pytest.mark.skip("We currently don't support international numbers")
def test_validate_and_format_recipient_succeeds_with_international_numbers_if_service_does_allow_int_sms(
key_type, sample_service_full_permissions
):
Expand Down
8 changes: 5 additions & 3 deletions tests/app/service/send_notification/test_send_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_should_reject_bad_phone_numbers(notify_api, sample_template, mocker):
@pytest.mark.parametrize(
"template_type, to",
[
(TemplateType.SMS, "+447700900855"),
(TemplateType.SMS, "+14254147755"),
(TemplateType.EMAIL, "[email protected]"),
],
)
Expand Down Expand Up @@ -257,7 +257,7 @@ def test_should_not_send_notification_for_archived_template(
sample_template.archived = True
dao_update_template(sample_template)
json_data = json.dumps(
{"to": "+447700900855", "template": sample_template.id}
{"to": "+14254147755", "template": sample_template.id}
)
auth_header = create_service_authorization_header(
service_id=sample_template.service_id
Expand All @@ -276,7 +276,7 @@ def test_should_not_send_notification_for_archived_template(
@pytest.mark.parametrize(
"template_type, to",
[
(TemplateType.SMS, "+447700900855"),
(TemplateType.SMS, "+16618675309"),
(TemplateType.EMAIL, "[email protected]"),
],
)
Expand Down Expand Up @@ -1230,6 +1230,7 @@ def test_should_allow_store_original_number_on_sms_notification(
assert "1" == notifications[0].to


@pytest.mark.skip("We don't support international at moment")
def test_should_not_allow_sending_to_international_number_without_international_permission(
client, sample_template, mocker
):
Expand All @@ -1254,6 +1255,7 @@ def test_should_not_allow_sending_to_international_number_without_international_
assert error_json["message"] == "Cannot send to international mobile numbers"


@pytest.mark.skip("We don't support international at the moment")
def test_should_allow_sending_to_international_number_with_international_permission(
client, sample_service_full_permissions, mocker
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def test_send_one_off_notification_calls_persist_correctly_for_sms(
)


@pytest.mark.skip("We currently don't support international")
def test_send_one_off_notification_calls_persist_correctly_for_international_sms(
persist_mock, celery_mock, notify_db_session
):
Expand Down
30 changes: 20 additions & 10 deletions tests/app/service/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,20 @@ def test_get_service_list(client, service_factory):
response = client.get("/service", headers=[auth_header])
assert response.status_code == 200
json_resp = json.loads(response.get_data(as_text=True))
assert len(json_resp["data"]) == 3
assert json_resp["data"][0]["name"] == "one"
assert json_resp["data"][1]["name"] == "two"
assert json_resp["data"][2]["name"] == "three"

found_service_one = False
found_service_two = False
found_service_three = False
for item in json_resp["data"]:
if item["name"] == "one":
found_service_one = True
elif item["name"] == "two":
found_service_two = True
elif item["name"] == "three":
found_service_three = True
assert found_service_one is True
assert found_service_two is True
assert found_service_three is True


def test_get_service_list_with_only_active_flag(client, service_factory):
Expand Down Expand Up @@ -1262,7 +1272,7 @@ def test_add_existing_user_to_another_service_with_all_permissions(
name="Invited User",
email_address="[email protected]",
password="password",
mobile_number="+4477123456",
mobile_number="+14254147755",
)
# they must exist in db first
save_model_user(user_to_add, validated_email_access=True)
Expand Down Expand Up @@ -1332,7 +1342,7 @@ def test_add_existing_user_to_another_service_with_send_permissions(
name="Invited User",
email_address="[email protected]",
password="password",
mobile_number="+4477123456",
mobile_number="+14254147755",
)
save_model_user(user_to_add, validated_email_access=True)

Expand Down Expand Up @@ -1382,7 +1392,7 @@ def test_add_existing_user_to_another_service_with_manage_permissions(
name="Invited User",
email_address="[email protected]",
password="password",
mobile_number="+4477123456",
mobile_number="+14254147755",
)
save_model_user(user_to_add, validated_email_access=True)

Expand Down Expand Up @@ -1433,7 +1443,7 @@ def test_add_existing_user_to_another_service_with_folder_permissions(
name="Invited User",
email_address="[email protected]",
password="password",
mobile_number="+4477123456",
mobile_number="+14254147755",
)
save_model_user(user_to_add, validated_email_access=True)

Expand Down Expand Up @@ -1474,7 +1484,7 @@ def test_add_existing_user_to_another_service_with_manage_api_keys(
name="Invited User",
email_address="[email protected]",
password="password",
mobile_number="+4477123456",
mobile_number="+14254147755",
)
save_model_user(user_to_add, validated_email_access=True)

Expand Down Expand Up @@ -1514,7 +1524,7 @@ def test_add_existing_user_to_non_existing_service_returns404(
name="Invited User",
email_address="[email protected]",
password="password",
mobile_number="+4477123456",
mobile_number="+14254147755",
)
save_model_user(user_to_add, validated_email_access=True)

Expand Down
2 changes: 1 addition & 1 deletion tests/app/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
)


@pytest.mark.parametrize("mobile_number", ["+447700900855", "+12348675309"])
@pytest.mark.parametrize("mobile_number", ["+14254147755", "+12348675309"])
def test_should_build_service_guest_list_from_mobile_number(mobile_number):
service_guest_list = ServiceGuestList.from_string(
"service_id",
Expand Down
2 changes: 1 addition & 1 deletion tests/app/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_notification_schema_has_correct_status(sample_notification, schema_name
[
("name", "New User"),
("email_address", "[email protected]"),
("mobile_number", "+4407700900460"),
("mobile_number", "+14254147755"),
],
)
def test_user_update_schema_accepts_valid_attribute_pairs(user_attribute, user_value):
Expand Down
Loading

0 comments on commit 0f3cdcf

Please sign in to comment.