mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 10:21:14 -05:00
fix personalisation
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user