本文整理匯總了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)