From be3a9802a3f99caee48980ec8f07452e354d65c9 Mon Sep 17 00:00:00 2001 From: "Rodrigo N. Carreras" Date: Mon, 20 May 2024 15:00:53 -0300 Subject: [PATCH] Change merge_headers to dict of dicts --- anymail/backends/amazon_ses.py | 5 ++++- tests/test_amazon_ses_backend.py | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/anymail/backends/amazon_ses.py b/anymail/backends/amazon_ses.py index 12277f88..041297ac 100644 --- a/anymail/backends/amazon_ses.py +++ b/anymail/backends/amazon_ses.py @@ -373,7 +373,10 @@ def finalize_payload(self): } if len(self.merge_headers) > 0: - entry["ReplacementHeaders"] = self.merge_headers.get(to.addr_spec, []) + entry["ReplacementHeaders"] = [ + {"Name": key, "Value": value} + for key, value in self.merge_headers.get(to.addr_spec, {}).items() + ] self.params["BulkEmailEntries"].append(entry) def parse_recipient_status(self, response): diff --git a/tests/test_amazon_ses_backend.py b/tests/test_amazon_ses_backend.py index 5a4728c2..b371e288 100644 --- a/tests/test_amazon_ses_backend.py +++ b/tests/test_amazon_ses_backend.py @@ -654,17 +654,14 @@ def test_template(self): "nobody@example.com": {"name": "Not a recipient for this message"}, }, merge_headers={ - "alice@example.com": [ - {"Name": "List-Unsubscribe", "Value": ""}, - {"List-Unsubscribe-Post": "List-Unsubscribe=One-Click"}, - ], - "nobody@example.com": [ - { - "Name": "List-Unsubscribe", - "Value": "", - }, - {"List-Unsubscribe-Post": "List-Unsubscribe=One-Click"}, - ], + "alice@example.com": { + "List-Unsubscribe": "", + "List-Unsubscribe-Post": "List-Unsubscribe=One-Click", + }, + "nobody@example.com": { + "List-Unsubscribe": "", + "List-Unsubscribe-Post": "List-Unsubscribe=One-Click", + }, }, merge_global_data={"group": "Users", "site": "ExampleCo"}, # (only works with AMAZON_SES_MESSAGE_TAG_NAME when using template): @@ -722,7 +719,10 @@ def test_template(self): bulk_entries[0]["ReplacementHeaders"], [ {"Name": "List-Unsubscribe", "Value": ""}, - {"List-Unsubscribe-Post": "List-Unsubscribe=One-Click"}, + { + "Name": "List-Unsubscribe-Post", + "Value": "List-Unsubscribe=One-Click", + }, ], ) self.assertEqual(