diff --git a/lms/djangoapps/course_goals/management/commands/tests/test_goal_reminder_email.py b/lms/djangoapps/course_goals/management/commands/tests/test_goal_reminder_email.py index ad60420e0d30..fc7b162b85e4 100644 --- a/lms/djangoapps/course_goals/management/commands/tests/test_goal_reminder_email.py +++ b/lms/djangoapps/course_goals/management/commands/tests/test_goal_reminder_email.py @@ -5,6 +5,7 @@ from unittest import mock # lint-amnesty, pylint: disable=wrong-import-order import ddt +from django.conf import settings from django.core.management import call_command from django.test import TestCase from edx_toggles.toggles.testutils import override_waffle_flag @@ -20,7 +21,7 @@ from lms.djangoapps.certificates.data import CertificateStatuses from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory from openedx.core.djangolib.testing.utils import skip_unless_lms -from openedx.features.course_experience import ENABLE_COURSE_GOALS +from openedx.features.course_experience import ENABLE_COURSE_GOALS, ENABLE_SES_FOR_GOALREMINDER # Some constants just for clarity of tests (assuming week starts on a Monday, as March 2021 used below does) MONDAY = 0 @@ -180,3 +181,34 @@ def test_no_days_per_week(self): def test_old_course(self, end): self.make_valid_goal(overview__end=end) self.call_command(expect_sent=False) + + @mock.patch('lms.djangoapps.course_goals.management.commands.goal_reminder_email.ace.send') + def test_params_with_ses(self, mock_ace): + """Test that the parameters of the msg passed to ace.send() are set correctly when SES is enabled""" + with override_waffle_flag(ENABLE_SES_FOR_GOALREMINDER, active=None): + goal = self.make_valid_goal() + flag = get_waffle_flag_model().get(ENABLE_SES_FOR_GOALREMINDER.name) + flag.users.add(goal.user) + + with freeze_time('2021-03-02 10:00:00'): + call_command('goal_reminder_email') + + assert mock_ace.call_count == 1 + msg = mock_ace.call_args[0][0] + assert msg.options['override_default_channel'] is True + assert msg.options['from_address'] == settings.LMS_COMM_DEFAULT_FROM_EMAIL + + @mock.patch('lms.djangoapps.course_goals.management.commands.goal_reminder_email.ace.send') + def test_params_without_ses(self, mock_ace): + """Test that the parameters of the msg passed to ace.send() are set correctly when SES is not enabled""" + self.make_valid_goal() + + with freeze_time('2021-03-02 10:00:00'): + call_command('goal_reminder_email') + + assert mock_ace.call_count == 1 + msg = mock_ace.call_args[0][0] + assert msg.options['transactional'] is True + assert 'override_default_channel' not in msg.options + assert 'from_address' not in msg.options +