本文整理汇总了Python中pystmark.Message.attach_binary方法的典型用法代码示例。如果您正苦于以下问题:Python Message.attach_binary方法的具体用法?Python Message.attach_binary怎么用?Python Message.attach_binary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pystmark.Message
的用法示例。
在下文中一共展示了Message.attach_binary方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_attach_binary
# 需要导入模块: from pystmark import Message [as 别名]
# 或者: from pystmark.Message import attach_binary [as 别名]
def test_attach_binary(self):
msg = Message(to='me', text='hi')
data = urandom(64)
name = 'test.pdf'
msg.attach_binary(data, name)
attachment = {
'Content': b64encode(data).decode('utf-8'),
'ContentType': 'application/pdf',
'Name': name
}
self.assertEqual(msg.attachments, [attachment])
示例2: test_attach_binary_content_type_override
# 需要导入模块: from pystmark import Message [as 别名]
# 或者: from pystmark.Message import attach_binary [as 别名]
def test_attach_binary_content_type_override(self):
msg = Message(to='me', text='hi')
data = urandom(64)
content_type = 'xcascasc'
name = 'test.pdf'
msg.attach_binary(data, name, content_type=content_type)
attachment = {
'Content': b64encode(data).decode('utf-8'),
'ContentType': content_type,
'Name': name
}
self.assertEqual(msg.attachments, [attachment])
示例3: test_attach_binary_default_content_type
# 需要导入模块: from pystmark import Message [as 别名]
# 或者: from pystmark.Message import attach_binary [as 别名]
def test_attach_binary_default_content_type(self, mock_type):
mock_type.return_value = 'application/octet-stream'
msg = Message(to='me', text='hi')
data = urandom(64)
name = 'test.bin'
msg.attach_binary(data, name)
attachment = {
'Content': b64encode(data).decode('utf-8'),
'ContentType': 'application/octet-stream',
'Name': name
}
self.assertEqual(msg.attachments, [attachment])
示例4: test_attach_binary_with_content_id
# 需要导入模块: from pystmark import Message [as 别名]
# 或者: from pystmark.Message import attach_binary [as 别名]
def test_attach_binary_with_content_id(self):
msg = Message(to='me', text='hi')
data = urandom(64)
name = 'test.pdf'
content_type = 'image/png'
content_id = 'cid:{0}@example.com'.format(uuid.uuid4())
msg.attach_binary(data, name, content_type=content_type,
content_id=content_id)
attachment = {
'Content': b64encode(data).decode('utf-8'),
'ContentType': 'image/png',
'Name': name,
'ContentID': content_id
}
self.assertEqual(msg.attachments, [attachment])
示例5: test_attach_binary_no_content_id
# 需要导入模块: from pystmark import Message [as 别名]
# 或者: from pystmark.Message import attach_binary [as 别名]
def test_attach_binary_no_content_id(self):
msg = Message(to='me', text='hi')
data = urandom(64)
name = 'test.pdf'
msg.attach_binary(data, name)
self.assertEqual('ContentID' in msg.attachments[0], False)