Postmark: Fix API error with template but no merge data

Fixes #223
This commit is contained in:
medmunds
2021-02-22 17:46:39 -08:00
committed by Mike Edmunds
parent fd9fdb9b03
commit 9ed5ce0213
3 changed files with 20 additions and 2 deletions

View File

@@ -25,6 +25,18 @@ Release history
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^
.. This extra heading level keeps the ToC from becoming unmanageably long .. This extra heading level keeps the ToC from becoming unmanageably long
vNext
-----
*unreleased changes*
Fixes
~~~~~
* **Postmark:** Fix Postmark API error when sending with a template that doesn't
require any merge data. (Thanks to `@Tobeyforce`_ for reporting it.)
v8.2 v8.2
----- -----
@@ -1225,8 +1237,9 @@ Features
.. _@sebbacon: https://github.com/sebbacon .. _@sebbacon: https://github.com/sebbacon
.. _@slinkymanbyday: https://github.com/slinkymanbyday .. _@slinkymanbyday: https://github.com/slinkymanbyday
.. _@swrobel: https://github.com/swrobel .. _@swrobel: https://github.com/swrobel
.. _@Thorbenl: https://github.com/Thorbenl
.. _@tcourtqtm: https://github.com/tcourtqtm .. _@tcourtqtm: https://github.com/tcourtqtm
.. _@Thorbenl: https://github.com/Thorbenl
.. _@Tobeyforce: https://github.com/Tobeyforce
.. _@varche1: https://github.com/varche1 .. _@varche1: https://github.com/varche1
.. _@vgrebenschikov: https://github.com/vgrebenschikov .. _@vgrebenschikov: https://github.com/vgrebenschikov
.. _@yourcelf: https://github.com/yourcelf .. _@yourcelf: https://github.com/yourcelf

View File

@@ -301,6 +301,10 @@ class PostmarkPayload(RequestsPayload):
except ValueError: except ValueError:
self.data["TemplateAlias"] = template_id self.data["TemplateAlias"] = template_id
# Postmark requires TemplateModel (empty ok) when TemplateId/TemplateAlias
# specified. (This may get overwritten by a real TemplateModel later.)
self.data.setdefault("TemplateModel", {})
# Subject, TextBody, and HtmlBody aren't allowed with TemplateId; # Subject, TextBody, and HtmlBody aren't allowed with TemplateId;
# delete Django default subject and body empty strings: # delete Django default subject and body empty strings:
for field in ("Subject", "TextBody", "HtmlBody"): for field in ("Subject", "TextBody", "HtmlBody"):

View File

@@ -373,7 +373,6 @@ class PostmarkBackendAnymailFeatureTests(PostmarkBackendMockAPITestCase):
# Omit subject and body (Postmark prohibits them with templates) # Omit subject and body (Postmark prohibits them with templates)
from_email='from@example.com', to=['to@example.com'], from_email='from@example.com', to=['to@example.com'],
template_id=1234567, template_id=1234567,
# Postmark doesn't support per-recipient merge_data
merge_global_data={'name': "Alice", 'group': "Developers"}, merge_global_data={'name': "Alice", 'group': "Developers"},
) )
message.send() message.send()
@@ -396,6 +395,8 @@ class PostmarkBackendAnymailFeatureTests(PostmarkBackendMockAPITestCase):
self.assert_esp_called('/email/withTemplate/') self.assert_esp_called('/email/withTemplate/')
data = self.get_api_call_json() data = self.get_api_call_json()
self.assertEqual(data['TemplateAlias'], 'welcome-message') self.assertEqual(data['TemplateAlias'], 'welcome-message')
# Postmark requires TemplateModel (can be empty) with TemplateId/TemplateAlias
self.assertEqual(data['TemplateModel'], {})
_mock_batch_response = json.dumps([{ _mock_batch_response = json.dumps([{
"ErrorCode": 0, "ErrorCode": 0,