Exemple #1
0
 def test_sendgrid_email(self):
     """ Test if we can send emails using our own class.
     """
     message = SendgridEmailMessage(**self.email_data)
     message.send()
     # this email should have a UUID
     self.assertEqual(len(mail.outbox), 1)
     self.assertEqual(mail.outbox[0].subject, self.email_data['subject'])
     self.assertIn('X-SMTPAPI', mail.outbox[0].extra_headers)
     content = json.loads(mail.outbox[0].extra_headers['X-SMTPAPI'])
     self.assertIn('uuid', content['unique_args'])
     self.assertEqual(len(content['unique_args']['uuid']), 36)
Exemple #2
0
    def test_email_headers(self):
        """ Test if we handle custom headers correctly.
        """
        # Add a custom extra_header field
        mail_data = copy(self.email_data)
        mail_data.update({'headers': {'X-AWESOME': 42, }})

        message = SendgridEmailMessage(**mail_data)
        message.send()
        # this email should have a UUID
        self.assertEqual(len(mail.outbox), 1)
        self.assertIn('X-SMTPAPI', mail.outbox[0].extra_headers)

        content = json.loads(mail.outbox[0].extra_headers['X-SMTPAPI'])
        self.assertIn('uuid', content['unique_args'])
        self.assertEqual(len(content['unique_args']['uuid']), 36)

        self.assertEqual(mail.outbox[0].extra_headers['X-AWESOME'], 42)
Exemple #3
0
    def test_sendgrid_email_object_attachment(self):
        """ Test attaching a related object to the email.
        """
        # first send a message without an object
        message = SendgridEmailMessage(**self.email_data)
        message.send()
        mail_event_1 = Email.objects.get(uuid=message.uuid)
        self.assertEqual(mail_event_1.content_object, None)

        # now attach an object
        data = dict(self.email_data)
        data['obj'] = mail_event_1  # code re-use :)
        message = SendgridEmailMessage(**data)
        message.send()
        mail_event = Email.objects.get(uuid=message.uuid)
        self.assertEqual(mail_event.content_object, mail_event_1)