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


Python SendGridClient._build_body方法代码示例

本文整理汇总了Python中sendgrid.SendGridClient._build_body方法的典型用法代码示例。如果您正苦于以下问题:Python SendGridClient._build_body方法的具体用法?Python SendGridClient._build_body怎么用?Python SendGridClient._build_body使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sendgrid.SendGridClient的用法示例。


在下文中一共展示了SendGridClient._build_body方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestSendGrid

# 需要导入模块: from sendgrid import SendGridClient [as 别名]
# 或者: from sendgrid.SendGridClient import _build_body [as 别名]
class TestSendGrid(unittest.TestCase):

    def setUp(self):
        self.sg = SendGridClient(os.getenv('SG_USER'), os.getenv('SG_PWD'))

    def test_send(self):
        m = Mail()
        m.add_to('John, Doe <[email protected]>')
        m.set_subject('test')
        m.set_html('WIN')
        m.set_text('WIN')
        m.set_from('[email protected]')
        m.add_substitution('subKey', 'subValue')
        m.add_section('testSection', 'sectionValue')
        m.add_category('testCategory')
        m.add_unique_arg('testUnique', 'uniqueValue')
        m.add_filter('testFilter', 'filter', 'filterValue')
        m.add_attachment_stream('testFile', 'fileValue')
        self.sg.send(m)

        url = self.sg._build_body(m)
        url.pop('api_key', None)
        url.pop('api_user', None)
        url.pop('date', None)
        test_url = json.loads('''
            {
                "to[]": ["[email protected]"],
                "toname[]": ["John Doe"],
                "html": "WIN",
                "text": "WIN",
                "subject": "test",
                "files[testFile]": "fileValue",
                "from": "[email protected]",
                "headers": "",
                "fromname": "",
                "replyto": ""
            }
            ''')
        test_url['x-smtpapi'] = json.dumps(json.loads('''
            {
                "sub": {
                    "subKey": ["subValue"]
                },
                "section": {
                    "testSection":"sectionValue"
                },
                "category": ["testCategory"],
                "unique_args": {
                    "testUnique":"uniqueValue"
                },
                "filters": {
                    "testFilter": {
                        "settings": {
                            "filter": "filterValue"
                        }
                    }
                }
            }
            '''))
        self.assertEqual(url, test_url)
开发者ID:iandouglas,项目名称:sendgrid-python,代码行数:62,代码来源:__init__.py

示例2: TestSendGrid

# 需要导入模块: from sendgrid import SendGridClient [as 别名]
# 或者: from sendgrid.SendGridClient import _build_body [as 别名]
class TestSendGrid(unittest.TestCase):
    def setUp(self):
        self.sg = SendGridClient(os.getenv('SG_USER'), os.getenv('SG_PWD'))

    @unittest.skipUnless(sys.version_info < (3, 0), 'only for python2')
    def test_unicode_recipients(self):
        recipients = [unicode('[email protected]'), unicode('[email protected]')]
        m = Mail(to=recipients,
                 subject='testing',
                 html='awesome',
                 from_email='[email protected]')

        mock = {'to[]': ['[email protected]', '[email protected]']}
        result = self.sg._build_body(m)

        self.assertEqual(result['to[]'], mock['to[]'])

    def test_send(self):
        m = Mail()
        m.add_to('John, Doe <[email protected]>')
        m.set_subject('test')
        m.set_html('WIN')
        m.set_text('WIN')
        m.set_from('[email protected]')
        m.add_substitution('subKey', 'subValue')
        m.add_section('testSection', 'sectionValue')
        m.add_category('testCategory')
        m.add_unique_arg('testUnique', 'uniqueValue')
        m.add_filter('testFilter', 'filter', 'filterValue')
        m.add_attachment_stream('testFile', 'fileValue')
        url = self.sg._build_body(m)
        url.pop('api_key', None)
        url.pop('api_user', None)
        url.pop('date', None)
        test_url = json.loads('''
            {
                "to[]": ["joh[email protected]"],
                "toname[]": ["John Doe"],
                "html": "WIN",
                "text": "WIN",
                "subject": "test",
                "files[testFile]": "fileValue",
                "from": "[email protected]"
            }
            ''')
        test_url['x-smtpapi'] = json.dumps(json.loads('''
            {
                "sub": {
                    "subKey": ["subValue"]
                },
                "section": {
                    "testSection":"sectionValue"
                },
                "category": ["testCategory"],
                "unique_args": {
                    "testUnique":"uniqueValue"
                },
                "filters": {
                    "testFilter": {
                        "settings": {
                            "filter": "filterValue"
                        }
                    }
                }
            }
            '''))
        self.assertEqual(url, test_url)

    @unittest.skipUnless(sys.version_info < (3, 0), 'only for python2')
    def test__build_body_unicode(self):
        """test _build_body() handles encoded unicode outside ascii range"""
        from_email = '\xd0\x9d\xd0\xb8\xd0\xba\xd0\[email protected]'
        from_name = '\xd0\x9a\xd0\xbb\xd0\xb0\xd0\xb2\xd0\xb4\xd0\xb8\xd1\x8f'
        subject = '\xd0\x9d\xd0\xb0\xd0\xb4\xd0\xb5\xd0\xb6\xd0\xb4\xd0\xb0'
        text = '\xd0\x9d\xd0\xb0\xd0\xb4\xd0\xb5\xd0\xb6\xd0\xb4\xd0\xb0'
        html = '\xd0\x9d\xd0\xb0\xd0\xb4\xd0\xb5\xd0\xb6\xd0\xb4\xd0\xb0'
        reply_to = '\xd0\x9d\xd0\xb8\xd0\xba\xd0\[email protected]'
        m = Mail()
        m.add_to('John, Doe <[email protected]>')
        m.set_subject(subject)
        m.set_html(html)
        m.set_text(text)
        m.set_from("%s <%s>" % (from_name, from_email))
        url = self.sg._build_body(m)
        self.assertEqual(from_email, url['from'])
        self.assertEqual(from_name, url['fromname'])
        self.assertEqual(subject, url['subject'])
        self.assertEqual(text, url['text'])
        self.assertEqual(html, url['html'])
