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


Python DirectMailDelivery.transaction_manager方法代码示例

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


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

示例1: test_alternate_transaction_manager

# 需要导入模块: from repoze.sendmail.delivery import DirectMailDelivery [as 别名]
# 或者: from repoze.sendmail.delivery.DirectMailDelivery import transaction_manager [as 别名]
    def test_alternate_transaction_manager(self):
        from repoze.sendmail.delivery import DirectMailDelivery
        from email.message import Message
        import transaction

        mailer = _makeMailerStub()
        delivery = DirectMailDelivery(mailer)
        tm = transaction.TransactionManager()
        delivery.transaction_manager = tm
        fromaddr = "Jim <[email protected]>"
        toaddrs = ("Guido <[email protected]>", "Steve <[email protected]>")
        message = Message()
        message["From"] = fromaddr
        message["To"] = ",".join(toaddrs)
        message["Date"] = "Date: Mon, 19 May 2003 10:17:36 -0400"
        message["Subject"] = "example"
        message.set_payload("This is just an example\n")

        msgid = delivery.send(fromaddr, toaddrs, message)

        transaction.commit()
        self.assertEqual(len(mailer.sent_messages), 0)
        t = tm.get()
        data_manager = t._resources[0]
        self.assertTrue(data_manager.transaction_manager is tm)
        t.commit()
        self.assertEqual(len(mailer.sent_messages), 1)
        self.assertEqual(mailer.sent_messages[0][0], fromaddr)
        self.assertEqual(mailer.sent_messages[0][1], toaddrs)
        self.assertEqual(mailer.sent_messages[0][2].get_payload(), "This is just an example\n")

        mailer.sent_messages = []
        msgid = delivery.send(fromaddr, toaddrs, message)
        tm.get().abort()
        self.assertEqual(len(mailer.sent_messages), 0)
开发者ID:repoze,项目名称:repoze.sendmail,代码行数:37,代码来源:test_delivery.py


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