本文整理汇总了Python中instance.tests.models.factories.instance.OpenEdXInstanceFactory.provision_failed_email方法的典型用法代码示例。如果您正苦于以下问题:Python OpenEdXInstanceFactory.provision_failed_email方法的具体用法?Python OpenEdXInstanceFactory.provision_failed_email怎么用?Python OpenEdXInstanceFactory.provision_failed_email使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类instance.tests.models.factories.instance.OpenEdXInstanceFactory
的用法示例。
在下文中一共展示了OpenEdXInstanceFactory.provision_failed_email方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_provision_failed_exception_email
# 需要导入模块: from instance.tests.models.factories.instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.instance.OpenEdXInstanceFactory import provision_failed_email [as 别名]
def test_provision_failed_exception_email(self):
"""
Tests that provision_failed sends email when called from exception handler
"""
instance = OpenEdXInstanceFactory(name='exception_test', sub_domain='exception_test')
reason = "something went wrong"
log_lines = ["log line1", "log_line2"]
exception_message = "Something Bad happened Unexpectedly"
exception = Exception(exception_message)
try:
raise exception
except Exception: # pylint: disable=broad-except
instance.provision_failed_email(reason, log_lines)
expected_subject = OpenEdXInstance.EmailSubject.PROVISION_FAILED.format(
instance_name=instance.name, instance_url=instance.url
)
expected_recipients = [admin_tuple[1] for admin_tuple in settings.ADMINS]
self.assertEqual(len(django_mail.outbox), 1)
mail = django_mail.outbox[0]
self.assertIn(expected_subject, mail.subject)
self.assertIn(instance.name, mail.body)
self.assertIn(reason, mail.body)
self.assertEqual(mail.from_email, settings.SERVER_EMAIL)
self.assertEqual(mail.to, expected_recipients)
self.assertEqual(len(mail.attachments), 2)
self.assertEqual(mail.attachments[0], ("provision.log", "\n".join(log_lines), "text/plain"))
name, content, mime_type = mail.attachments[1]
self.assertEqual(name, "debug.html")
self.assertIn(exception_message, content)
self.assertEqual(mime_type, "text/html")
示例2: test_provision_failed_email
# 需要导入模块: from instance.tests.models.factories.instance import OpenEdXInstanceFactory [as 别名]
# 或者: from instance.tests.models.factories.instance.OpenEdXInstanceFactory import provision_failed_email [as 别名]
def test_provision_failed_email(self):
"""
Tests that provision_failed sends email when called from normal program flow
"""
instance = OpenEdXInstanceFactory(name='test', sub_domain='test')
reason = "something went wrong"
log_lines = ["log line1", "log_line2"]
instance.provision_failed_email(reason, log_lines)
expected_subject = OpenEdXInstance.EmailSubject.PROVISION_FAILED.format(
instance_name=instance.name, instance_url=instance.url
)
expected_recipients = [admin_tuple[1] for admin_tuple in settings.ADMINS]
self.assertEqual(len(django_mail.outbox), 1)
mail = django_mail.outbox[0]
self.assertIn(expected_subject, mail.subject)
self.assertIn(instance.name, mail.body)
self.assertIn(reason, mail.body)
self.assertEqual(mail.from_email, settings.SERVER_EMAIL)
self.assertEqual(mail.to, expected_recipients)
self.assertEqual(len(mail.attachments), 1)
self.assertEqual(mail.attachments[0], ("provision.log", "\n".join(log_lines), "text/plain"))