Skip to content

Commit

Permalink
test: added test cases for ace message parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
sohailfatima committed Oct 11, 2024
1 parent 6202633 commit ca5fe4c
Showing 1 changed file with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

0 comments on commit ca5fe4c

Please sign in to comment.