Example #1
0
    def test_attach_file_without_content_id(self):
        msg = Message(to='me', text='hi')
        with patch(open_label) as mock_open:
            mock_open.return_value.__enter__ = lambda s: s
            mock_open.return_value.__exit__ = MagicMock(spec=file)
            mock_open.return_value.read.return_value = b'x'

            msg.attach_file('dummy.png')
            self.assertEqual('ContentID' in msg.attachments[0], False)
Example #2
0
    def test_attach_file_without_content_id(self):
        msg = Message(to='me', text='hi')
        with patch(open_label) as mock_open:
            mock_open.return_value.__enter__ = lambda s: s
            mock_open.return_value.__exit__ = MagicMock(spec=file)
            mock_open.return_value.read.return_value = b'x'

            msg.attach_file('dummy.png')
            self.assertEqual('ContentID' in msg.attachments[0], False)
Example #3
0
    def test_attach_file_with_content_id(self):
        msg = Message(to='me', text='hi')
        with patch(open_label) as mock_open:
            mock_open.return_value.__enter__ = lambda s: s
            mock_open.return_value.__exit__ = MagicMock(spec=file)
            mock_open.return_value.read.return_value = b'x'

            content_type = 'image/png'
            content_id = 'cid:valid_cid'
            filename = 'dummy.png'

            msg.attach_file('dummy.png', content_type=content_type,
                            content_id=content_id)
            attachment = {
                'Content': b64encode(b'x').decode('utf-8'),
                'ContentType': content_type,
                'Name': filename,
                'ContentID': content_id
            }
            self.assertEqual(msg.attachments, [attachment])
Example #4
0
    def test_attach_file_with_content_id(self):
        msg = Message(to='me', text='hi')
        with patch(open_label) as mock_open:
            mock_open.return_value.__enter__ = lambda s: s
            mock_open.return_value.__exit__ = MagicMock(spec=file)
            mock_open.return_value.read.return_value = b'x'

            content_type = 'image/png'
            content_id = 'cid:valid_cid'
            filename = 'dummy.png'

            msg.attach_file('dummy.png', content_type=content_type,
                            content_id=content_id)
            attachment = {
                'Content': b64encode(b'x').decode('utf-8'),
                'ContentType': content_type,
                'Name': filename,
                'ContentID': content_id
            }
            self.assertEqual(msg.attachments, [attachment])