44
55from django .test import tag
66
7- from anymail .exceptions import AnymailConfigurationError
7+ from anymail .exceptions import AnymailConfigurationError , AnymailWarning
88from anymail .inbound import AnymailInboundMessage
99from anymail .signals import AnymailInboundEvent
1010from anymail .webhooks .postmark import PostmarkInboundWebhookView
@@ -165,14 +165,27 @@ def test_attachments(self):
165165 "ContentType" : 'message/rfc822; charset="us-ascii"' ,
166166 "ContentLength" : len (email_content ),
167167 },
168+ # This is an attachement like send by the test webhook
169+ # A workaround is implemented to handle it.
170+ # Once Postmark solves the bug on their side this workaround
171+ # can be reverted.
172+ {
173+ "Name" : "test.txt" ,
174+ "ContentType" : "text/plain" ,
175+ "Data" : "VGhpcyBpcyBhdHRhY2htZW50IGNvbnRlbnRzLCBiYXNlLTY0IGVuY29kZWQu" ,
176+ "ContentLength" : 45 ,
177+ },
168178 ]
169179 }
170180
171- response = self .client .post (
172- "/anymail/postmark/inbound/" ,
173- content_type = "application/json" ,
174- data = json .dumps (raw_event ),
175- )
181+ with self .assertWarnsRegex (
182+ AnymailWarning , r"Received a test webhook attachment. "
183+ ):
184+ response = self .client .post (
185+ "/anymail/postmark/inbound/" ,
186+ content_type = "application/json" ,
187+ data = json .dumps (raw_event ),
188+ )
176189 self .assertEqual (response .status_code , 200 )
177190 kwargs = self .assert_handler_called_once_with (
178191 self .inbound_handler ,
@@ -183,7 +196,7 @@ def test_attachments(self):
183196 event = kwargs ["event" ]
184197 message = event .message
185198 attachments = message .attachments # AnymailInboundMessage convenience accessor
186- self .assertEqual (len (attachments ), 2 )
199+ self .assertEqual (len (attachments ), 3 )
187200 self .assertEqual (attachments [0 ].get_filename (), "test.txt" )
188201 self .assertEqual (attachments [0 ].get_content_type (), "text/plain" )
189202 self .assertEqual (attachments [0 ].get_content_text (), "test attachment" )
@@ -192,6 +205,14 @@ def test_attachments(self):
192205 attachments [1 ].get_content_bytes (), email_content
193206 )
194207
208+ # Attachment of test webhook
209+ self .assertEqual (attachments [2 ].get_filename (), "test.txt" )
210+ self .assertEqual (attachments [2 ].get_content_type (), "text/plain" )
211+ self .assertEqual (
212+ attachments [2 ].get_content_text (),
213+ "This is attachment contents, base-64 encoded." ,
214+ )
215+
195216 inlines = message .inline_attachments
196217 self .assertEqual (len (inlines ), 1 )
197218 inline = inlines ["abc123" ]
0 commit comments