diff --git a/anymail/webhooks/postmark.py b/anymail/webhooks/postmark.py index e6824b92..652947d7 100644 --- a/anymail/webhooks/postmark.py +++ b/anymail/webhooks/postmark.py @@ -1,8 +1,9 @@ import json +import warnings from django.utils.dateparse import parse_datetime -from ..exceptions import AnymailConfigurationError +from ..exceptions import AnymailConfigurationError, AnymailWarning from ..inbound import AnymailInboundMessage from ..signals import ( AnymailInboundEvent, @@ -183,6 +184,18 @@ def esp_to_anymail_event(self, esp_event): for attachment in esp_event.get("Attachments", []) ] + # Warning to the user regarding the workaround of above. + for attachment in esp_event.get("Attachments", []): + if "Data" in attachment: + warnings.warn( + "Received a test webhook attachment. " + "It is recommended to test with real inbound events. " + "See https://github.com/anymail/django-anymail/issues/304 " + "for more information.", + AnymailWarning, + ) + break + message = AnymailInboundMessage.construct( from_email=self._address(esp_event.get("FromFull")), to=", ".join([self._address(to) for to in esp_event.get("ToFull", [])]), diff --git a/tests/test_postmark_inbound.py b/tests/test_postmark_inbound.py index 47a92b22..7dd8d4b5 100644 --- a/tests/test_postmark_inbound.py +++ b/tests/test_postmark_inbound.py @@ -4,7 +4,7 @@ from django.test import tag -from anymail.exceptions import AnymailConfigurationError +from anymail.exceptions import AnymailConfigurationError, AnymailWarning from anymail.inbound import AnymailInboundMessage from anymail.signals import AnymailInboundEvent from anymail.webhooks.postmark import PostmarkInboundWebhookView @@ -178,11 +178,14 @@ def test_attachments(self): ] } - response = self.client.post( - "/anymail/postmark/inbound/", - content_type="application/json", - data=json.dumps(raw_event), - ) + with self.assertWarnsRegex( + AnymailWarning, r"Received a test webhook attachment. " + ): + response = self.client.post( + "/anymail/postmark/inbound/", + content_type="application/json", + data=json.dumps(raw_event), + ) self.assertEqual(response.status_code, 200) kwargs = self.assert_handler_called_once_with( self.inbound_handler,