当前位置: 首页>>代码示例>>Python>>正文


Python pystmark.Message类代码示例

本文整理汇总了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)
开发者ID:muravjov,项目名称:pystmark,代码行数:9,代码来源:test_pystmark.py

示例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)
开发者ID:jdavisp3,项目名称:pystmark,代码行数:10,代码来源:test_pystmark.py

示例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])
开发者ID:jdavisp3,项目名称:pystmark,代码行数:11,代码来源:test_pystmark.py

示例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])
开发者ID:jdavisp3,项目名称:pystmark,代码行数:12,代码来源:test_pystmark.py

示例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])
开发者ID:jdavisp3,项目名称:pystmark,代码行数:12,代码来源:test_pystmark.py

示例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')
开发者ID:muravjov,项目名称:pystmark,代码行数:12,代码来源:test_pystmark.py

示例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])
开发者ID:muravjov,项目名称:pystmark,代码行数:15,代码来源:test_pystmark.py

示例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)
开发者ID:jdavisp3,项目名称:pystmark,代码行数:7,代码来源:test_pystmark.py

示例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)
开发者ID:jdavisp3,项目名称:pystmark,代码行数:19,代码来源:test_pystmark.py

示例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])
开发者ID:muravjov,项目名称:pystmark,代码行数:20,代码来源:test_pystmark.py

示例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'))
开发者ID:jdavisp3,项目名称:pystmark,代码行数:13,代码来源:test_pystmark.py

示例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'))
开发者ID:muravjov,项目名称:pystmark,代码行数:17,代码来源:test_pystmark.py

示例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')])
开发者ID:jdavisp3,项目名称:pystmark,代码行数:4,代码来源:test_pystmark.py

示例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))
开发者ID:jdavisp3,项目名称:pystmark,代码行数:6,代码来源:test_pystmark.py

示例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)
开发者ID:jdavisp3,项目名称:pystmark,代码行数:3,代码来源:test_pystmark.py


注:本文中的pystmark.Message类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。