本文整理汇总了Python中pystmark.Message类的典型用法代码示例。如果您正苦于以下问题:Python Message类的具体用法?Python Message怎么用?Python Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_attach_file_without_content_id
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_api_key_on_send
def test_api_key_on_send(self, mock_request):
mock_request.return_value = self.mock_response('')
msg = Message(to='me', text='hi')
sender = Sender(message=msg)
url = sender._get_api_url(secure=True)
data = msg.json()
headers = sender._get_headers(api_key=POSTMARK_API_TEST_KEY)
sender.send(api_key=POSTMARK_API_TEST_KEY)
mock_request.assert_called_with('POST', url, data=data,
headers=headers)
示例3: test_attach_binary
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])
示例4: test_attach_binary_content_type_override
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])
示例5: test_attach_binary_default_content_type
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])
示例6: test_detect_content_type
def test_detect_content_type(self):
m = Message()
# No extension error
self.assertRaises(MessageError, m._detect_content_type, 'xxx')
# Blacklisted extension error
self.assertRaises(MessageError, m._detect_content_type, 'xxx.bin')
# Unknown extension returns default content type
ext = 'xcacaswcawc'
self.assertEqual(m._detect_content_type('xxx.' + ext),
m._default_content_type)
# Known extension returns correct mimetype
self.assertEqual(m._detect_content_type('xxx.png'), 'image/png')
示例7: test_attach_binary_with_content_id
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])
示例8: test_load_message_postmark
def test_load_message_postmark(self):
self.assertNotRaises(TypeError, Message.load_message,
self.message)
msg = Message.load_message(self.message)
self.assertNotRaises(MessageError, Message.load_message,
self.message, verify=True)
self.assertEqual(msg.data(), self.message)
示例9: _test_secure_overrides
def _test_secure_overrides(self, mock_request, init_secure=None,
send_secure=None):
mock_request.return_value = self.mock_response('')
msg = Message(to='me', text='hi')
sender = Sender(test=True, secure=init_secure)
if init_secure or init_secure is None:
url = POSTMARK_API_URL_SECURE
else:
url = POSTMARK_API_URL
if not send_secure and send_secure is not None:
url = POSTMARK_API_URL
elif send_secure:
url = POSTMARK_API_URL_SECURE
url = urljoin(url, Sender.endpoint)
data = msg.json()
headers = sender._get_headers(api_key=POSTMARK_API_TEST_KEY)
sender.send(secure=send_secure, message=msg)
mock_request.assert_called_with('POST', url, data=data,
headers=headers)
示例10: test_attach_file_with_content_id
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])
示例11: test_load_message_native
def test_load_message_native(self):
msg = dict(to='me', text='hi', html='<b>hi</b>', reply_to='you',
cc='dog,cat', subject='dogs', headers=[dict(Name='Food',
Value='7')])
self.assertNotRaises(TypeError, Message.load_message, msg)
self.assertNotRaises(MessageError, Message.load_message, msg,
verify=True)
msg = dict(to='me', text='hi')
self.assertNotRaises(TypeError, Message.load_message, msg)
self.assertNotRaises(MessageError, Message.load_message, msg,
verify=True)
pystmsg = Message.load_message(msg)
self.assertEqual(pystmsg.data(), dict(To='me', TextBody='hi'))
示例12: test_load_message_native
def test_load_message_native(self):
msg = dict(to='me', text='hi', html='<b>hi</b>', reply_to='you',
cc='dog,cat', bcc='foo,bar', subject='dogs',
track_opens=True, headers=[dict(Name='Food', Value='7')],
attachments=[], sender='admin', tag='tag')
self.assertEqual(sorted(msg), sorted(Message._fields))
self.assertNotRaises(TypeError, Message.load_message, msg)
self.assertNotRaises(MessageError, Message.load_message, msg,
verify=True)
msg = dict(to='me', text='hi')
self.assertNotRaises(TypeError, Message.load_message, msg)
self.assertNotRaises(MessageError, Message.load_message, msg,
verify=True)
pystmsg = Message.load_message(msg)
self.assertEqual(pystmsg.data(), dict(To='me', TextBody='hi'))
示例13: test_attach_header
def test_attach_header(self):
msg = Message(to='me', text='hi')
msg.add_header('Boy', 'Dog')
self.assertEqual(msg.headers, [dict(Name='Boy', Value='Dog')])
示例14: test_not_equal
def test_not_equal(self):
m = Message(sender='me')
n = Message(sender='you')
self.assertNotEqual(m, n)
# To get python 2.6 to trigger __ne__:
self.assertTrue(m.__ne__(n))
示例15: test_load_invalid_message_some_data
def test_load_invalid_message_some_data(self):
msg = Message.load_message(dict(to='me'))
self.assertRaises(MessageError, msg.verify)