本文整理汇总了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)