开发者ID:Jaymon,项目名称:sendgrid-python,代码行数:91,代码来源:__init__.py

示例3: TestSendGrid

# 需要导入模块: from sendgrid import SendGridClient [as 别名]
# 或者: from sendgrid.SendGridClient import _build_body [as 别名]
class TestSendGrid(unittest.TestCase):
    
    def setUp(self):
        self.sg = SendGridClient(SG_USER, SG_PWD)
        self.maxDiff = None

    def test_apikey_init(self):
        sg = SendGridClient(SG_PWD)
        self.assertEqual(sg.password, SG_PWD)
        self.assertIsNone(sg.username)

    @unittest.skipUnless(sys.version_info < (3, 0), 'only for python2')
    def test_unicode_recipients(self):
        recipients = [unicode('[email protected]'), unicode('[email protected]')]
        m = Mail(to=recipients,
                 subject='testing',
                 html='awesome',
                 from_email='[email protected]')

        mock = {'to[]': ['[email protected]', '[email protected]']}
        result = self.sg._build_body(m)

        self.assertEqual(result['to[]'], mock['to[]'])

    def test_send(self):
        m = Mail()
        m.add_to('John, Doe <[email protected]>')
        m.set_subject('test')
        m.set_html('WIN')
        m.set_text('WIN')
        m.set_from('[email protected]')
        m.set_asm_group_id(42)
        m.add_cc('[email protected]')
        m.add_bcc('[email protected]')
        m.add_substitution('subKey', 'subValue')
        m.add_section('testSection', 'sectionValue')
        m.add_category('testCategory')
        m.add_unique_arg('testUnique', 'uniqueValue')
        m.add_filter('testFilter', 'filter', 'filterValue')
        m.add_attachment_stream('testFile', 'fileValue')
        url = self.sg._build_body(m)
        url.pop('api_key', None)
        url.pop('api_user', None)
        url.pop('date', None)
        test_url = json.loads('''
            {
                "to[]": ["[email protected]"],
                "toname[]": ["John Doe"],
                "html": "WIN",
                "text": "WIN",
                "subject": "test",
                "files[testFile]": "fileValue",
                "from": "[email protected]",
                "cc[]": ["[email protected]"],
                "bcc[]": ["[email protected]"]
            }
            ''')
        test_url['x-smtpapi'] = json.dumps(json.loads('''
            {
                "sub": {
                    "subKey": ["subValue"]
                },
                "section": {
                    "testSection":"sectionValue"
                },
                "category": ["testCategory"],
                "unique_args": {
                    "testUnique":"uniqueValue"
                },
                "filters": {
                    "testFilter": {
                        "settings": {
                            "filter": "filterValue"
                        }
                    }
                },
                "asm_group_id": 42
            }
            '''))
        
        try:
            self.assertItemsEqual(url, test_url)
        except: # Python 3+
            self.assertCountEqual(url, test_url)
        
    @unittest.skipUnless(sys.version_info < (3, 0), 'only for python2')
    def test__build_body_unicode(self):
        """test _build_body() handles encoded unicode outside ascii range"""
        from_email = '\xd0\x9d\xd0\xb8\xd0\xba\xd0\[email protected]'
        from_name = '\xd0\x9a\xd0\xbb\xd0\xb0\xd0\xb2\xd0\xb4\xd0\xb8\xd1\x8f'
        subject = '\xd0\x9d\xd0\xb0\xd0\xb4\xd0\xb5\xd0\xb6\xd0\xb4\xd0\xb0'
        text = '\xd0\x9d\xd0\xb0\xd0\xb4\xd0\xb5\xd0\xb6\xd0\xb4\xd0\xb0'
        html = '\xd0\x9d\xd0\xb0\xd0\xb4\xd0\xb5\xd0\xb6\xd0\xb4\xd0\xb0'
        m = Mail()
        m.add_to('John, Doe <[email protected]>')
        m.set_subject(subject)
        m.set_html(html)
        m.set_text(text)
        m.set_from("%s <%s>" % (from_name, from_email))
        url = self.sg._build_body(m)
