當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。