def test_attachment_string_type(self): backend = SendGridBackend() attachments = (('file.txt', 'File content', 'text/plain'), ) mail = EmailMessage( subject='Email subject', body='Email body', from_email='*****@*****.**', to=(RECIPIENT, ), attachments=attachments, ) # Replicate backend sending prepared_mail = backend._build_sg_mail(mail) # Send to SendGrid response = backend.sg.client.mail.send.post(request_body=prepared_mail) self.assertEqual(response.status_code, 202)
def test_reply_to_header(self): backend = SendGridBackend() mail = EmailMultiAlternatives( subject='Your subject', body='Simple text body', from_email='*****@*****.**', to=[ '*****@*****.**', ], headers={'Reply-To': '*****@*****.**'}) # Replicate backend sending prepared_mail = backend._build_sg_mail(mail) # Check for propper assembly self.assertEqual( prepared_mail, { 'from': { 'email': '*****@*****.**' }, 'subject': 'Your subject', 'personalizations': [{ 'to': [{ 'email': '*****@*****.**' }], 'subject': 'Your subject' }], 'content': [{ 'type': 'text/plain', 'value': 'Simple text body' }], 'reply_to': { 'email': '*****@*****.**' } }) # Send to SendGrid response = backend.sg.client.mail.send.post(request_body=prepared_mail) self.assertEqual(response.status_code, 202)
def test_attachment_image_type(self): backend = SendGridBackend() with open(os.path.join(os.path.dirname(__file__), 'octocat.png'), 'rb') as f: img = f.read() attachments = (('octocat.png', img, 'image/png'), ) mail = EmailMessage( subject='Email subject', body='Email body', from_email='*****@*****.**', to=(RECIPIENT, ), attachments=attachments, ) # Replicate backend sending prepared_mail = backend._build_sg_mail(mail) # Send to SendGrid response = backend.sg.client.mail.send.post(request_body=prepared_mail) self.assertEqual(response.status_code, 202)