#.........这里部分代码省略.........
开发者ID:Adomako-Bismark,项目名称:sendgrid-python,代码行数:103,代码来源:test_mail_v2.py

示例4: TestSendGrid

# 需要导入模块: from sendgrid import SendGridClient [as 别名]
# 或者: from sendgrid.SendGridClient import _build_body [as 别名]
class TestSendGrid(unittest.TestCase):
    def setUp(self):
        self.sg = SendGridClient(SG_USER, SG_PWD)

    def test_apikey_init(self):
        sg = SendGridClient(SG_PWD)
        self.assertEqual(sg.password, SG_PWD)
        self.assertIsNone(sg.username)

    @unittest.skipUnless(sys.version_info < (3, 0), "only for python2")
    def test_unicode_recipients(self):
        recipients = [unicode("[email protected]"), unicode("[email protected]")]
        m = Mail(to=recipients, subject="testing", html="awesome", from_email="[email protected]")

        mock = {"to[]": ["[email protected]", "[email protected]"]}
        result = self.sg._build_body(m)

        self.assertEqual(result["to[]"], mock["to[]"])

    def test_send(self):
        m = Mail()
        m.add_to("John, Doe <[email protected]>")
        m.set_subject("test")
        m.set_html("WIN")
        m.set_text("WIN")
        m.set_from("[email protected]")
        m.set_asm_group_id(42)
        m.add_cc("[email protected]")
        m.add_bcc("[email protected]")
        m.add_substitution("subKey", "subValue")
        m.add_section("testSection", "sectionValue")
        m.add_category("testCategory")
        m.add_unique_arg("testUnique", "uniqueValue")
        m.add_filter("testFilter", "filter", "filterValue")
        m.add_attachment_stream("testFile", "fileValue")
        url = self.sg._build_body(m)
        url.pop("api_key", None)
        url.pop("api_user", None)
        url.pop("date", None)
        test_url = json.loads(
            """
            {
                "to[]": ["[email protected]"],
                "toname[]": ["John Doe"],
                "html": "WIN",
                "text": "WIN",
                "subject": "test",
                "files[testFile]": "fileValue",
                "from": "[email protected]",
                "cc[]": ["[email protected]"],
                "bcc[]": ["[email protected]"]
            }
            """
        )
        test_url["x-smtpapi"] = json.dumps(
            json.loads(
                """
            {
                "sub": {
                    "subKey": ["subValue"]
                },
                "section": {
                    "testSection":"sectionValue"
                },
                "category": ["testCategory"],
                "unique_args": {
                    "testUnique":"uniqueValue"
                },
                "filters": {
                    "testFilter": {
                        "settings": {
                            "filter": "filterValue"
                        }
                    }
                },
                "asm_group_id": 42
            }
            """
            )
        )

        self.assertEqual(url, test_url)

    @unittest.skipUnless(sys.version_info < (3, 0), "only for python2")
    def test__build_body_unicode(self):
        """test _build_body() handles encoded unicode outside ascii range"""
        from_email = "\xd0\x9d\xd0\xb8\xd0\xba\xd0\[email protected]"
        from_name = "\xd0\x9a\xd0\xbb\xd0\xb0\xd0\xb2\xd0\xb4\xd0\xb8\xd1\x8f"
        subject = "\xd0\x9d\xd0\xb0\xd0\xb4\xd0\xb5\xd0\xb6\xd0\xb4\xd0\xb0"
        text = "\xd0\x9d\xd0\xb0\xd0\xb4\xd0\xb5\xd0\xb6\xd0\xb4\xd0\xb0"
        html = "\xd0\x9d\xd0\xb0\xd0\xb4\xd0\xb5\xd0\xb6\xd0\xb4\xd0\xb0"
        m = Mail()
        m.add_to("John, Doe <[email protected]>")
        m.set_subject(subject)
        m.set_html(html)
        m.set_text(text)
        m.set_from("%s <%s>" % (from_name, from_email))
        url = self.sg._build_body(m)
        self.assertEqual(from_email, url["from"])
        self.assertEqual(from_name, url["fromname"])
#.........这里部分代码省略.........
开发者ID:kykocamp,项目名称:sendgrid-python,代码行数:103,代码来源:__init__.py


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