本文整理匯總了Python中pystmark.Message.attach_file方法的典型用法代碼示例。如果您正苦於以下問題:Python Message.attach_file方法的具體用法?Python Message.attach_file怎麽用?Python Message.attach_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pystmark.Message
的用法示例。
在下文中一共展示了Message.attach_file方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_attach_file_without_content_id
# 需要導入模塊: from pystmark import Message [as 別名]
# 或者: from pystmark.Message import attach_file [as 別名]
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)
示例2: test_attach_file_with_content_id
# 需要導入模塊: from pystmark import Message [as 別名]
# 或者: from pystmark.Message import attach_file [as 別名]
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])