-
Notifications
You must be signed in to change notification settings - Fork 133
/
Copy pathtest_inline_image.py
33 lines (25 loc) · 1.3 KB
/
test_inline_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import base64
from email.utils import unquote
from django.test import TestCase
from templated_email.backends.vanilla_django import TemplateBackend
from templated_email import InlineImage
from tests.utils import MockedNetworkTestCaseMixin
imageb64 = ('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1B'
'MVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvD'
'MAAAAASUVORK5CYII=')
class GetMessageWithInlineMessageTestCase(MockedNetworkTestCaseMixin, TestCase):
def setUp(self):
self.backend = TemplateBackend()
self.inline_image = InlineImage('foo.png', base64.b64decode(imageb64))
self.message = self.backend.get_email_message(
'inline_image.email', {'image_file': self.inline_image},
from_email='from@example.com', cc=['cc@example.com'],
bcc=['bcc@example.com'], to=['to@example.com'])
def test_cid_in_message(self):
alternative_message = self.message.alternatives[0][0]
self.assertIn('cid:%s' % unquote(self.inline_image._content_id),
alternative_message)
def test_image_in_attachments(self):
mimage = self.message.attachments[0]
attachment_content = base64.b64encode(mimage.get_payload(decode=True))
self.assertEqual(attachment_content.decode(), imageb64)