From 68aa63945a38553bc894346effbfb26fc14ca9df Mon Sep 17 00:00:00 2001 From: alexjanousekGSA Date: Wed, 14 May 2025 13:41:23 -0400 Subject: [PATCH] Fixed test_rest file --- app/notifications/rest.py | 2 +- app/schemas.py | 32 +++++++++++++++------------- tests/app/notifications/test_rest.py | 4 ++-- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/app/notifications/rest.py b/app/notifications/rest.py index 7e5682027..21e4727d1 100644 --- a/app/notifications/rest.py +++ b/app/notifications/rest.py @@ -51,7 +51,7 @@ def get_notification_by_id(notification_id): notification.to = recipient notification.normalised_to = recipient - serialized = PublicNotificationSchema().dump(notification) + serialized = notification_with_personalisation_schema.dump(notification) return jsonify(data={"notification": serialized}), 200 diff --git a/app/schemas.py b/app/schemas.py index 449a0f800..42deef43b 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -639,27 +639,29 @@ class NotificationWithPersonalisationSchema(NotificationWithTemplateSchema): in_data._merged_personalisation = in_data.personalisation return in_data + @post_dump(pass_original=True) + def handle_template_merge(self, in_data, original_obj, **kwargs): + personalisation = getattr(original_obj, "_merged_personalisation", None) -@post_dump(pass_original=True) -def handle_template_merge(self, in_data, original_obj, **kwargs): - personalisation = getattr(original_obj, "_merged_personalisation", None) + in_data["template"] = in_data.pop("template_history") + template = get_template_instance(in_data["template"], personalisation) - in_data["template"] = in_data.pop("template_history") - template = get_template_instance(in_data["template"], personalisation) + in_data["body"] = template.content_with_placeholders_filled_in - in_data["body"] = template.content_with_placeholders_filled_in + if in_data["template"]["template_type"] != TemplateType.SMS: + in_data["subject"] = template.subject + in_data["content_char_count"] = None + else: + in_data["content_char_count"] = template.content_count + + in_data["template"].pop("content", None) + in_data["template"].pop("subject", None) + in_data.pop("personalisation", None) + + return in_data - if in_data["template"]["template_type"] != TemplateType.SMS: - in_data["subject"] = template.subject - in_data["content_char_count"] = None - else: - in_data["content_char_count"] = template.content_count - in_data["template"].pop("content", None) - in_data["template"].pop("subject", None) - in_data.pop("personalisation", None) - return in_data class InvitedUserSchema(BaseSchema): diff --git a/tests/app/notifications/test_rest.py b/tests/app/notifications/test_rest.py index c4c06acb5..fc3730228 100644 --- a/tests/app/notifications/test_rest.py +++ b/tests/app/notifications/test_rest.py @@ -558,8 +558,8 @@ def test_get_notification_by_id_returns_merged_template_content( def test_get_notification_by_id_returns_merged_template_content_for_email( client, sample_email_template_with_placeholders, mocker ): - mock_s3 = mocker.patch("app.notifications.rest.get_personalisation_from_s3") - mock_s3.return_value = {"name": "foo"} + # mock_s3 = mocker.patch("app.notifications.rest.get_personalisation_from_s3") + # mock_s3.return_value = {"name": "foo"} sample_notification = create_notification( sample_email_template_with_placeholders, personalisation={"name": "world"} )