fix personalisation

This commit is contained in:
Kenneth Kehl
2024-01-18 10:03:35 -08:00
parent 40f8718a61
commit 567dd390b4
9 changed files with 87 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ from botocore.exceptions import ClientError
from app.aws.s3 import (
file_exists,
get_personalisation_from_s3,
get_phone_number_from_s3,
get_s3_file,
remove_csv_object,
@@ -73,6 +74,35 @@ def test_get_phone_number_from_s3(
assert phone_number == expected_phone_number
@pytest.mark.parametrize(
"job, job_id, job_row_number, expected_personalisation",
[
("phone number\r\n+15555555555", "aaa", 0, {"phone number": "+15555555555"}),
(
"day of week,favorite color,phone number\r\nmonday,green,1.555.111.1111\r\ntuesday,red,+1 (555) 222-2222",
"bbb",
1,
{"day of week": "tuesday", "favorite color": "red", "phone number": "+1 (555) 222-2222"},
),
(
"day of week,favorite color,phone number\r\nmonday,green,1.555.111.1111\r\ntuesday,red,+1 (555) 222-2222",
"ccc",
0,
{"day of week": "monday", "favorite color": "green", "phone number": "1.555.111.1111"},
),
],
)
def test_get_personalisation_from_s3(
mocker, job, job_id, job_row_number, expected_personalisation
):
mocker.patch("app.aws.s3.redis_store")
get_job_mock = mocker.patch("app.aws.s3.get_job_from_s3")
get_job_mock.return_value = job
personalisation = get_personalisation_from_s3("service_id", job_id, job_row_number)
assert personalisation == expected_personalisation
def test_remove_csv_object(notify_api, mocker):
get_s3_mock = mocker.patch("app.aws.s3.get_s3_object")
remove_csv_object("mykey")

View File

@@ -428,7 +428,7 @@ def test_should_send_template_to_correct_sms_task_and_persist(
assert not persisted_notification.sent_at
assert not persisted_notification.sent_by
assert not persisted_notification.job_id
assert persisted_notification.personalisation == {"name": "Jo"}
assert persisted_notification.personalisation == {}
assert persisted_notification.notification_type == "sms"
mocked_deliver_sms.assert_called_once_with(
[str(persisted_notification.id)], queue="send-sms-tasks"
@@ -644,7 +644,7 @@ def test_should_use_email_template_and_persist(
assert persisted_notification.status == "created"
assert not persisted_notification.sent_by
assert persisted_notification.job_row_number == 1
assert persisted_notification.personalisation == {"name": "Jo"}
assert persisted_notification.personalisation == {}
assert persisted_notification.api_key_id is None
assert persisted_notification.key_type == KEY_TYPE_NORMAL
assert persisted_notification.notification_type == "email"
@@ -714,7 +714,7 @@ def test_should_use_email_template_subject_placeholders(
assert persisted_notification.status == "created"
assert persisted_notification.created_at >= now
assert not persisted_notification.sent_by
assert persisted_notification.personalisation == {"name": "Jo"}
assert persisted_notification.personalisation == {}
assert not persisted_notification.reference
assert persisted_notification.notification_type == "email"
provider_tasks.deliver_email.apply_async.assert_called_once_with(

View File

@@ -481,8 +481,6 @@ def test_send_user_email_code(
)
assert noti.to == sample_user.email_address
assert str(noti.template_id) == current_app.config["EMAIL_2FA_TEMPLATE_ID"]
assert noti.personalisation["name"] == "Test User"
assert noti.personalisation["url"].startswith(expected_auth_url)
deliver_email.assert_called_once_with([str(noti.id)], queue="notify-internal-tasks")

View File

@@ -986,6 +986,7 @@ def test_post_email_notification_with_archived_reply_to_id_returns_400(
assert "BadRequestError" in resp_json["errors"][0]["error"]
@pytest.mark.skip(reason="We've removed personalization from db, needs refactor if we want to support this")
@pytest.mark.parametrize(
"csv_param",
(
@@ -1041,6 +1042,7 @@ def test_post_notification_with_document_upload(
notification = Notification.query.one()
assert notification.status == NOTIFICATION_CREATED
assert notification.personalisation == {
"first_link": "abababab-link",
"second_link": "cdcdcdcd-link",