Skip to content

Commit

Permalink
Unisender Go: Fix integrations bcc test and add unit test for cc/bcc
Browse files Browse the repository at this point in the history
  • Loading branch information
Arondit committed Mar 4, 2024
1 parent 58aab53 commit 5c5f926
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tests/test_unisender_go_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ def test_all_options(self):
),
to=["[email protected]", '"Recipient 2, OK?" <[email protected]>'],
cc=["[email protected]", '"Copy 2, OK?" <[email protected]>'],
bcc=["[email protected]", '"BCC 2, OK?" <[email protected]>'],
bcc=[
f"test+bcc1@{ANYMAIL_TEST_UNISENDER_GO_DOMAIN}",
f'"BCC 2, OK?" <bcc2@{ANYMAIL_TEST_UNISENDER_GO_DOMAIN}>',
],
# Unisender Go only supports a single reply-to:
reply_to=['"Reply, with comma (and parens)" <[email protected]>'],
headers={"X-Anymail-Test": "value", "X-Anymail-Count": 3},
Expand Down
42 changes: 42 additions & 0 deletions tests/test_unisender_go_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = "[email protected]"
bcc_to_email = "[email protected]"
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,
Expand Down

0 comments on commit 5c5f926

Please sign in to comment.