mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Postmark: Use new RecordType field to identify event types
Simplify Postmark tracking webhook code by using new "RecordType" field introduced with Postmark "modular webhooks". (Rather than looking for fields that are probably only in certain events.) Also issue configuration error on inbound url installed as tracking webhook (and vice versa).
This commit is contained in:
@@ -3,6 +3,7 @@ from base64 import b64encode
|
||||
|
||||
from mock import ANY
|
||||
|
||||
from anymail.exceptions import AnymailConfigurationError
|
||||
from anymail.inbound import AnymailInboundMessage
|
||||
from anymail.signals import AnymailInboundEvent
|
||||
from anymail.webhooks.postmark import PostmarkInboundWebhookView
|
||||
@@ -222,3 +223,9 @@ class PostmarkInboundTestCase(WebhookTestCase):
|
||||
"Value": "Pass (malicious sender added this) identity=mailfrom; envelope-from=spoofed@example.org"
|
||||
}]}))
|
||||
self.assertIsNone(self.get_kwargs(self.inbound_handler)['event'].message.envelope_sender)
|
||||
|
||||
def test_misconfigured_tracking(self):
|
||||
errmsg = "You seem to have set Postmark's *Delivery* webhook to Anymail's Postmark *inbound* webhook URL."
|
||||
with self.assertRaisesMessage(AnymailConfigurationError, errmsg):
|
||||
self.client.post('/anymail/postmark/inbound/', content_type='application/json',
|
||||
data=json.dumps({"RecordType": "Delivery"}))
|
||||
|
||||
@@ -4,6 +4,7 @@ from datetime import datetime
|
||||
from django.utils.timezone import get_fixed_timezone, utc
|
||||
from mock import ANY
|
||||
|
||||
from anymail.exceptions import AnymailConfigurationError
|
||||
from anymail.signals import AnymailTrackingEvent
|
||||
from anymail.webhooks.postmark import PostmarkTrackingWebhookView
|
||||
from .webhook_cases import WebhookBasicAuthTestsMixin, WebhookTestCase
|
||||
@@ -202,3 +203,13 @@ class PostmarkDeliveryTestCase(WebhookTestCase):
|
||||
self.assertEqual(event.reject_reason, "spam")
|
||||
self.assertEqual(event.description, "")
|
||||
self.assertEqual(event.mta_response, "Test spam complaint details")
|
||||
|
||||
def test_misconfigured_inbound(self):
|
||||
errmsg = "You seem to have set Postmark's *inbound* webhook to Anymail's Postmark *tracking* webhook URL."
|
||||
with self.assertRaisesMessage(AnymailConfigurationError, errmsg):
|
||||
self.client.post('/anymail/postmark/tracking/', content_type='application/json',
|
||||
data=json.dumps({"FromFull": {"Email": "from@example.org"}}))
|
||||
|
||||
with self.assertRaisesMessage(AnymailConfigurationError, errmsg):
|
||||
self.client.post('/anymail/postmark/tracking/', content_type='application/json',
|
||||
data=json.dumps({"RecordType": "Inbound"}))
|
||||
|
||||
Reference in New Issue
Block a user