-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathtest_utils.py
54 lines (43 loc) · 1.9 KB
/
test_utils.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from unittest.mock import patch, Mock
from django.test import TestCase
from templated_email import InlineImage
from tests.utils import MockedNetworkTestCaseMixin
class InlineMessageTestCase(MockedNetworkTestCaseMixin, TestCase):
def setUp(self):
self.inline_image = InlineImage('foo.png', 'content', 'png')
def test_needs_two_args(self):
with self.assertRaises(TypeError):
InlineImage()
with self.assertRaises(TypeError):
InlineImage('foo')
def test_has_no_cid(self):
self.assertIsNone(self.inline_image._content_id)
def test_generate_cid(self):
str(self.inline_image)
self.assertIsNotNone(self.inline_image._content_id)
@patch('templated_email.utils.make_msgid', return_value='foo')
def test_str(self, mocked):
self.assertEqual(str(self.inline_image), 'cid:foo')
@patch('templated_email.utils.make_msgid', return_value='foo')
def test_should_cache_cid(self, mocked):
str(self.inline_image)
str(self.inline_image)
mocked.assert_called_once()
def test_changing_content_should_generate_new_cid(self):
src_value = str(self.inline_image)
cid = self.inline_image._content_id
self.inline_image.content = 'content2'
cid2 = self.inline_image._content_id
src_value2 = str(self.inline_image)
self.assertNotEqual(src_value, src_value2)
cid3 = self.inline_image._content_id
self.assertNotEqual(cid, cid2)
self.assertNotEqual(cid2, cid3)
def test_attach_to_message(self):
message = Mock()
self.inline_image.attach_to_message(message)
mimeimage = message.attach.call_args[0][0]
self.assertEqual(mimeimage.get('Content-ID'),
self.inline_image._content_id)
self.assertEqual(mimeimage.get('Content-Disposition'),
'inline; filename="foo.png"')