From 5c5f926e326941d45daf8277ebdf89081aad5060 Mon Sep 17 00:00:00 2001 From: Arondit Date: Mon, 4 Mar 2024 18:54:28 +0300 Subject: [PATCH] Unisender Go: Fix integrations bcc test and add unit test for cc/bcc --- tests/test_unisender_go_integration.py | 5 ++- tests/test_unisender_go_payload.py | 42 ++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/tests/test_unisender_go_integration.py b/tests/test_unisender_go_integration.py index 784511e6..863172e4 100644 --- a/tests/test_unisender_go_integration.py +++ b/tests/test_unisender_go_integration.py @@ -84,7 +84,10 @@ def test_all_options(self): ), to=["test+to1@anymail.dev", '"Recipient 2, OK?" '], cc=["test+cc1@anymail.dev", '"Copy 2, OK?" '], - bcc=["test+bcc1@anymail.dev", '"BCC 2, OK?" '], + bcc=[ + f"test+bcc1@{ANYMAIL_TEST_UNISENDER_GO_DOMAIN}", + f'"BCC 2, OK?" ', + ], # Unisender Go only supports a single reply-to: reply_to=['"Reply, with comma (and parens)" '], headers={"X-Anymail-Test": "value", "X-Anymail-Count": 3}, diff --git a/tests/test_unisender_go_payload.py b/tests/test_unisender_go_payload.py index 5332f439..c32d3253 100644 --- a/tests/test_unisender_go_payload.py +++ b/tests/test_unisender_go_payload.py @@ -3,6 +3,7 @@ from email.headerregistry import Address from django.test import SimpleTestCase, override_settings, tag +from requests.structures import CaseInsensitiveDict from anymail.backends.unisender_go import EmailBackend, UnisenderGoPayload from anymail.message import AnymailMessage @@ -64,6 +65,47 @@ def test_unisender_go_payload__full(self): self.assertEqual(payload.data, expected_payload) + def test_unisender_go_payload__cc_bcc(self): + cc_to_email = "receiver_cc@test.test" + bcc_to_email = "receiver_bcc@test.test" + email = AnymailMessage( + template_id=TEMPLATE_ID, + subject=SUBJECT, + merge_global_data=GLOBAL_DATA, + from_email=f"{FROM_NAME} <{FROM_EMAIL}>", + to=[ + str(Address(display_name=TO_NAME, addr_spec=TO_EMAIL)), + str(Address(display_name=OTHER_TO_NAME, addr_spec=OTHER_TO_EMAIL)), + ], + cc=[cc_to_email], + bcc=[bcc_to_email], + ) + backend = EmailBackend() + + payload = UnisenderGoPayload( + message=email, backend=backend, defaults=backend.send_defaults + ) + expected_headers = { + "To": f"{TO_NAME} <{TO_EMAIL}>, {OTHER_TO_NAME} <{OTHER_TO_EMAIL}>", + "CC": cc_to_email, + } + expected_headers = CaseInsensitiveDict(expected_headers) + expected_recipients = [ + { + "email": TO_EMAIL, + "substitutions": {"to_name": TO_NAME}, + }, + { + "email": OTHER_TO_EMAIL, + "substitutions": {"to_name": OTHER_TO_NAME}, + }, + {"email": cc_to_email}, + {"email": bcc_to_email}, + ] + + self.assertEqual(payload.data["headers"], expected_headers) + self.assertCountEqual(payload.data["recipients"], expected_recipients) + def test_unisender_go_payload__parse_from__with_name(self): email = AnymailMessage( subject=SUBJECT,