From 300c3a34ddda3eb91385ed6e52789124a6c27f6a Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Wed, 27 Feb 2019 14:43:26 -0500 Subject: [PATCH] Don't swallow exceptions inside `emulate_http_request` --- lms/djangoapps/discussion/tests/test_tasks.py | 12 ++++++------ openedx/core/lib/celery/task_utils.py | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lms/djangoapps/discussion/tests/test_tasks.py b/lms/djangoapps/discussion/tests/test_tasks.py index 556b206c5c..a63fcb2d68 100644 --- a/lms/djangoapps/discussion/tests/test_tasks.py +++ b/lms/djangoapps/discussion/tests/test_tasks.py @@ -15,6 +15,7 @@ from django_comment_common.models import ForumsConfig from django_comment_common.signals import comment_created from edx_ace.recipient import Recipient from edx_ace.renderers import EmailRenderer +from edx_ace.channel import ChannelType, get_channel_for_message from edx_ace.utils import date from lms.djangoapps.discussion.signals.handlers import ENABLE_FORUM_NOTIFICATIONS_FOR_SITE_KEY from lms.djangoapps.discussion.tasks import _should_send_message, _track_notification_sent @@ -230,12 +231,11 @@ class TaskTestCase(ModuleStoreTestCase): with emulate_http_request( site=message.context['site'], user=self.thread_author ): - rendered_email = EmailRenderer().render(message) - self.assertTrue(self.comment['body'] in rendered_email.body_html) - self.assertTrue(self.comment_author.username in rendered_email.body_html) - self.assertTrue(self.thread_author.username in rendered_email.body_html) - self.assertTrue(self.mock_permalink in rendered_email.body_html) - self.assertTrue(message.context['site'].domain in rendered_email.body_html) + rendered_email = EmailRenderer().render(get_channel_for_message(ChannelType.EMAIL, message), message) + assert self.comment['body'] in rendered_email.body_html + assert self.comment_author.username in rendered_email.body_html + assert self.mock_permalink.return_value in rendered_email.body_html + assert message.context['site'].domain in rendered_email.body_html def run_should_not_send_email_test(self, thread, comment_dict): """ diff --git a/openedx/core/lib/celery/task_utils.py b/openedx/core/lib/celery/task_utils.py index 224f03273f..10f45c2cb2 100644 --- a/openedx/core/lib/celery/task_utils.py +++ b/openedx/core/lib/celery/task_utils.py @@ -45,6 +45,7 @@ def emulate_http_request(site=None, user=None, middleware_classes=None): except Exception as exc: for middleware in reversed(middleware_instances): _run_method_if_implemented(middleware, 'process_exception', request, exc) + raise else: for middleware in reversed(middleware_instances): _run_method_if_implemented(middleware, 'process_response', request, response)