本文整理汇总了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])