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")
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"))
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"))
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")